Comments (3)
@Julioevm Hi there, it looks to me like your CustomExitingAnimation
is not working because your shared value never gets updated (it's using initial value all the time, so value from the very first render). Also there is no need to store animation directions inside state, you can store it directly as a shared value, pass it to the children component and then use useDerivedValue
in order to access it.
I've modified your example to achieve proper exiting animation. Please check below
import { Text, StyleSheet, View, SafeAreaView, Button } from 'react-native';
import React, { useState } from 'react';
import Animated, {
SlideOutRight,
SlideOutLeft,
useSharedValue,
useDerivedValue,
ExitAnimationsValues,
SharedValue,
} from 'react-native-reanimated';
const slideOutLeftAnimation = new SlideOutLeft().build();
const slideOutRightAnimation = new SlideOutRight().build();
function Card({ animation }: { animation: Readonly<SharedValue> }) {
const animationDirection = useDerivedValue(() => animation.value);
const CustomExitingAnimation = (values: ExitAnimationsValues) => {
'worklet';
return animationDirection.value === 'right'
? slideOutLeftAnimation(values)
: slideOutRightAnimation(values);
};
return (
<Animated.View exiting={CustomExitingAnimation}>
<View style={styles.cardContainer}>
<Text style={styles.paragraph}>Let's go</Text>
</View>
</Animated.View>
);
}
export default function App() {
const [number, setNumber] = useState(0);
const animation = useSharedValue('right');
const nextButton = () => {
animation.value = 'right';
setNumber((n) => n + 1);
};
const prevButton = () => {
animation.value = 'left';
setNumber((n) => n - 1);
};
return (
<SafeAreaView style={styles.container}>
<Card key={number} animation={animation} />
<View style={styles.buttonWrapper}>
<Button onPress={prevButton} title={'prev'} />
<Button onPress={nextButton} title={'next'} />
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
buttonWrapper: {
flexDirection: 'row',
},
cardContainer: {
alignItems: 'center',
justifyContent: 'center',
padding: 24,
backgroundColor: 'aquamarine',
margin: 20,
},
});
from react-native-reanimated.
+1
from react-native-reanimated.
Thanks a lot @exploIF!
from react-native-reanimated.
Related Issues (20)
- 1st item in an inverted list is no longer animated after a while with itemLayoutAnimation HOT 1
- expo 51.0.7 CRASH [TypeError: animatedRef.getTag is not a function (it is undefined)] HOT 3
- useAnimatedKeyboard break navigation color HOT 5
- Found Error TypeScript when run yarn tsc HOT 2
- Task :react-native-reanimated:buildCMakeRelWithDebInfo[armeabi-v7a] FAILED HOT 4
- Entering and/or layout animation flickering when SafeAreaView is a first parent of an animated component HOT 1
- > java.net.SocketException: Connection reset HOT 1
- iOS build faied: ld: Undefined symbols HOT 3
- SVG Polygon Animation not working HOT 1
- [3.12.0] TypeError: property is not configurable on useAnimatedStyle hook HOT 12
- useSharedValue `modify` does not exist, but shows in docs HOT 1
- Animated component issue: touchables and TextInputs inside the Animated.ScrollView are not responsive HOT 3
- web: AnimatedComponent raises a deprecation warning for findDOMNode in v3.12.0 HOT 4
- React Native Reanimated Not Responsive HOT 5
- Invalid `RNReanimated.podspec` file: [Reanimated] Unsupported React Native version. Please use 0.71 or newer. HOT 3
- Android build failure v3.12.0 HOT 10
- Impossible to animate any SVG color on android HOT 5
- 3.12.0 crashes with 'property is not configurable' HOT 11
- Performance regression or race condition between UI and JS threads
- RangeError: Set maximum size exceeded HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-reanimated.