interpolateColor on <Animated.Text /> causes warning
See original GitHub issueDescription
When interpolating the color of an <Animated.Text>
the following warning is displayed:
Warning: You are setting the style
{ color: ... }
as a prop. You should nest it in a style object. E.g.{ style: { color: ... } }
The animation works fine, however, the warning is annoying and I don’t want to ignore it as it may be an underlying issue of some sort.
Screenshots
Steps To Reproduce
const colorMap = useSharedValue(0);
const animatedPlaceholderStyles = useAnimatedStyle(() => ({
color: interpolateColor(
colorMap.value,
[0, 1, 2],
[inactiveColor, activeColor, errorColor]
),
}));
return (
<Animated.View style={[styles.container, animatedContainerStyle]}>
<Animated.Text
style={[styles.placeholder, animatedPlaceholderStyles]}
onLayout={handlePlaceholderLayout}
>
{placeholder}
</Animated.Text>
</Animated.View>
);
Expected behavior
No warning with expected animation.
Actual behavior
Warning with expected animation.
Snack or minimal code example
See above.
Package versions
- React: 16.13.1
- React Native: 0.63.4
- React Native Reanimated: 2.0.0-rc.0
- NodeJS: 12.18.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
interpolateColors | React Native Reanimated
Maps an input value within a range to an output value within a color range. Example: const color = Animated.interpolateColors( ...
Read more >Animated - React Native
The Animated library is designed to make animations fluid, powerful, and painless to build and maintain. Animated focuses on declarative ...
Read more >Reanimated 2 - the new approach to creating animations in ...
Reanimated 2 - exploring the new API to creating animations in React ... View, Text} from 'react-native' import { StyleSheet, View, Alert } ......
Read more >reactjs - React Native Animated: how to detect moment when ...
import Animated, { interpolateColor, useAnimatedStyle, ... the destination offset of the square - substitute whatever makes sense const ...
Read more >Animations in React Native: Performance and Reason-about ...
While discussing building smooth animations and gestures with a ... The color of the text. color: interpolateColor( percentComplete, [0, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After many, many hours of debugging, I finally have some insight into what causes this!
The native Objective C / Java node manager uses a whitelist to determine which props it can set natively. There is a Javascript function called
configureProps
that is responsible for building this whitelist and sending it down to the native code. This needs to happen before any rendering takes place, or the native Objective C / Javascript code will treat everything as a JS prop, which causes this warning.The tricky thing is that recent React Native versions load modules lazily by default. This means
configureProps
won’t have a chance to run until some poor animated component decides to render for the first time. By then, it’s too late. The nativeconfigureProps
call will get batched up on the bridge, and won’t execute until after the render completes with an empty whitelist.One super-hacky way to defeat the lazy module loading is to add code like this to the app’s
index.js
:This forces react-native-reanimated to download the whitelist before the app has a chance to render anything.
@swushi Thank you for the detailed description. I have reproduced the issue on the example app from your repository (using Reanimated 2.0.0-rc.0) by commenting out the
LogBox.ignore
calls.After bumping Reanimated to 2.0.0 to check if the problem persists on the latest release, I get the following error:
However, when I add your library as a dependency to our Reanimated 2 Example app, remove the
LogBox.ignore
calls from source code located innode_modules
and then replace any existing screen with one of the showcase examples, there are no warnings or errors at all (in particular, color interpolation works great). This suggests that there might be either a problem with using Reanimated 2 on Expo or some issue specific to your example app.