Skip to content

Commit 5b0e44c

Browse files
committed
Add checking availability for webp animation
1 parent e711bb7 commit 5b0e44c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

MMMLoadable.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Pod::Spec.new do |s|
77

88
s.name = "MMMLoadable"
9-
s.version = "2.2.1"
9+
s.version = "2.2.2"
1010
s.summary = "A simple model for async calculations"
1111
s.description = "#{s.summary}."
1212
s.homepage = "https://github.com/mediamonks/#{s.name}"

Sources/MMMLoadableObjC/MMMLoadableImage.m

+15-4
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,28 @@ - (NSNumber *)imageAnimationDelayTime:(CGImageSourceRef)source {
224224
return nil;
225225
}
226226
NSDictionary *gifProps = (__bridge NSDictionary *)(CFDictionaryRef)CFDictionaryGetValue(props, kCGImagePropertyGIFDictionary);
227-
NSDictionary *webpProps = (__bridge NSDictionary *)(CFDictionaryRef)CFDictionaryGetValue(props, kCGImagePropertyWebPDictionary);
228-
CFRelease(props);
229227
if (gifProps) {
228+
CFRelease(props);
230229
return (NSNumber *)gifProps[(NSString *)kCGImagePropertyGIFDelayTime];
231-
} else if (webpProps) {
230+
} else if (@available(iOS 14.0, *)) {
231+
return [self webpAnimationDelayTime:props];
232+
} else {
233+
CFRelease(props);
234+
return nil;
235+
}
236+
}
237+
238+
- (NSNumber *)webpAnimationDelayTime: (CFDictionaryRef)props API_AVAILABLE(ios(14)) {
239+
NSDictionary *webpProps = (__bridge NSDictionary *)(CFDictionaryRef)CFDictionaryGetValue(props, kCGImagePropertyWebPDictionary);
240+
CFRelease(props);
241+
if (webpProps) {
232242
return (NSNumber *)webpProps[(NSString *)kCGImagePropertyWebPDelayTime];
233243
} else {
234244
return nil;
235245
}
236246
}
237247

248+
238249
/// [UIImage imageWithData:] does not decode GIFs as animated images, this is to correct that.
239250
- (UIImage *)imageWithData:(NSData *)data {
240251

@@ -270,7 +281,7 @@ - (UIImage *)imageWithData:(NSData *)data {
270281
[images addObject:image];
271282
}
272283

273-
NSTimeInterval delayTime = MAX([delayTimeNum doubleValue], 0.1);
284+
NSTimeInterval delayTime = MAX([delayTimeNum doubleValue], 0.04);
274285

275286
UIImage *result = [UIImage animatedImageWithImages:images duration:delayTime * count];
276287

0 commit comments

Comments
 (0)