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.

Opacity animations not working on Android with the native driver

See original GitHub issue

RN Version

react-native-cli: 2.0.1 react-native: 0.63.3

Environment Info

System: OS: Windows 10 10.0.19041 CPU: (12) x64 Intel® Core™ i7-8750H CPU @ 2.20GHz Memory: 7.62 GB / 15.85 GB Binaries: Node: 12.18.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Version 3.6.0.0 AI-192.7142.36.36.6241897 Visual Studio: Not Found Languages: Java: 1.8.0_221 - /c/Program Files/Java/jdk1.8.0_221/bin/javac Python: 3.7.4 - /c/Users/34683/AppData/Local/Programs/Python/Python37-32/python npmPackages: @react-native-community/cli: Not Found react: ^16.13.1 => 16.13.1 react-native: ^0.63.3 => 0.63.3 react-native-windows: ^0.63.3 => 0.63.3 npmGlobalPackages: react-native: Not Found

Problem

I updated my RN version, and for some reason, the opacity animations are not working now on Android if they run on the native driver.

In your code I have seen that opacity is still in the WHITE_LIST

/**
 * Styles allowed by the native animated implementation.
 *
 * In general native animated implementation should support any numeric property that doesn't need
 * to be updated through the shadow view hierarchy (all non-layout properties).
 */
const STYLES_WHITELIST = {
  opacity: true,
  transform: true,
  borderRadius: true,
  borderBottomEndRadius: true,
  borderBottomLeftRadius: true,
  borderBottomRightRadius: true,
  borderBottomStartRadius: true,
  borderTopEndRadius: true,
  borderTopLeftRadius: true,
  borderTopRightRadius: true,
  borderTopStartRadius: true,
  elevation: true,
  zIndex: true,
  /* ios styles */
  shadowOpacity: true,
  shadowRadius: true,
  /* legacy android transform properties */
  scaleX: true,
  scaleY: true,
  translateX: true,
  translateY: true,
};

but running this simple code doesn’t work on my Samsung Galaxy S8+

     Animated.parallel([
        Animated.timing(hidePanel, {
          toValue: 0,
          duration: 300,
          delay: 1500,
          easing: Easing.linear,
          useNativeDriver: true,
        }),
        Animated.timing(hideLogo, {
          toValue: 0,
          duration: 300,
          delay: 1000,
          easing: Easing.linear,
          useNativeDriver: true,
        }),
      ]).start();

        ...
       
       <Animated.View
        style={[
          StyleSheet.absoluteFill,
          {
            opacity: hidePanel,
          },
        ]}
      > 
         ...

Why is this happening? This is working good on IOS, but not on Android.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
michalpolakfortumcommented, Oct 20, 2020

It’s just one of possible solutions. As mentioned in https://github.com/facebook/react-native/issues/25318 another solution is to start opacity animation from different value than 1 (say 0.99 as an example). It’s an old issue and a pull have already been created for it (https://github.com/facebook/react-native/pull/25361) but was causing some issues and was reverted.

It seems that in certain circumstances animated component is being optimised away. According to docs testID disables optimisation and that’s probably why it works as well.

1reaction
michalpolakfortumcommented, Oct 13, 2020

It’s probably an old issue related to https://github.com/facebook/react-native/issues/25318. Also i found out that for some reason appending testID prop to Animated.View resolves the issue as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-native Animation.event style property is not supported
If I use opacity property - it works fine. opacity - works. height - didn't works. Without useNativeDriver: true - all works fine....
Read more >
Animations - React Native
The opacity property on the View is mapped to this animated value. ... this Animation will not render on Android while working fine...
Read more >
Navigate between fragments using animations
The Fragment API provides two ways to use motion effects and transformations to visually connect fragments during navigation.
Read more >
react-native-modal - npm
Start using react-native-modal in your project by running `npm i ... backdrop opacity, color and timing; Listeners for the modal animations ...
Read more >
Touchables | React Native Gesture Handler - Software Mansion
Gesture Handler's TouchableOpacity uses native driver for animations by default. If this causes problems for you, you can set useNativeAnimations prop to ...
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