Fix the bug that isAnimating control does not works on WebImage
This commit is contained in:
parent
ed288667c9
commit
940907a6f9
|
@ -14,8 +14,6 @@ import SDWebImage
|
|||
public final class ImagePlayer : ObservableObject {
|
||||
var player: SDAnimatedImagePlayer?
|
||||
|
||||
var waitingPlaying = false
|
||||
|
||||
/// Max buffer size
|
||||
public var maxBufferSize: UInt?
|
||||
|
||||
|
@ -51,14 +49,6 @@ public final class ImagePlayer : ObservableObject {
|
|||
player != nil
|
||||
}
|
||||
|
||||
/// The player is preparing to resume from previous stop state. This is intermediate status when previous frame disappear and new frame appear
|
||||
public var isWaiting: Bool {
|
||||
if let player = player {
|
||||
return player.isPlaying && waitingPlaying
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/// Current playing status
|
||||
public var isPlaying: Bool {
|
||||
player?.isPlaying ?? false
|
||||
|
@ -67,12 +57,6 @@ public final class ImagePlayer : ObservableObject {
|
|||
/// Start the animation
|
||||
public func startPlaying() {
|
||||
player?.startPlaying()
|
||||
waitingPlaying = true
|
||||
DispatchQueue.main.async {
|
||||
// This workaround `WebImage` caller
|
||||
// Which previous frame onDisappear and new frame onAppear, cause player status wrong
|
||||
self.waitingPlaying = false
|
||||
}
|
||||
}
|
||||
|
||||
/// Pause the animation
|
||||
|
|
|
@ -117,11 +117,7 @@ public struct WebImage : View {
|
|||
if isAnimating && !imageManager.isIncremental {
|
||||
setupPlayer()
|
||||
} else {
|
||||
if let currentFrame = imagePlayer.currentFrame {
|
||||
configure(image: currentFrame)
|
||||
} else {
|
||||
configure(image: imageManager.image!)
|
||||
}
|
||||
displayImage()
|
||||
}
|
||||
} else {
|
||||
// Load Logic
|
||||
|
@ -231,6 +227,16 @@ public struct WebImage : View {
|
|||
}
|
||||
}
|
||||
|
||||
/// Static Image Display
|
||||
func displayImage() -> some View {
|
||||
disappearAction()
|
||||
if let currentFrame = imagePlayer.currentFrame {
|
||||
return configure(image: currentFrame)
|
||||
} else {
|
||||
return configure(image: imageManager.image!)
|
||||
}
|
||||
}
|
||||
|
||||
/// Animated Image Support
|
||||
func setupPlayer() -> some View {
|
||||
let shouldResetPlayer: Bool
|
||||
|
@ -240,6 +246,9 @@ public struct WebImage : View {
|
|||
} else {
|
||||
shouldResetPlayer = false
|
||||
}
|
||||
if !shouldResetPlayer {
|
||||
imagePlayer.startPlaying()
|
||||
}
|
||||
if let currentFrame = imagePlayer.currentFrame, !shouldResetPlayer {
|
||||
// Bind frame index to ID to ensure onDisappear called with sync
|
||||
return configure(image: currentFrame)
|
||||
|
|
Loading…
Reference in New Issue