I am trying to move my view off screen when the "Enter Now" button is pressed:
export class Onboarding extends Component {
constructor(props) {
super(props);
this.state = {
offsetX: new Animated.Value(0),
}
}
hideOnboarding() {
console.log("hiding"); // <-------- prints out when button pressed
Animated.timing(
this.state.offsetX,
{ toValue: new Animated.Value(-100) }
).start();
}
render() {
return (
<Animated.View style={{ transform: [{translateX: this.state.offsetX}] }}>
...
<TouchableOpacity onPress={ () => { this.hideOnboarding() } }>
<View style={styles.enterButton}>
<Text style={styles.buttonText}>Enter Now</Text>
</View>
</TouchableOpacity>
</Animated.View>
);
But nothing is moving when I tap my button. My console statement works though. Does anyone know what I'm doing wrong?
React Native TranslateY animation property style is used to move views in vertical Axis. Here if you enter animation toValue in + Plus then it will move views top to bottom. If we would pass toValue in – Minus then it will move view from bottom to top again.
Here if you enter animation toValue in + Plus then it will move views top to bottom. If we would pass toValue in – Minus then it will move view from bottom to top again. So in this tutorial we would move object view from top to bottom using TranslateY Position Animation Android iOS Tutorial.
Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
You can use the native driver by specifying useNativeDriver: true in your animation configuration. See the Animations guide to learn more. Only animatable components can be animated.
I think you need to change:
{ toValue: new Animated.Value(-100) }
to
{ toValue: -100 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With