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 not working as expected with other view

See original GitHub issue

Description

I’m try to use layout animtion with other view of react native. But i think, Layout Animation just create a copy element to animate not like animte layout as docs mentioned

Expected behavior

Animate my view same the docs

Actual behavior & steps to reproduce

Let’s see my code and my video

Snack or minimal code example

https://user-images.githubusercontent.com/43195241/150716485-7e59b651-0162-4a86-8c9d-530cee51a79d.mp4

import React, {memo, useState} from 'react';
import isEqual from 'react-fast-compare';
import {Button, Text, View} from 'react-native';
import Animated, {FadeIn, FadeOut, Layout} from 'react-native-reanimated';

const LoginComponent = () => {
  const [visible, setVisible] = useState<boolean>(false);
  // render
  return (
    <View style={{flex: 1, paddingVertical: 50}}>
      <Button
        title={'Toggle'}
        onPress={() => {
          setVisible(v => !v);
        }}
      />
      <Animated.View layout={Layout} style={{backgroundColor: 'green'}}>
        <Text>Layout</Text>
        {visible && (
          <Animated.View
            layout={Layout}
            entering={FadeIn}
            exiting={FadeOut}
            style={{width: 50, height: 50, backgroundColor: 'red'}}
          />
        )}
      </Animated.View>
      <View style={{backgroundColor: 'yellow', paddingVertical: 10}}>
        <Text>My Text</Text>
      </View>
    </View>
  );
};
export const Login = memo(LoginComponent, isEqual);

Package versions

name version
react-native 0.66.4
react-native-reanimated 2.3.1

Affected platforms

  • Android
  • [x ] iOS
  • Web

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
frankpena06commented, Jun 20, 2022

ok. with a more complex screen and want to use layout animation inside, i can’t use Animted.View for all parent.

I faced an issue like this. You just need to cover your parent element in <Animated.View/> Tag.

` <Animated.View style={{flex: 1, paddingVertical: 50}}> <Button title={‘Toggle’} onPress={() => { setVisible(v => !v); }} />

  <Animated.View layout={Layout} style={{backgroundColor: 'green'}}>
    <Text>Layout</Text>
    {visible && (
      <Animated.View
        layout={Layout}
        entering={FadeIn}
        exiting={FadeOut}
        style={{width: 50, height: 50, backgroundColor: 'red'}}
      />
    )}
  </Animated.View>
  <View style={{backgroundColor: 'yellow', paddingVertical: 10}}>
    <Text>My Text</Text>
  </View>

</Animated.View>

`

1reaction
tomekzawcommented, Jan 28, 2022

Hello! Can you please clarify what is the expected behaviour?

If you want the yellow box to animate smoothly to its target position instead of jumping immediately, please convert the component to Animated.View and use layout prop, similarly as for the green box:

-<View style={{backgroundColor: 'yellow', paddingVertical: 10}}>
+<Animated.View layout={Layout} style={{backgroundColor: 'yellow', paddingVertical: 10}}>
  <Text>My Text</Text>
-</View>
+</Animated.View>

Alternatively, if the issue is related to the red box layout animation when toggling it on and off faster than the duration of the animation, please clarify what is the expected behaviour so we can help you! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Layout animation not working on first run - Stack Overflow
My problem is, the first time I run the app, when I click on an item, the onClick callback is executed, but the...
Read more >
RecyclerView android:layoutAnimation not working
If you attempt to animate on a view that has not been rendered yet, the animation will occur on the view without a...
Read more >
Animation | Jetpack Compose - Android Developers
Many Jetpack Compose Animation APIs are available as composable functions just like layouts and other UI elements, and they are backed by lower-level...
Read more >
The little secret of android:animateLayoutChanges
A flag indicating the animation that runs on those items that are changing due to a layout change not caused by items being...
Read more >
How to fix ZStack's views disappear transition not animated in ...
The transition animation work as expected. Set the views below the problem view to a non-zero value. Depend on your view layout, set ......
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