mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-17 09:10:30 +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 {
|
||||
// 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.
|
||||
self.image = [UIImage imageWithContentsOfFile:_URL.path];
|
||||
if (!self.image) {
|
||||
UIImage *nonAnimatedImage = [UIImage imageWithContentsOfFile:_URL.path];
|
||||
if (nonAnimatedImage == nil) {
|
||||
// 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.
|
||||
NSString *filename = [[NSBundle mainBundle] pathForResource:_URL.path.lastPathComponent ofType:nil];
|
||||
if (filename) {
|
||||
self.image = [UIImage imageWithContentsOfFile:filename];
|
||||
if (filename != nil) {
|
||||
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;
|
||||
|
@ -142,12 +142,21 @@ withDownloadIdentifier:(id)downloadIdentifier;
|
||||
|
||||
@protocol ASAnimatedImageProtocol <NSObject>
|
||||
|
||||
@optional
|
||||
|
||||
/**
|
||||
@abstract Should be called when the objects cover image is ready.
|
||||
@param coverImageReadyCallback a block which receives the cover image.
|
||||
*/
|
||||
@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
|
||||
|
||||
/**
|
||||
|
@ -56,6 +56,11 @@
|
||||
return self.fileReady;
|
||||
}
|
||||
|
||||
- (BOOL)isDataSupported:(NSData *)data
|
||||
{
|
||||
return [data pin_isGIF];
|
||||
}
|
||||
|
||||
@end
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user