Repository navigation
iOS: run native-driven animations above 60 fps on ProMotion screens - #60384
chrfalch-bot wants to merge 1 commit into
Conversation
On 120 Hz iPhones, native-driven animations ran at 60 fps because no CADisplayLink driving them set preferredFrameRateRange. Add RCTAdaptiveFrameRate and RCTAdaptiveFrameRateController. On screens faster than 60 Hz they request the screen maximum and step down to 60, 30 or 24 fps when the average work time of the last four frames exceeds the frame budget, the same tiers Reanimated uses. The range is written only when the tier changes. Apply it to the display links of the old native driver, the C++ animated driver and RCTAnimationChoreographer. Screens at 60 Hz or below are untouched. The JS requestAnimationFrame display link is unchanged. RNTester and HelloWorld set CADisableMinimumFrameDurationOnPhone, which iPhone apps need to go above 60 fps.
|
Hi @chrfalch-bot! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Summary
On 120 Hz iPhones (ProMotion), animations that use the native driver run at only 60 fps. None of the display links that drive them ask iOS for a higher frame rate, and the repo's apps do not opt in to rates above 60 Hz.
This change makes those display links ask for up to the screen's top rate. When frames take too long, they step down to 60, 30 or 24 fps, the same steps Reanimated uses. Screens at 60 Hz or below are not affected. RNTester and HelloWorld opt in with Apple's
CADisableMinimumFrameDurationOnPhoneInfo.plist key. There is no feature flag.How to check: run
RNTesterUnitTests. All 22RCTAdaptiveFrameRateTestsshould pass.This PR does not depend on any other PR.
Details
New helper:
React/Base/RCTAdaptiveFrameRate.{h,m}RCTAdaptiveFrameRatekeeps the work times of the last 4 frames. It picks the highest step whose frame budget is larger than their average. The steps request these ranges:(60, max, max),(30, 60, 60),(24, 30, 30)and(10, 24, 24), wheremaxis the screen's maximum fps, as in Reanimated'sAnimationFrameQueue.mm. It moves back up when the work gets cheaper. A maximum below 60 is treated as 60.+adaptiveFrameRateForMaximumFramesPerSecond:returns nil at 60 Hz or below.RCTAdaptiveFrameRateControllerrecords each tick's work time and setspreferredFrameRateRangeonly when the step changes. It is used only on the display-link tick, on the main thread, so nothing on the stop or invalidate paths touches it. It starts over when the display link changes (tracked through a weak reference) or when more than 250 ms pass between ticks, which covers pause and resume.UIScreenis read on the main thread only, on the first tick.Call sites
RCTNativeAnimatedNodesManager.mm: the old native driver.RCTAnimatedModuleProvider.mm: the C++ animated driver, iOS branch only.RCTScheduler.mm: the display link ofRCTAnimationChoreographer.Deliberately unchanged
RCTDisplayLink(JSrequestAnimationFrame) stays at 60 fps. Its JS work runs after the tick, so the tick cannot measure it, and Reanimated leaves it alone too.@availablecheck. The minimum is iOS 15.1, andpreferredFrameRateRangeexists since iOS 15.0.Follow-up
Changelog:
[IOS] [CHANGED] - Native-driven animations can run above 60 fps on ProMotion displays. Apps opt in with
CADisableMinimumFrameDurationOnPhone.Test Plan:
xcodebuild test -workspace packages/rn-tester/RNTesterPods.xcworkspace -scheme RNTester -only-testing:RNTesterUnitTestson the iPhone 18 Pro simulator.RCTAdaptiveFrameRateTests: 22 of 22 passed. They cover step choice and its boundaries, the 4-frame average, moving back up, skipping screens at 60 Hz or below, writing only on a change, the below-60 limit, and the controller starting over on a new display link and after a pause.RCTBundleURLProviderTests testBundleURL, which needs Metro, and Metro was not running.clang-formaton the changed native files: clean.Animatedloop withuseNativeDriver: truein RNTester on a 120 Hz iPhone and watch the frame rate in Instruments or the performance HUD.