Add a new optional method for SDAnimatedImage, because we want to do refactory of `Progressive Animated Loading`

This commit is contained in:
DreamPiggy 2019-11-04 02:21:28 +08:00
parent 5d5679a75b
commit c8b84c7575
2 changed files with 14 additions and 8 deletions

View File

@ -57,6 +57,12 @@
*/ */
@property (nonatomic, assign, readonly, getter=isAllFramesLoaded) BOOL allFramesLoaded; @property (nonatomic, assign, readonly, getter=isAllFramesLoaded) BOOL allFramesLoaded;
/**
Return the animated image coder if the image is created with `initWithAnimatedCoder:scale:` method.
@note We use this with animated coder which conforms to `SDProgressiveImageCoder` for progressive animation decoding.
*/
@property (nonatomic, strong, readonly, nullable) id<SDAnimatedImageCoder> animatedCoder;
@end @end
/** /**

View File

@ -32,7 +32,7 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
@interface SDAnimatedImage () @interface SDAnimatedImage ()
@property (nonatomic, strong) id<SDAnimatedImageCoder> coder; @property (nonatomic, strong) id<SDAnimatedImageCoder> animatedCoder;
@property (nonatomic, assign, readwrite) SDImageFormat animatedImageFormat; @property (nonatomic, assign, readwrite) SDImageFormat animatedImageFormat;
@property (atomic, copy) NSArray<SDImageFrame *> *loadedAnimatedImageFrames; // Mark as atomic to keep thread-safe @property (atomic, copy) NSArray<SDImageFrame *> *loadedAnimatedImageFrames; // Mark as atomic to keep thread-safe
@property (nonatomic, assign, getter=isAllFramesLoaded) BOOL allFramesLoaded; @property (nonatomic, assign, getter=isAllFramesLoaded) BOOL allFramesLoaded;
@ -156,7 +156,7 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
self = [super initWithCGImage:image.CGImage scale:MAX(scale, 1) orientation:image.imageOrientation]; self = [super initWithCGImage:image.CGImage scale:MAX(scale, 1) orientation:image.imageOrientation];
#endif #endif
if (self) { if (self) {
_coder = animatedCoder; _animatedCoder = animatedCoder;
NSData *data = [animatedCoder animatedImageData]; NSData *data = [animatedCoder animatedImageData];
SDImageFormat format = [NSData sd_imageFormatForImageData:data]; SDImageFormat format = [NSData sd_imageFormatForImageData:data];
_animatedImageFormat = format; _animatedImageFormat = format;
@ -207,7 +207,7 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
if (!animatedCoder) { if (!animatedCoder) {
return self; return self;
} }
_coder = animatedCoder; _animatedCoder = animatedCoder;
SDImageFormat format = [NSData sd_imageFormatForImageData:animatedImageData]; SDImageFormat format = [NSData sd_imageFormatForImageData:animatedImageData];
_animatedImageFormat = format; _animatedImageFormat = format;
} }
@ -229,15 +229,15 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
#pragma mark - SDAnimatedImage #pragma mark - SDAnimatedImage
- (NSData *)animatedImageData { - (NSData *)animatedImageData {
return [self.coder animatedImageData]; return [self.animatedCoder animatedImageData];
} }
- (NSUInteger)animatedImageLoopCount { - (NSUInteger)animatedImageLoopCount {
return [self.coder animatedImageLoopCount]; return [self.animatedCoder animatedImageLoopCount];
} }
- (NSUInteger)animatedImageFrameCount { - (NSUInteger)animatedImageFrameCount {
return [self.coder animatedImageFrameCount]; return [self.animatedCoder animatedImageFrameCount];
} }
- (UIImage *)animatedImageFrameAtIndex:(NSUInteger)index { - (UIImage *)animatedImageFrameAtIndex:(NSUInteger)index {
@ -248,7 +248,7 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
SDImageFrame *frame = [self.loadedAnimatedImageFrames objectAtIndex:index]; SDImageFrame *frame = [self.loadedAnimatedImageFrames objectAtIndex:index];
return frame.image; return frame.image;
} }
return [self.coder animatedImageFrameAtIndex:index]; return [self.animatedCoder animatedImageFrameAtIndex:index];
} }
- (NSTimeInterval)animatedImageDurationAtIndex:(NSUInteger)index { - (NSTimeInterval)animatedImageDurationAtIndex:(NSUInteger)index {
@ -259,7 +259,7 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
SDImageFrame *frame = [self.loadedAnimatedImageFrames objectAtIndex:index]; SDImageFrame *frame = [self.loadedAnimatedImageFrames objectAtIndex:index];
return frame.duration; return frame.duration;
} }
return [self.coder animatedImageDurationAtIndex:index]; return [self.animatedCoder animatedImageDurationAtIndex:index];
} }
@end @end