Monday, May 20, 2024
194
rated 0 times [  197] [ 3]  / answers: 1 / hits: 17100  / 8 Years ago, wed, december 14, 2016, 12:00:00

I am trying to move my view off screen when the Enter Now button is pressed:



Screenshot



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?


More From » react-native

 Answers
20

I think you need to change:



{ toValue: new Animated.Value(-100) }


to



{ toValue: -100 }

[#59701] Tuesday, December 13, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dusty

Total Points: 739
Total Questions: 97
Total Answers: 85

Location: Angola
Member since Wed, Apr 13, 2022
2 Years ago
;