@@ -84,6 +84,7 @@ final class AnimatedImageConfiguration: ObservableObject {
84
84
var pausable : Bool ?
85
85
var purgeable : Bool ?
86
86
var playbackRate : Double ?
87
+ var playbackMode : SDAnimatedImagePlaybackMode ?
87
88
// These configurations only useful for web image loading
88
89
var indicator : SDWebImageIndicator ?
89
90
var transition : SDWebImageTransition ?
@@ -253,7 +254,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
253
254
} else {
254
255
// This is a hack because of iOS 13's SwiftUI bug, the @Published does not trigger another `updateUIView` call
255
256
// Here I have to use UIKit/AppKit API to triger the same effect (the window change implicitly cause re-render)
256
- if let hostingView = AnimatedImage . findHostingView ( from : view ) {
257
+ if let hostingView = view . findHostingView ( ) {
257
258
if let _ = hostingView. window {
258
259
#if os(macOS)
259
260
hostingView. viewDidMoveToWindow ( )
@@ -542,17 +543,13 @@ public struct AnimatedImage : PlatformViewRepresentable {
542
543
} else {
543
544
view. wrapped. playbackRate = 1.0
544
545
}
545
- }
546
-
547
- private static func findHostingView( from entry: PlatformView ) -> PlatformView ? {
548
- var superview = entry. superview
549
- while let s = superview {
550
- if NSStringFromClass ( type ( of: s) ) . contains ( " HostingView " ) {
551
- return s
552
- }
553
- superview = s. superview
546
+
547
+ // Playback Mode
548
+ if let playbackMode = imageConfiguration. playbackMode {
549
+ view. wrapped. playbackMode = playbackMode
550
+ } else {
551
+ view. wrapped. playbackMode = . normal
554
552
}
555
- return nil
556
553
}
557
554
}
558
555
@@ -717,6 +714,13 @@ extension AnimatedImage {
717
714
self . imageConfiguration. playbackRate = playbackRate
718
715
return self
719
716
}
717
+
718
+ /// Control the animation playback mode. Default is .normal
719
+ /// - Parameter playbackMode: The playback mode, including normal order, reverse order, bounce order and reversed bounce order.
720
+ public func playbackMode( _ playbackMode: SDAnimatedImagePlaybackMode ) -> AnimatedImage {
721
+ self . imageConfiguration. playbackMode = playbackMode
722
+ return self
723
+ }
720
724
}
721
725
722
726
// Completion Handler
0 commit comments