Skip to content

Commit 20b6a65

Browse files
committed
Fix the bug that isAnimating control does not works on WebImage
1 parent 8192aec commit 20b6a65

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

SDWebImageSwiftUI/Classes/ImagePlayer.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import SDWebImage
1414
public 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

SDWebImageSwiftUI/Classes/WebImage.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class WebImageConfiguration: ObservableObject {
3535
var maxBufferSize: UInt?
3636
var customLoopCount: UInt?
3737
var runLoopMode: RunLoop.Mode = .common
38-
var pausable: Bool = true
38+
var pausable: Bool = false
3939
var purgeable: Bool = false
4040
var playbackRate: Double = 1.0
4141
var playbackMode: SDAnimatedImagePlaybackMode = .normal
@@ -115,11 +115,7 @@ public struct WebImage : View {
115115
if isAnimating && !imageManager.isIncremental {
116116
setupPlayer()
117117
} else {
118-
if let currentFrame = imagePlayer.currentFrame {
119-
configure(image: currentFrame)
120-
} else {
121-
configure(image: imageManager.image!)
122-
}
118+
displayImage()
123119
}
124120
} else {
125121
// Load Logic
@@ -229,6 +225,16 @@ public struct WebImage : View {
229225
}
230226
}
231227

228+
/// Static Image Display
229+
func displayImage() -> some View {
230+
disappearAction()
231+
if let currentFrame = imagePlayer.currentFrame {
232+
return configure(image: currentFrame)
233+
} else {
234+
return configure(image: imageManager.image!)
235+
}
236+
}
237+
232238
/// Animated Image Support
233239
func setupPlayer() -> some View {
234240
let shouldResetPlayer: Bool
@@ -238,6 +244,9 @@ public struct WebImage : View {
238244
} else {
239245
shouldResetPlayer = false
240246
}
247+
if !shouldResetPlayer {
248+
imagePlayer.startPlaying()
249+
}
241250
if let currentFrame = imagePlayer.currentFrame, !shouldResetPlayer {
242251
// Bind frame index to ID to ensure onDisappear called with sync
243252
return configure(image: currentFrame)

0 commit comments

Comments
 (0)