Skip to content

Commit

Permalink
fix duration calculation for RCTUIImageViewAnimated
Browse files Browse the repository at this point in the history
Summary:
## Changelog:
[iOS] [Fixed] - Fix duration calculation for RCTUIImageViewAnimated

Reviewed By: p-sun, shergin

Differential Revision: D21321089

fbshipit-source-id: 7464231bbc3b90e70d3ba95288fd90707d3d24af
  • Loading branch information
Boyang Yu authored and facebook-github-bot committed May 1, 2020
1 parent 2047041 commit 12f8b25
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Libraries/Image/RCTUIImageViewAnimated.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,21 @@ - (void)displayDidRefresh:(CADisplayLink *)displayLink
// TODO: `displayLink.frameInterval` is not available on UIKitForMac
NSTimeInterval duration = displayLink.duration;
#else
NSTimeInterval duration = displayLink.duration * displayLink.preferredFramesPerSecond;
NSTimeInterval duration = displayLink.duration;
if (@available(iOS 10.0, *)) {
// Per https://developer.apple.com/documentation/quartzcore/cadisplaylink
// displayLink.duration provides the amount of time between frames at the maximumFramesPerSecond
// Thus we need to calculate true duration based on preferredFramesPerSecond
if (displayLink.preferredFramesPerSecond != 0) {
double maxFrameRate = 60.0; // default to 60 fps
if (@available(iOS 10.3, tvOS 10.3, *)) {
maxFrameRate = self.window.screen.maximumFramesPerSecond;
}
duration = duration * displayLink.preferredFramesPerSecond / maxFrameRate;
} // else respect maximumFramesPerSecond
} else { // version < (ios 10)
duration = duration * displayLink.frameInterval;
}
#endif
NSUInteger totalFrameCount = self.totalFrameCount;
NSUInteger currentFrameIndex = self.currentFrameIndex;
Expand Down

0 comments on commit 12f8b25

Please sign in to comment.