-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
LayoutAnimations entering
and exiting
not working
#5395
Comments
Hey! 👋 The issue doesn't seem to contain a minimal reproduction. Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem? |
Same error here. It was working with V2, but after upgrading to V3 it sometimes worked, but not consistently. I'm using it on a series of screens that have the same animation, and sometimes the item just fades in partially, other times it just does nothing and gives me a transparent screen. I had this issue on both Android and IOS. <Animated.View
style={{ flex: 1 }}
layout={Layout.duration(300).delay(300)}
entering={FadeInUp}
exiting={FadeOut}
/> One thing I noticed was that it did render the component since the buttons I had inside the view still worked, and its children were also selectable in the element inspector. |
Hey @mrousavy, thanks again for reporting this issue.
The exiting animation is running (you can substitute 1.mov
Not really sure what this means, could you provide more details on what's the actual and expected behavior? One problem I can clearly see is that during the first render the position of the cards does not account for header height; this is a regression caused by some changes in react-native-screens, here's how it looks like:
I was able to reproduce this problem but it looks like it's caused by incorrect implementation of function getRandomColor(): string {
- return '#' + Math.floor(Math.random() * 16777215).toString(16);
+ return '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');
}
That's true, currently |
Thanks for the detailed insights Tomasz, really interesting! Regarding "2. Custom useAnimatedStyle not running on first mount": I am not sure what the issue there was as I am not able to reproduce it anymore - but in my app the back card was not rotated to the right when the app first starts, it was just behind the first card - no rotations applied. So it was invisible to the user. I'll try to reproduce that again when I get the chance! |
Hey all, I've opened previous issues with repros for some of these, hopefully they provide some more insight:
|
Currently chasing down a race condition with REA 3.6.1 and Bottom Sheet 4.6.0, that might be connected to @computerjazz but if we downgrade to REA 2 the issue doesn't seem to be there which isn't consistent with the bug report in #3296 I think. @mrousavy was |
Problem: Solution Attempt: Suggested Improvement: Additional Information: React Native Version: 0.72.6 |
## Summary In this PR #4969 I didn't include neither animatedStyles nor styles nested in arrays. That's why the problem wasn't reported in this example: #5395 closes #5395 |Before|After| |---|---| |<img width="387" alt="image" src="https://github.com/software-mansion/react-native-reanimated/assets/56199675/52c1de46-49d8-458c-ac4b-659bbcbca531">|<img width="387" alt="image" src="https://github.com/software-mansion/react-native-reanimated/assets/56199675/d12eb7d6-b409-41b8-873b-bc8cbc46e258">| ## Test plan <details><summary>Code</summary> ```jsx import Animated, { useAnimatedStyle, SlideInDown, ZoomOut, useDerivedValue, withSpring, interpolate, } from 'react-native-reanimated'; import { StyleSheet, View } from 'react-native'; import React, { useEffect, useState } from 'react'; interface Item { color: string; } function getRandomColor(): string { return '#' + Math.floor(Math.random() * 16777215).toString(16); } const Entering = SlideInDown.springify().mass(1).stiffness(1000).damping(500); const Exiting = ZoomOut.springify().mass(1).stiffness(1000).damping(500); function ItemComponent({ item, index }: { item: Item; index: number }) { const rotation = useDerivedValue(() => withSpring(index * 15), [index]); const animatedStyle = useAnimatedStyle(() => { return { zIndex: -index, backgroundColor: item.color, transform: [ { translateX: interpolate(rotation.value, [0, 100], [0, 100]), }, { translateY: interpolate(rotation.value, [0, 100], [0, -30]), }, { scale: interpolate(rotation.value, [0, 100], [1, 0.7]), }, { rotate: `${rotation.value}deg`, }, ], }; }, [rotation, index, item]); return ( <Animated.View entering={Entering} exiting={Exiting} style={[styles.item, animatedStyle]} /> ); } export default function StackedLayoutAnimationExample() { const [items, setItems] = useState<Item[]>([ { color: 'red' }, { color: 'green' }, ]); useEffect(() => { const interval = setInterval(() => { setItems((i) => [{ color: getRandomColor() }, ...i]); }, 1500); return () => clearInterval(interval); }, []); return ( <View style={styles.container}> {items.map((item, index) => { if (index > 2) { return null; } return <ItemComponent key={item.color} item={item} index={index} />; })} </View> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', }, item: { width: 100, height: 150, borderRadius: 15, position: 'absolute', }, }); ``` </details> --------- Co-authored-by: Aleksandra Cynk <aleksandracynk@Aleksandras-MacBook-Pro-3.local> Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
I'm having the same issue when updating from v2 to v3. why this issue was closed? |
Description
Hey yall,
I tried playing around with LayoutAnimations and I love the idea - they're so simple to implement, amazing work!
Screen_Recording_2023-11-14_at_17.36.31.mov
I did notice that there are a few bugs though.
I created a repro here that showcases those bugs: #5394
1. Exiting not running
The
exiting
animation is not running in the given example.2. Custom
useAnimatedStyle
not running on first mountOn the first mount, the
useAnimatedStyle
for the second card is not properly applied. I think this is a race condition where the LayoutAnimation takes precedence over theuseAnimatedStyle
.3. Some items not showing
Sometimes the items just don't show up.
4.
layout
instead ofuseAnimatedStyle
does not workWhen using
layout
instead of manually usinguseAnimatedStyle
it will not consider properties in thetransform
style.This is how I animate the slide & rotate to the right now:
This is how I want to do it:
Let me know if you need more details!
Steps to reproduce
#5394 <-- open the new page
Snack or a link to a repository
#5394
Reanimated version
3.5.0 (main)
React Native version
0.72.6
Platforms
Android, iOS
JavaScript runtime
Hermes
Workflow
React Native
Architecture
Paper (Old Architecture)
Build type
Debug mode
Device
iOS simulator
Device model
iPhone 15 Pro Simulator
Acknowledgements
Yes
The text was updated successfully, but these errors were encountered: