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.

Layout animation leave orphaned component in Expo

See original GitHub issue

Description

I found a strange behavior while trying to use react-native-reanimated layout animation with the latest Expo SDK (44). Component with layout animation seems to leave orphaned component at re-render. (related expo issue)

I have a simple conditional rendering, when the component mount it should display a spinner for 3000ms and then a list of (transparent for demo purpose) items. However, on the first render after the 3000ms the spinner AND the list are both visible at the same time.

If I reload the project everything works as expect. But as soon as I completely restart the app, this behavior happen.

I was able to reproduce this behavior in a fresh new app, I will include the steps bellow.

https://user-images.githubusercontent.com/23317360/146521672-a5c679cf-eff2-4ba8-baee-a99346778f37.mov

Expected behavior

The layout animation works as expected (and are, actually, awesome). But it seems to introduce a bug with conditional component rendering. In my case, after 3000ms, the spinner is supposed to be hidden and replaced by the list.

Actual behavior & steps to reproduce

At component mount a spinner is supposed to be visible during 3000ms. After this time, the spinner should be replaced by a scrollview.

Check my minimal code bellow.

Snack or minimal code example

// update to expo 44 (currently beta) to be able to use react-native-reanimated > 2

$ EXPO_BETA=1 expo init --npm
$ # Choose "blank (TypeScript)"
$ expo install react-native-reanimated react-native-screens

babel.config.js

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: ['react-native-reanimated/plugin'],
  };
};

App.tsx

import { useEffect, useState } from 'react';
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native';
import Animated, {
  FadeInUp,
  FadeOutDown,
  Layout,
} from 'react-native-reanimated';

const AnimatedView = Animated.createAnimatedComponent(View);

export default function App() {
  const [isLoading, setIsLoading] = useState<boolean>(true);

  useEffect(() => {
    const timeout = setTimeout(() => setIsLoading(false), 3000);
    return () => {
      clearTimeout(timeout);
    };
  }, []);

  return (
    <View style={styles.container}>
      {isLoading ? (
        <ActivityIndicator size='large' color='red' />
      ) : (
        <AnimatedView
          entering={FadeInUp}
          exiting={FadeOutDown}
          layout={Layout.springify()}
          style={styles.scrollContainer}
        >
          {[...Array(10).keys()].map((value) => (
            <View style={styles.row} key={value}>
              <Text>row n°{value}</Text>
            </View>
          ))}
        </AnimatedView>
      )}
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  scrollContainer: {
    flex: 1,
    width: '100%',
  },
  row: {
    flexDirection: 'row',
    backgroundColor: 'transparent',
    height: 50,
  },
});

Package versions

    "expo": "~44.0.0",
    "react-native": "0.64.3",
    "react-native-reanimated": "~2.3.1",
    "react-native-screens": "~3.10.1"

Node.js: v14.15.3

Affected platforms

  • Android : (not sure, unable to test at the moment)
  • iOS

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

8reactions
bryansumcommented, Dec 25, 2021

Calling enableLayoutAnimations(true) in App.tsx fixes this for me:

--- a/App.tsx
+++ b/App.tsx
@@ -1,12 +1,14 @@
 import { useEffect, useState } from "react";
 import { ActivityIndicator, StyleSheet, Text, View } from "react-native";
 import Animated, {
+  enableLayoutAnimations,
   FadeInUp,
   FadeOutDown,
   Layout,
 } from "react-native-reanimated";
 
 const AnimatedView = Animated.createAnimatedComponent(View);
+enableLayoutAnimations(true);

Also made a repo of the project detailed above ^ for ease of debugging: https://github.com/bryansum/reanimated-layout-repro

Would be interesting to see if this fixes things for anyone else.

3reactions
pairohit305commented, Dec 17, 2021

Thanks for reporting this issue man! I am facing same bug in my app Screenshot_2021 12 18_02 22 45 452 Overlapping on condition render and it goes if I manually refresh

Read more comments on GitHub >

github_iconTop Results From Across the Web

Layout Transitions | React Native Reanimated
The document explains how can you animate all layout changes for a specific view just by adding a single property to the view....
Read more >
NOK - River Thames Conditions
Olive leaves turning yellow, Tcl group bd, Algertshausen hofgut, Modern 1920's ... Orphan black season 2 episode 1 vimeo, Feca dofus jeux online,...
Read more >
The Promised Neverland - Wikipedia
The series follows a group of orphaned children in their plan to escape from their orphanage, after learning the dark truth behind their...
Read more >
Cytoscape.js
Graph theory / network library for analysis and visualisation - compatible with CommonJS/Node.js/Browserify/Webpack, AMD/Require.js, npm, ...
Read more >
wordlist ranked - Massachusetts Institute of Technology
... research university mail january full map reviews program life know games ... islands career military rental decision leave british teens pre sat...
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