question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apps supporting a dark theme frequently crash when the theme is toggled

See original GitHub issue

Current 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
lukewalczakcommented, Jan 10, 2022

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.

4reactions
lukewalczakcommented, Jan 14, 2022

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 ✌🏽

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do my App crashes when the AppTheme is changed
NOTE: I just noticed that the issue regarding menu icon colour, icons are white when the 'Dark Mode' is ON and black when...
Read more >
Dark-mode support on your Android app - Educative.io
Step 1: Change the theme to DayLight . Step 2: Turn on the dark theme. There you have it – run the app...
Read more >
How to turn on dark mode on all your apps and devices
Then tap 'Display' and go to 'Advanced'. Here you can toggle the dark theme on and off. If you don't want to go...
Read more >
Dark theme - Android Developers
There are three ways to enable Dark theme in Android 10 (API level 29) and higher: Use the system setting (Settings -> Display...
Read more >
How to Enable Dark Mode in Your Favorite Apps and Websites
Use promo code SIMPLETIVITY to upgrade your Taskade subscription for FREE! Select "Add promo code" on checkout and get a 1-year upgrade at ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found