react-native-paper: Darkmode Card onPress error with 4.0.x
Current behaviour
With darkmode enabled, when clicking on a Card component with onPress prop set, I get the following error:
Error: Style property 'backgroundColor' is not supported by native animated module, js engine: hermes
Expected behaviour
The onPress function should be executed and the Card background should be animated to become lighter.
Code sample
Just create any project rendering a card with the following props:
<Card
onPress={() => console.log("cc")}
>
<Text>Hello</Text>
</Card>
Screenshots (if applicable)
What have you tried
Tried switching to light mode, no issue. Tried to go back to 3.11.1, no issue.
Your Environment
software | version |
---|---|
ios or android | android (did not try iOS) |
react-native | 0.63.1 |
react-native-paper | 4.0.1 and 4.0.0 |
react-native-vector-icons | 7.0.0 |
node | 12.18.2 |
npm or yarn | npm 6.14.5 |
expo sdk | N/A |
JS engine | Hermes |
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 17 (4 by maintainers)
Commits related to this issue
- Only use the native driver if the compatible On dark themes, the default mode is adaptive. This mode will change the `backgroundColor`. This property is not animatable using the nativeDriver. Upstrea... — committed to SleeplessByte/react-native-paper by SleeplessByte 4 years ago
- fix: ensure compatible animation drive for cards On dark themes, the default mode is adaptive. This mode will change the `backgroundColor`. This property is not animatable using the nativeDriver. Ups... — committed to SleeplessByte/react-native-paper by SleeplessByte 4 years ago
- fix: ensure compatible animation driver for cards On dark themes, the default mode is adaptive. This mode will change the `backgroundColor`. This property is not animatable using the nativeDriver. Up... — committed to SleeplessByte/react-native-paper by SleeplessByte 4 years ago
If you use
...DarkTheme, mode: "exact",
then also everything is fine but not without exact mode
Need to reopen this
#2068 looks like solving the issue, but it still breaks if:
1: Currently on light theme 2: Press a card, for example, that opens a menu 3: The user quickly change mind and click a “toggle dark theme switch with adaptive mode”
What is happening is:
The Card component is still with the elevation animation running with
dark: false
, but suddenly thedark: true
and the animation breaks. Just as if we tried to start the animation with thedark: true
in the first place (partial solution by #2068).The problem is here in the Surface. At this line the elevation is using native driver with the dark theme (in this very specific case of running animation while toggling the theme).
@Trancever can you reopen?
@Keplyx if you’re still interested in a
patch-package
solution, the following preserves the native driver on light mode / exact mode and only uses the JS driver on dark adaptive mode.This is because using backgroundColor is not supported with the native driver, it’s an unresolved issue from 3 years ago: https://github.com/facebook/react-native/issues/14178
The problem is handlePressIn / handlePressOut functions for the Card component have
useNativeDriver: true
https://github.com/callstack/react-native-paper/blob/2ce47a149215bfe6c7c6cb8391a5096faf8a1266/src/components/Card/Card.tsx#L112
If you go and edit both of those functions to
useNativeDriver: false
, it will work fine.Yes but this means disabling the built-in DarkTheme, which is not a fix.
I updated the issue to include a link to a Snack example
I have the same issue. when I toggle on darkmode > the card module from react native paper throws an error for animated backgrouncColor.
This issue is only available on darkmode not on the normal theme
@SleeplessByte already solved at #2113
Yes it was changed for v4 with this PR #1787
As for editing the lib, I use patch-package to make small temporary patches that are relatively easy to maintain without needing to make a fork or track upstream.