Skip to content

Commit 4736821

Browse files
committed
Fix the compile issue on other platforms
1 parent cf588c8 commit 4736821

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

SDWebImageSwiftUI/Classes/SDAnimatedImageInterface.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
* file that was distributed with this source code.
77
*/
88

9-
#import <WatchKit/WatchKit.h>
109
#import <SDWebImage/SDWebImage.h>
11-
12-
NS_ASSUME_NONNULL_BEGIN
13-
10+
#if SD_WATCH
1411
@interface SDAnimatedImageInterface : WKInterfaceImage
1512

1613
- (instancetype)init WK_AVAILABLE_WATCHOS_ONLY(6.0);
1714
- (void)setContentMode:(SDImageScaleMode)contentMode;
1815

1916
@end
20-
21-
NS_ASSUME_NONNULL_END
17+
#endif

SDWebImageSwiftUI/Classes/SDAnimatedImageInterface.m

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
*/
88

99
#import "SDAnimatedImageInterface.h"
10+
#if SD_WATCH
1011
#import <SDWebImage/SDWebImage.h>
1112
#import <ImageIO/CGImageAnimation.h>
1213

14+
#pragma mark - SPI
15+
1316
@protocol CALayerProtocol <NSObject>
1417
@property (nullable, strong) id contents;
1518
@property CGFloat contentsScale;
@@ -65,6 +68,15 @@ - (instancetype)init {
6568
return self;
6669
}
6770

71+
- (NSDictionary *)interfaceDescriptionForDynamicCreation {
72+
// This is called by WatchKit
73+
return @{
74+
@"type" : @"image",
75+
@"property" : self.interfaceProperty,
76+
@"image" : [self.class sharedEmptyImage]
77+
};
78+
}
79+
6880
+ (UIImage *)sharedEmptyImage {
6981
// This is used for placeholder on `WKInterfaceImage`
7082
// Do not using `[UIImage new]` because WatchKit will ignore it
@@ -83,14 +95,6 @@ + (UIImage *)sharedEmptyImage {
8395
return image;
8496
}
8597

86-
-(NSDictionary *)interfaceDescriptionForDynamicCreation {
87-
return @{
88-
@"type" : @"image",
89-
@"property" : self.interfaceProperty,
90-
@"image" : [self.class sharedEmptyImage]
91-
};
92-
}
93-
9498
- (void)setImage:(UIImage *)image {
9599
if (_image == image) {
96100
return;
@@ -218,12 +222,22 @@ - (void)setContentMode:(SDImageScaleMode)contentMode {
218222
[self _interfaceView].contentMode = contentMode;
219223
}
220224

225+
@end
226+
227+
#pragma mark - Web Cache
228+
229+
@interface SDAnimatedImageInterface (WebCache)
230+
231+
@end
232+
233+
@implementation SDAnimatedImageInterface (WebCache)
234+
221235
- (void)sd_setImageWithURL:(nullable NSURL *)url
222-
placeholderImage:(nullable UIImage *)placeholder
223-
options:(SDWebImageOptions)options
224-
context:(nullable SDWebImageContext *)context
225-
progress:(nullable SDImageLoaderProgressBlock)progressBlock
226-
completed:(nullable SDExternalCompletionBlock)completedBlock {
236+
placeholderImage:(nullable UIImage *)placeholder
237+
options:(SDWebImageOptions)options
238+
context:(nullable SDWebImageContext *)context
239+
progress:(nullable SDImageLoaderProgressBlock)progressBlock
240+
completed:(nullable SDExternalCompletionBlock)completedBlock {
227241
Class animatedImageClass = [SDAnimatedImage class];
228242
SDWebImageMutableContext *mutableContext;
229243
if (context) {
@@ -239,10 +253,11 @@ - (void)sd_setImageWithURL:(nullable NSURL *)url
239253
setImageBlock:nil
240254
progress:progressBlock
241255
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
242-
if (completedBlock) {
243-
completedBlock(image, error, cacheType, imageURL);
244-
}
245-
}];
256+
if (completedBlock) {
257+
completedBlock(image, error, cacheType, imageURL);
258+
}
259+
}];
246260
}
247261

248262
@end
263+
#endif

0 commit comments

Comments
 (0)