Skip to content
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

Style property 'backgroundColor' is not supported by native animated module #14178

Closed
mongris opened this issue May 25, 2017 · 12 comments
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@mongris
Copy link

mongris commented May 25, 2017

Description

I am trying to animate backgroundColor with scrollView, but got

Style property 'backgroundColor' is not supported by native animated module

But accoding to the blog post it has be supported.

Not everything you can do with Animated is currently supported in Native Animated. The main limitation is that you can only animate non-layout properties, things like transform, opacity and backgroundColor will work but flexbox and position properties won't. Another one is with Animated.event, it will only work with direct events and not bubbling events. This means it does not work with PanResponder but does work with things like ScrollView#onScroll.

Please help me to figure out how to animate backgroundColor with useNativeDriver or is it still not support (the blog post is wrong)?

Reproduction Steps and Sample Code

Some code like:

const  _scrollPos = new Animated.Value(0);
const  _scrollSinkX = Animated.event(
    [{ nativeEvent: { contentOffset: { x: this._scrollPos } } }],
    { useNativeDriver: true });

<Animated.ScrollView
  onScrol={_scrollSinkX}
>
  {items}
</Animated.ScrollView>

const animatedStyle = _scrollPos.interpolate({
  inputRange: [0, 100],
  outputRange: ['rgba(255, 0, 0, 1)', 'rgba(0, 255, 0, 1)']
});

<Animated.View
  style={animatedStyle}
>{children}</Animated.View>

Solution

None

I were trying to simple add 'backgroundColor: true' to


but not working.

Additional Information

  • React Native version: 0.44
  • Platform: iOS
  • Development Operating System: macOS
  • Dev tools: XCode
@julienvincent
Copy link

I just hit this problem myself while using it on a <View />. Cannot use native driver for backgroundColor.

@janicduplessis
Copy link
Contributor

This is an error in the documentation, backgroundColor is not supported at the moment.

@chrisknepper
Copy link
Contributor

chrisknepper commented Jul 12, 2017

@janicduplessis Is there a way to use the JS driver, i.e. by passing useNativeDrive: false? My calls to Animated.timing look like:

Animated.parallel([
	Animated.timing(sectionData.animatedBackgroundValue, {
		toValue: targetAnimationValue,
		duration: 500,
		useNativeDriver: false
	}),
	Animated.timing(sectionData.animatedValue, {
		toValue: targetAnimationValue,
		duration: 500,
		useNativeDriver: false
	})
]).start();

But I still get an error:

Attempting to run JS driven animation on animated node that has been moved to "native" earlier by starting an animation with `useNativeDriver: true`

This is with react-native 0.45.1

@janicduplessis
Copy link
Contributor

@chrisknepper Native and non-native drivers are not compatible so you need to use either one per animated value. If you get this error it is probably because you use useNativeDriver on another animation for the same animated value.

@JanPeter
Copy link

JanPeter commented Jul 15, 2017

Is there any roadmap when style properties like height or backgroundColor will be supported by native animations?

Especially for things like animating the navigation header when transitioning from one to another screen this would be awesome! 👍

@janicduplessis
Copy link
Contributor

It's not on the roadmap at the moment, backgroundColor should not be that bad to implement but layout properties like height is a lot harder. You can usually get around those limitations by using opacity with multiple stacked views and LayoutAnimation.

@JanPeter
Copy link

Thanks for the quick reply! Actually never thought about using opacity for the backgroundColor, thanks! 👍
Can I use LayoutAnimation in combination with native animations? Not planning on using it at the moment, just curious if it will work since the Animated Value is no compatible with the native Animated Value.

@janicduplessis
Copy link
Contributor

LayoutAnimation doesn't use animated values so it should not be an issue, LayoutAnimation is a lot less flexible but it makes some animations that are hard to do with Animated pretty easy.

@JanPeter
Copy link

Thanks, I'll have a look into that :)

@Palisand
Copy link

@janicduplessis Any news on this?

@pintocarlos
Copy link

Does LayoutAnimation use the ui thread like the animated driver? Also, which properties are supported by LayoutAnimation? Blog post says layout and position, but what about borderRadius, border, and margin?

@pintocarlos
Copy link

I was able to confirm that borderRadius and margin are also animated, but padding is not. Native driver is used yes.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 14, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants