Skip to content

Commit 12f8b25

Browse files
Boyang Yufacebook-github-bot
Boyang Yu
authored andcommitted
fix duration calculation for RCTUIImageViewAnimated
Summary: ## Changelog: [iOS] [Fixed] - Fix duration calculation for RCTUIImageViewAnimated Reviewed By: p-sun, shergin Differential Revision: D21321089 fbshipit-source-id: 7464231bbc3b90e70d3ba95288fd90707d3d24af
1 parent 2047041 commit 12f8b25

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Libraries/Image/RCTUIImageViewAnimated.m

+15-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,21 @@ - (void)displayDidRefresh:(CADisplayLink *)displayLink
183183
// TODO: `displayLink.frameInterval` is not available on UIKitForMac
184184
NSTimeInterval duration = displayLink.duration;
185185
#else
186-
NSTimeInterval duration = displayLink.duration * displayLink.preferredFramesPerSecond;
186+
NSTimeInterval duration = displayLink.duration;
187+
if (@available(iOS 10.0, *)) {
188+
// Per https://developer.apple.com/documentation/quartzcore/cadisplaylink
189+
// displayLink.duration provides the amount of time between frames at the maximumFramesPerSecond
190+
// Thus we need to calculate true duration based on preferredFramesPerSecond
191+
if (displayLink.preferredFramesPerSecond != 0) {
192+
double maxFrameRate = 60.0; // default to 60 fps
193+
if (@available(iOS 10.3, tvOS 10.3, *)) {
194+
maxFrameRate = self.window.screen.maximumFramesPerSecond;
195+
}
196+
duration = duration * displayLink.preferredFramesPerSecond / maxFrameRate;
197+
} // else respect maximumFramesPerSecond
198+
} else { // version < (ios 10)
199+
duration = duration * displayLink.frameInterval;
200+
}
187201
#endif
188202
NSUInteger totalFrameCount = self.totalFrameCount;
189203
NSUInteger currentFrameIndex = self.currentFrameIndex;

0 commit comments

Comments
 (0)