Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Remove old GIF code #25636

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Libraries/Image/RCTImageLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;

@interface UIImage (React)

@property (nonatomic, copy) CAKeyframeAnimation *reactKeyframeAnimation;

/**
* Memory bytes of the image with the default calculation of static image or GIF. Custom calculations of decoded bytes can be assigned manually.
*/
Expand Down
19 changes: 1 addition & 18 deletions Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,12 @@

static NSInteger RCTImageBytesForImage(UIImage *image)
{
CAKeyframeAnimation *keyFrameAnimation = [image reactKeyframeAnimation];
NSInteger singleImageBytes = image.size.width * image.size.height * image.scale * image.scale * 4;
if (keyFrameAnimation) {
return keyFrameAnimation.values.count * singleImageBytes;
} else {
return image.images ? image.images.count * singleImageBytes : singleImageBytes;
}
return image.images ? image.images.count * singleImageBytes : singleImageBytes;
}

@implementation UIImage (React)

- (CAKeyframeAnimation *)reactKeyframeAnimation
{
return objc_getAssociatedObject(self, _cmd);
}

- (void)setReactKeyframeAnimation:(CAKeyframeAnimation *)reactKeyframeAnimation
{
objc_setAssociatedObject(self, @selector(reactKeyframeAnimation), reactKeyframeAnimation, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (NSInteger)reactDecodedImageBytes
{
NSNumber *imageBytes = objc_getAssociatedObject(self, _cmd);
Expand Down Expand Up @@ -280,11 +265,9 @@ - (void)setImageCache:(id<RCTImageCache>)cache
CGSizeEqualToSize(image.size, size)) {
return image;
}
CAKeyframeAnimation *animation = image.reactKeyframeAnimation;
CGRect targetSize = RCTTargetRect(image.size, size, scale, resizeMode);
CGAffineTransform transform = RCTTransformFromTargetRect(image.size, targetSize);
image = RCTTransformImage(image, size, scale, transform);
image.reactKeyframeAnimation = animation;
return image;
}

Expand Down
14 changes: 1 addition & 13 deletions Libraries/Image/RCTImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ - (void)cancelImageLoad
- (void)clearImage
{
[self cancelImageLoad];
[_imageView.layer removeAnimationForKey:@"contents"];
self.image = nil;
_imageSource = nil;
}
Expand Down Expand Up @@ -364,18 +363,7 @@ - (void)imageLoaderLoadedImage:(UIImage *)loadedImage error:(NSError *)error for
self->_pendingImageSource = nil;
}

[self->_imageView.layer removeAnimationForKey:@"contents"];
if (image.reactKeyframeAnimation) {
CGImageRef posterImageRef = (__bridge CGImageRef)[image.reactKeyframeAnimation.values firstObject];
if (!posterImageRef) {
return;
}
// Apply renderingMode to animated image.
self->_imageView.image = [[UIImage imageWithCGImage:posterImageRef] imageWithRenderingMode:self->_renderingMode];
[self->_imageView.layer addAnimation:image.reactKeyframeAnimation forKey:@"contents"];
} else {
self.image = image;
}
self.image = image;

if (isPartialLoad) {
if (self->_onPartialLoad) {
Expand Down
6 changes: 3 additions & 3 deletions Libraries/Image/RCTUIImageViewAnimated.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ - (void)setImage:(UIImage *)image
if (self.image == image) {
return;
}

[self stop];
[self resetAnimatedImage];

if ([image respondsToSelector:@selector(animatedImageFrameAtIndex:)]) {
[self stop];
[self resetAnimatedImage];

NSUInteger animatedImageFrameCount = ((UIImage<RCTAnimatedImage> *)image).animatedImageFrameCount;

// Check the frame count
Expand Down