From 12f8b2598fa46533ea59834a0225cc9e36b20111 Mon Sep 17 00:00:00 2001 From: Boyang Yu Date: Fri, 1 May 2020 12:37:58 -0700 Subject: [PATCH] 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 --- Libraries/Image/RCTUIImageViewAnimated.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Libraries/Image/RCTUIImageViewAnimated.m b/Libraries/Image/RCTUIImageViewAnimated.m index 979b9aff3a4336..8402d0e28bb958 100644 --- a/Libraries/Image/RCTUIImageViewAnimated.m +++ b/Libraries/Image/RCTUIImageViewAnimated.m @@ -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;