mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-13 18:00:17 +00:00
Merge pull request #1726 from ejensen/local-animated-image
[ASNetworkImageNode] Support loading local animated images
This commit is contained in:
commit
f72f39b445
@ -457,15 +457,32 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
|
|||||||
} else {
|
} else {
|
||||||
// First try to load the path directly, for efficiency assuming a developer who
|
// First try to load the path directly, for efficiency assuming a developer who
|
||||||
// doesn't want caching is trying to be as minimal as possible.
|
// doesn't want caching is trying to be as minimal as possible.
|
||||||
self.image = [UIImage imageWithContentsOfFile:_URL.path];
|
UIImage *nonAnimatedImage = [UIImage imageWithContentsOfFile:_URL.path];
|
||||||
if (!self.image) {
|
if (nonAnimatedImage == nil) {
|
||||||
// If we couldn't find it, execute an -imageNamed:-like search so we can find resources even if the
|
// If we couldn't find it, execute an -imageNamed:-like search so we can find resources even if the
|
||||||
// extension is not provided in the path. This allows the same path to work regardless of shouldCacheImage.
|
// extension is not provided in the path. This allows the same path to work regardless of shouldCacheImage.
|
||||||
NSString *filename = [[NSBundle mainBundle] pathForResource:_URL.path.lastPathComponent ofType:nil];
|
NSString *filename = [[NSBundle mainBundle] pathForResource:_URL.path.lastPathComponent ofType:nil];
|
||||||
if (filename) {
|
if (filename != nil) {
|
||||||
self.image = [UIImage imageWithContentsOfFile:filename];
|
nonAnimatedImage = [UIImage imageWithContentsOfFile:filename];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the file may be an animated gif and then created an animated image.
|
||||||
|
id<ASAnimatedImageProtocol> animatedImage = nil;
|
||||||
|
if (_downloaderImplementsAnimatedImage) {
|
||||||
|
NSData *data = [NSData dataWithContentsOfURL:_URL];
|
||||||
|
animatedImage = [_downloader animatedImageWithData:data];
|
||||||
|
|
||||||
|
if ([animatedImage respondsToSelector:@selector(isDataSupported:)] && [animatedImage isDataSupported:data] == NO) {
|
||||||
|
animatedImage = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (animatedImage != nil) {
|
||||||
|
self.animatedImage = animatedImage;
|
||||||
|
} else {
|
||||||
|
self.image = nonAnimatedImage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_imageLoaded = YES;
|
_imageLoaded = YES;
|
||||||
|
|||||||
@ -142,12 +142,21 @@ withDownloadIdentifier:(id)downloadIdentifier;
|
|||||||
|
|
||||||
@protocol ASAnimatedImageProtocol <NSObject>
|
@protocol ASAnimatedImageProtocol <NSObject>
|
||||||
|
|
||||||
|
@optional
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@abstract Should be called when the objects cover image is ready.
|
@abstract Should be called when the objects cover image is ready.
|
||||||
@param coverImageReadyCallback a block which receives the cover image.
|
@param coverImageReadyCallback a block which receives the cover image.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, strong, readwrite) void (^coverImageReadyCallback)(UIImage *coverImage);
|
@property (nonatomic, strong, readwrite) void (^coverImageReadyCallback)(UIImage *coverImage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
@abstract Returns whether the supplied data contains a supported animated image format.
|
||||||
|
@param data the data to check if contains a supported animated image.
|
||||||
|
*/
|
||||||
|
- (BOOL)isDataSupported:(NSData *)data;
|
||||||
|
|
||||||
|
|
||||||
@required
|
@required
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -56,6 +56,11 @@
|
|||||||
return self.fileReady;
|
return self.fileReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)isDataSupported:(NSData *)data
|
||||||
|
{
|
||||||
|
return [data pin_isGIF];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user