Skip to content

Commit e456b38

Browse files
committed
Support to custom loop count on watchOS AnimatedImage
1 parent a9fa353 commit e456b38

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ public struct AnimatedImage : PlatformViewRepresentable {
383383
// disable custom loop count
384384
view.wrapped.shouldCustomLoopCount = false
385385
}
386+
#elseif os(watchOS)
387+
if let customLoopCount = imageConfiguration.customLoopCount {
388+
view.wrapped.setAnimationRepeatCount(customLoopCount as NSNumber)
389+
} else {
390+
// disable custom loop count
391+
view.wrapped.setAnimationRepeatCount(nil)
392+
}
386393
#endif
387394
}
388395
}

SDWebImageSwiftUI/Classes/SDAnimatedImageInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
1414

1515
- (instancetype)init WK_AVAILABLE_WATCHOS_ONLY(6.0);
1616
- (void)setContentMode:(SDImageScaleMode)contentMode;
17+
- (void)setAnimationRepeatCount:(nullable NSNumber *)repeatCount;
1718

1819
@end
1920

SDWebImageSwiftUI/Classes/SDAnimatedImageInterface.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ @interface SDAnimatedImageInterface () {
5959
@property (nonatomic, strong) UIImage<SDAnimatedImage> *animatedImage;
6060
@property (nonatomic, assign) CGFloat animatedImageScale;
6161
@property (nonatomic, strong) SDAnimatedImageStatus *currentStatus;
62+
@property (nonatomic, strong) NSNumber *animationRepeatCount;
6263

6364
@end
6465

@@ -136,7 +137,12 @@ - (void)setImage:(UIImage *)image {
136137

137138
- (void)startBuiltInAnimationWithImage:(UIImage<SDAnimatedImage> *)animatedImage {
138139
NSData *animatedImageData = animatedImage.animatedImageData;
139-
NSUInteger maxLoopCount = 0;
140+
NSUInteger maxLoopCount;
141+
if (self.animationRepeatCount != nil) {
142+
maxLoopCount = self.animationRepeatCount.unsignedIntegerValue;
143+
} else {
144+
maxLoopCount = animatedImage.animatedImageLoopCount;
145+
}
140146
if (maxLoopCount == 0) {
141147
// The documentation says `kCFNumberPositiveInfinity may be used`, but it actually treat as 1 loop count
142148
// 0 was treated as 1 loop count as well, not the same as Image/IO or UIKit

0 commit comments

Comments
 (0)