I am using reanimated2
for my react native project. I want to dynamically change the animation to ZoomInLeft
or ZoomInRight
based on the situation:
export default function SigninCard(props){
const [zoomout,setZoomout] = useState('left')
function handleExiting(s){
console.log(s)
setZoomout(s)
}
<Animated.View
style={{flex:1, alignItems:'center'}}
entering={ZoomInRight}
exiting={zoomout=='left' ? ZoomOutLeft : ZoomOutRight}
...
<Button title='Register' onPress={()=>{
handleExiting('left');
parentgoto('userdetails';
)}}
/>
<Button title='Login' onPress={()=>{
handleExiting('right');
parentgoto('userdetails';
)}}
/>
</Animated.View>
}
Like to code above, I use zoomout
variable to decide if I want the animation to go right or left, then set ternary condition in exiting
. But somehow the animation will always go left. even I click on the right button.
After a few tests, I believe the decision factor is at the useState('left')
. even though I setZoomOut('right')
, it don't seems to change the state.
How can I resolve this? Or is there another way to achieve this?