Apps supporting a dark theme frequently crash when the theme is toggled
See original GitHub issueCurrent behaviour
When switching between a light and a dark theme (e.g. by using the OSs theme setting in combination with the react-native Appearance API) the following error frequently occurs and the app crashes.
Error: Style property 'backgroundColor' is not supported by native animated module
Linked issue: #2063 #2574 #2167 #2641 Linked PR: #2113 #2068
Expected behaviour
Well, the app shouldn’t crash
Code sample
Any app with Dark Theme support, dedicated light and dark themes would work. (The app would also need to display one of the affected components described below). Expo go apparently doesn’t support system wide dark themes so one would need to copy this snack to hopefully have a working repro.
What have you tried
The root cause for this error is that the backgroundColor
of the Surface
component is calculated based on the Surfaces elevation (using the overlay()
helper). However, Card
, Button
and Chip
animate their elevation which causes their Surfaces backgroundColor
to be animated as well which causes said error.
There were attempts to fix this by disabling the native animation driver if toggling of the dark mode is detected. Unfortunately, these attempts did not cover all cases. Furthermore, disabling the native animation driver isn’t optimal for performance reasons.
What’s the Surface components expected behaviour here? Should its background color change when its elevation is animated? In this case we can’t use the native animation driver and should disable it for elevation animations of said components.
Or should the Surface component keep its background color when its evelation is animated? In this case we need a way to tell the Surface component which fixed elevation to use to calculate its background color.
Your Environment
software | version |
---|---|
ios or android | android |
react-native | 0.66.4 |
react-native-paper | 4.11.1 |
node | 14.18.2 |
npm or yarn | npm 8.3.0 |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:11 (2 by maintainers)
Top GitHub Comments
I’ve just came back from my holiday’s break and put the issue on my todo list. Will investigate it and do my best to prepare the fix.
Hey, I’ve refreshed the PR mentioned above, which is resolving the issue with
Card
animation drivers behavior related to switching the theme.Please try to install the library from the new PR: https://github.com/callstack/react-native-paper/pull/3041 and let me know about the result ✌🏽