I am learing about animation and react-native-gesture-handler in React Native on Youtube by this tutorial: https://www.youtube.com/watch?v=aoENL4gF9rE&t=201s.
The thing is I have the trouble in understanding these code, it will move the red box horizontally when user drag it.
class AnimApp extends Component {
constructor() {
this.translateX = new Animated.Value(0);
this.onGestureEvent = Animated.event([
{
nativeEvent: {
translationX: this.translateX,
},
},
]);
}
render() {
return (
<View style={styles.container}>
<PanGestureHandler onGestureEvent={this.onGestureEvent}>
<Animated.View
style={{...styles.box, transform: [{translateX: this.translateX}]}}
/>
</PanGestureHandler>
</View>
);
}
}
export default AnimApp;
I know in the transform part, the translateX
property is using this.translateX
to move the view, but I dont know how the this.translateX
have its value. I dont see any value is assigned to this.translateX
. I have console.log(this.translateX)
and its value changes when dragging, just dont know how the flow is.