File tree Expand file tree Collapse file tree 2 files changed +14
-21
lines changed
SDWebImageSwiftUI/Classes Expand file tree Collapse file tree 2 files changed +14
-21
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,6 @@ import SDWebImage
1414public final class ImagePlayer : ObservableObject {
1515 var player : SDAnimatedImagePlayer ?
1616
17- var waitingPlaying = false
18-
1917 /// Max buffer size
2018 public var maxBufferSize : UInt ?
2119
@@ -51,14 +49,6 @@ public final class ImagePlayer : ObservableObject {
5149 player != nil
5250 }
5351
54- /// The player is preparing to resume from previous stop state. This is intermediate status when previous frame disappear and new frame appear
55- public var isWaiting : Bool {
56- if let player = player {
57- return player. isPlaying && waitingPlaying
58- }
59- return true
60- }
61-
6252 /// Current playing status
6353 public var isPlaying : Bool {
6454 player? . isPlaying ?? false
@@ -67,12 +57,6 @@ public final class ImagePlayer : ObservableObject {
6757 /// Start the animation
6858 public func startPlaying( ) {
6959 player? . startPlaying ( )
70- waitingPlaying = true
71- DispatchQueue . main. async {
72- // This workaround `WebImage` caller
73- // Which previous frame onDisappear and new frame onAppear, cause player status wrong
74- self . waitingPlaying = false
75- }
7660 }
7761
7862 /// Pause the animation
Original file line number Diff line number Diff line change @@ -117,11 +117,7 @@ public struct WebImage : View {
117117 if isAnimating && !imageManager. isIncremental {
118118 setupPlayer ( )
119119 } else {
120- if let currentFrame = imagePlayer. currentFrame {
121- configure ( image: currentFrame)
122- } else {
123- configure ( image: imageManager. image!)
124- }
120+ displayImage ( )
125121 }
126122 } else {
127123 // Load Logic
@@ -231,6 +227,16 @@ public struct WebImage : View {
231227 }
232228 }
233229
230+ /// Static Image Display
231+ func displayImage( ) -> some View {
232+ disappearAction ( )
233+ if let currentFrame = imagePlayer. currentFrame {
234+ return configure ( image: currentFrame)
235+ } else {
236+ return configure ( image: imageManager. image!)
237+ }
238+ }
239+
234240 /// Animated Image Support
235241 func setupPlayer( ) -> some View {
236242 let shouldResetPlayer : Bool
@@ -240,6 +246,9 @@ public struct WebImage : View {
240246 } else {
241247 shouldResetPlayer = false
242248 }
249+ if !shouldResetPlayer {
250+ imagePlayer. startPlaying ( )
251+ }
243252 if let currentFrame = imagePlayer. currentFrame, !shouldResetPlayer {
244253 // Bind frame index to ID to ensure onDisappear called with sync
245254 return configure ( image: currentFrame)
You can’t perform that action at this time.
0 commit comments