Skip to content

Commit

Permalink
Enable animated gif playback on Mac (microsoft#724)
Browse files Browse the repository at this point in the history
* enable gif for mac

Summary:
I verify that it works for Zeratul as well. 

It also works regardless turbo module is enabled or not.

Test Plan: 
|{F369886201}|{F369889196}|



Reviewers: skyle

Reviewed By: skyle

Subscribers: zackargyle

Differential Revision: https://phabricator.intern.facebook.com/D26272145

Tasks: T82742678

Signature: 26272145:1612513052:520a8b0b3ab4b211c953b3225c6c96ffb8a29fc5

* bypass setImage logic when it is Mac

Summary: as titled

Test Plan:

{F370138978}

{F370139033}


Reviewers: skyle

Reviewed By: skyle

Subscribers: zackargyle

Differential Revision: https://phabricator.intern.facebook.com/D26288169

Signature: 26288169:1612565769:8f779fe01614e3399ac3e484853bb61246210ff4

* address PR comments

* address PR comments 1

Co-authored-by: Mo Wang <mowang@fb.com>
  • Loading branch information
2 people authored and HeyImChris committed Mar 1, 2021
1 parent 159dce1 commit 19f4a9c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Libraries/Image/RCTAnimatedImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ - (instancetype)initWithData:(NSData *)data scale:(CGFloat)scale

_imageSource = imageSource;

#if TARGET_OS_OSX // [TODO(macOS ISS#2323203)
self = [super initWithData:data];
#else // ]TODO(macOS ISS#2323203)
// grab image at the first index
UIImage *image = [self animatedImageFrameAtIndex:0];
if (!image) {
return nil;
}
#if TARGET_OS_OSX // [TODO(macOS ISS#2323203)
self = [image copy];
#else // ]TODO(macOS ISS#2323203)
self = [super initWithCGImage:image.CGImage scale:MAX(scale, 1) orientation:image.imageOrientation];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
Expand Down
11 changes: 5 additions & 6 deletions Libraries/Image/RCTUIImageViewAnimated.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ - (void)setImage:(UIImage *)image
return;
}

#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
#if TARGET_OS_OSX
[super setImage:image];
#else // TODO(macOS ISS#2323203)
[self stop];
#endif // TODO(macOS ISS#2323203)

[self resetAnimatedImage];

if ([image respondsToSelector:@selector(animatedImageFrameAtIndex:)]) {
Expand All @@ -116,19 +116,18 @@ - (void)setImage:(UIImage *)image
self.frameBuffer[@(self.currentFrameIndex)] = self.currentFrame;
dispatch_semaphore_signal(self.lock);

#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
// Calculate max buffer size
[self calculateMaxBufferCount];

if ([self paused]) {
[self start];
}
#endif // TODO(macOS ISS#2323203)


[self.layer setNeedsDisplay];
} else {
super.image = image;
}
#endif // TODO(macOS ISS#2323203)
}

#pragma mark - Private
Expand Down
2 changes: 1 addition & 1 deletion RNTester/js/examples/Image/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ exports.examples = [
/>
);
},
platform: 'ios',
platform: ['ios', 'macos'], // TODO(OSS Candidate ISS#2710739)
},
{
title: 'Base64 image',
Expand Down

0 comments on commit 19f4a9c

Please sign in to comment.