From 91afe3bb9d51a0266fcfdf9e113f3d080c5e413c Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Sun, 4 Sep 2022 14:47:05 -0600 Subject: [PATCH 1/3] Fix iOS 16 publishishing changes is not allowed warnings. --- SDWebImageSwiftUI/Classes/WebImage.swift | 60 +++++++++++------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/SDWebImageSwiftUI/Classes/WebImage.swift b/SDWebImageSwiftUI/Classes/WebImage.swift index 6e0c3f34..0e1af4e3 100644 --- a/SDWebImageSwiftUI/Classes/WebImage.swift +++ b/SDWebImageSwiftUI/Classes/WebImage.swift @@ -55,26 +55,22 @@ public struct WebImage : View { } public var body: some View { - // This solve the case when WebImage created with new URL, but `onAppear` not been called, for example, some transaction indeterminate state, SwiftUI :) - if imageManager.isFirstLoad { - imageManager.load() - } return Group { if let image = imageManager.image { if isAnimating && !imageManager.isIncremental { setupPlayer() - .onPlatformAppear(appear: { - self.imagePlayer.startPlaying() - }, disappear: { - if self.pausable { - self.imagePlayer.pausePlaying() - } else { - self.imagePlayer.stopPlaying() - } - if self.purgeable { - self.imagePlayer.clearFrameBuffer() + .onAppear { + self.imagePlayer.startPlaying() + }.onDisappear { + if self.pausable { + self.imagePlayer.pausePlaying() + } else { + self.imagePlayer.stopPlaying() + } + if self.purgeable { + self.imagePlayer.clearFrameBuffer() + } } - }) } else { if let currentFrame = imagePlayer.currentFrame { configure(image: currentFrame) @@ -84,24 +80,24 @@ public struct WebImage : View { } } else { setupPlaceholder() - .onPlatformAppear(appear: { - // Load remote image when first appear - if self.imageManager.isFirstLoad { - self.imageManager.load() - return - } - guard self.retryOnAppear else { return } - // When using prorgessive loading, the new partial image will cause onAppear. Filter this case - if self.imageManager.image == nil && !self.imageManager.isIncremental { - self.imageManager.load() - } - }, disappear: { - guard self.cancelOnDisappear else { return } - // When using prorgessive loading, the previous partial image will cause onDisappear. Filter this case - if self.imageManager.image == nil && !self.imageManager.isIncremental { - self.imageManager.cancel() + .onAppear { + // Load remote image when first appear + if self.imageManager.isFirstLoad { + self.imageManager.load() + return + } + guard self.retryOnAppear else { return } + // When using prorgessive loading, the new partial image will cause onAppear. Filter this case + if self.imageManager.image == nil && !self.imageManager.isIncremental { + self.imageManager.load() + } + }.onDisappear { + guard self.cancelOnDisappear else { return } + // When using prorgessive loading, the previous partial image will cause onDisappear. Filter this case + if self.imageManager.image == nil && !self.imageManager.isIncremental { + self.imageManager.cancel() + } } - }) } } } From ae55272bdc20bbf0d344c190ca65d1206350113b Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 5 Sep 2022 05:39:26 -0600 Subject: [PATCH 2/3] Fix iOS 16 undefined behavior warnings related to setupPlayer(). --- SDWebImageSwiftUI/Classes/WebImage.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/SDWebImageSwiftUI/Classes/WebImage.swift b/SDWebImageSwiftUI/Classes/WebImage.swift index 0e1af4e3..9aa2e640 100644 --- a/SDWebImageSwiftUI/Classes/WebImage.swift +++ b/SDWebImageSwiftUI/Classes/WebImage.swift @@ -154,13 +154,14 @@ public struct WebImage : View { /// Animated Image Support func setupPlayer() -> some View { if let currentFrame = imagePlayer.currentFrame { - return configure(image: currentFrame) + return configure(image: currentFrame).onAppear() } else { - if let animatedImage = imageManager.image as? SDAnimatedImageProvider { - self.imagePlayer.setupPlayer(animatedImage: animatedImage) - self.imagePlayer.startPlaying() + return configure(image: imageManager.image!).onAppear { + if let animatedImage = imageManager.image as? SDAnimatedImageProvider { + self.imagePlayer.setupPlayer(animatedImage: animatedImage) + self.imagePlayer.startPlaying() + } } - return configure(image: imageManager.image!) } } From d9feae51080fac94691e4d43b2252de1e0171391 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Sat, 10 Sep 2022 01:24:36 -0600 Subject: [PATCH 3/3] Restore isFirstLoad check to WebImage init. --- SDWebImageSwiftUI/Classes/WebImage.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SDWebImageSwiftUI/Classes/WebImage.swift b/SDWebImageSwiftUI/Classes/WebImage.swift index 9aa2e640..b58a0131 100644 --- a/SDWebImageSwiftUI/Classes/WebImage.swift +++ b/SDWebImageSwiftUI/Classes/WebImage.swift @@ -52,6 +52,11 @@ public struct WebImage : View { } self.imageManager = ImageManager(url: url, options: options, context: context) self.imagePlayer = ImagePlayer() + + // This solve the case when WebImage created with new URL, but `onAppear` not been called, for example, some transaction indeterminate state, SwiftUI :) + if imageManager.isFirstLoad { + imageManager.load() + } } public var body: some View {