File tree 2 files changed +14
-21
lines changed
SDWebImageSwiftUI/Classes
2 files changed +14
-21
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,6 @@ import SDWebImage
14
14
public final class ImagePlayer : ObservableObject {
15
15
var player : SDAnimatedImagePlayer ?
16
16
17
- var waitingPlaying = false
18
-
19
17
/// Max buffer size
20
18
public var maxBufferSize : UInt ?
21
19
@@ -51,14 +49,6 @@ public final class ImagePlayer : ObservableObject {
51
49
player != nil
52
50
}
53
51
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
-
62
52
/// Current playing status
63
53
public var isPlaying : Bool {
64
54
player? . isPlaying ?? false
@@ -67,12 +57,6 @@ public final class ImagePlayer : ObservableObject {
67
57
/// Start the animation
68
58
public func startPlaying( ) {
69
59
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
- }
76
60
}
77
61
78
62
/// Pause the animation
Original file line number Diff line number Diff line change @@ -117,11 +117,7 @@ public struct WebImage : View {
117
117
if isAnimating && !imageManager. isIncremental {
118
118
setupPlayer ( )
119
119
} else {
120
- if let currentFrame = imagePlayer. currentFrame {
121
- configure ( image: currentFrame)
122
- } else {
123
- configure ( image: imageManager. image!)
124
- }
120
+ displayImage ( )
125
121
}
126
122
} else {
127
123
// Load Logic
@@ -231,6 +227,16 @@ public struct WebImage : View {
231
227
}
232
228
}
233
229
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
+
234
240
/// Animated Image Support
235
241
func setupPlayer( ) -> some View {
236
242
let shouldResetPlayer : Bool
@@ -240,6 +246,9 @@ public struct WebImage : View {
240
246
} else {
241
247
shouldResetPlayer = false
242
248
}
249
+ if !shouldResetPlayer {
250
+ imagePlayer. startPlaying ( )
251
+ }
243
252
if let currentFrame = imagePlayer. currentFrame, !shouldResetPlayer {
244
253
// Bind frame index to ID to ensure onDisappear called with sync
245
254
return configure ( image: currentFrame)
You can’t perform that action at this time.
0 commit comments