-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement prefersReducedMotion on native #4039
Conversation
Your Render PR Server URL is https://social-app-pr-4039.onrender.com. Follow its progress at https://dashboard.render.com/web/srv-cp2la4a1hbls73e41oq0. |
|
The Pull Request introduced fingerprint changes against the base commit: 3674c8a Fingerprint diff[{"type":"dir","filePath":"node_modules/react-native-reanimated","reasons":["bareRncliAutolinking"],"hash":"edca9b4d869ae5a07b1b4af99e1bc2df6d0cec32"},{"type":"dir","filePath":"patches","reasons":["patchPackage"],"hash":"cbf4d74939a85a1082b8fc1888c43d2319fbeca2"}] Generated by PR labeler 🤖 |
Oh holy shit, was wanting to do this before but realized it wasn't available in the RN function. This is great. |
This is actually a global on native too, so if you wanted to you could drop the patch and access it directly through https://github.com/software-mansion/react-native-reanimated/blob/44d55dd3b6b92759fa820538d4f7c420bc8c2fa0/Common/cpp/ReanimatedRuntime/RNRuntimeDecorator.cpp#L41 With that said though, they actually used to get the value this way for Could be meaningless, could mean they intend to change it. The patch at least will tell us if it ever does change so that seems fine! |
Yep, I think the patch is a good canary for if their internal implementation changes |
Currently, we only get the
prefersReducedMotion
value on web. Luckily, Reanimated has auseReducedMotion
hook, but we need the value not in a hook. This PR uses the (internal)isReducedMotion
function from Reanimated since it does exactly the same thing on web, and gets the value as it is at app startup on native. Check the simple implementation herehttps://github.com/software-mansion/react-native-reanimated/blob/44d55dd3b6b92759fa820538d4f7c420bc8c2fa0/src/reanimated2/PlatformChecker.ts#L49
Note that the implementation of
useReducedMotion
is ultra simple and we could just call it here as not to rely on internal functions, but I think it's probably unsafe to break the rule of hooks here in case they change the implementation.https://github.com/software-mansion/react-native-reanimated/blob/44d55dd3b6b92759fa820538d4f7c420bc8c2fa0/src/reanimated2/hook/useReducedMotion.ts#L4