Skip to content

Commit 3c9c30c

Browse files
committed
Support runloopMode and playback rate on watchOS
1 parent 225cbb1 commit 3c9c30c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

SDWebImageSwiftUI/Classes/ObjC/SDAnimatedImageInterface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ NS_ASSUME_NONNULL_BEGIN
1919
- (instancetype)init WK_AVAILABLE_WATCHOS_ONLY(6.0);
2020
- (void)setContentMode:(SDImageScaleMode)contentMode;
2121
- (void)setAnimationRepeatCount:(nullable NSNumber *)repeatCount;
22+
- (void)setRunLoopMode:(nonnull NSRunLoopMode)runLoopMode;
23+
- (void)setPlaybackRate:(double)playbackRate;
24+
25+
/// Trigger the animation check when view appears/disappears
2226
- (void)updateAnimation;
2327

2428
@end

SDWebImageSwiftUI/Classes/ObjC/SDAnimatedImageInterface.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ @interface SDAnimatedImageInterface () {
5656
@property (nonatomic, assign, readwrite) NSUInteger currentLoopCount;
5757
@property (nonatomic, strong) NSNumber *animationRepeatCount;
5858
@property (nonatomic, assign) BOOL shouldAnimate;
59+
@property (nonatomic, copy) NSRunLoopMode runLoopMode;
60+
@property (nonatomic, assign) double playbackRate;
5961
@property (nonatomic,strong) SDAnimatedImagePlayer *player; // The animation player.
6062
@property (nonatomic) id<CALayerProtocol> imageViewLayer; // The actual rendering layer.
6163

@@ -68,6 +70,10 @@ - (instancetype)init {
6870
NSString *UUID = [NSUUID UUID].UUIDString;
6971
NSString *property = [NSString stringWithFormat:@"%@_%@", cls, UUID];
7072
self = [self _initForDynamicCreationWithInterfaceProperty:property];
73+
if (self) {
74+
self.runLoopMode = NSRunLoopCommonModes;
75+
self.playbackRate = 1.0;
76+
}
7177
return self;
7278
}
7379

@@ -125,11 +131,11 @@ - (void)setImage:(UIImage *)image {
125131
self.player.totalLoopCount = self.animationRepeatCount.unsignedIntegerValue;
126132
}
127133

128-
// // RunLoop Mode
129-
// self.player.runLoopMode = self.runLoopMode;
130-
//
131-
// // Play Rate
132-
// self.player.playbackRate = self.playbackRate;
134+
// RunLoop Mode
135+
self.player.runLoopMode = self.runLoopMode;
136+
137+
// Play Rate
138+
self.player.playbackRate = self.playbackRate;
133139

134140
// Setup handler
135141
__weak typeof(self) wself = self;

0 commit comments

Comments
 (0)