Skip to content

Commit 166764f

Browse files
committed
Fix the bug that isAnimating control does not works on WebImage
1 parent ed28866 commit 166764f

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

SDWebImageSwiftUI/Classes/ImagePlayer.swift

-16
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

+15-6
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
@@ -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)

0 commit comments

Comments
 (0)