I want the text to move up when i click it. But even though the topPosition value is updated on click to -40, the View doesnt ever move. How can I make the animation run?
const TabButton = () => {
//Animation variables
const topPosition = useRef(new Animated.Value(1)).current;
const labelVisibility = useRef(false);
const pushIconUp = () => {
console.log('dwad');
Animated.timing(topPosition, {
toValue: -40,
duration: 1000,
useNativeDriver: false,
}).start();
console.log(topPosition);
};
const pushIconDown = () => {
Animated.timing(topPosition, {
toValue: 0,
duration: 100,
useNativeDriver: false,
}).start();
};
return (
<TouchableHighlight onPress={pushIconUp}>
<Animated.View style={{marginTop: topPosition, borderColor: 'white'}}>
<Text>daw</Text>
</Animated.View>
</TouchableHighlight>
);
};
export default TabButton;
I think it's better if you animate the translation instead and also the TouchableOpacity should be inside the Animated.View.
<Animated.View style={{ transform: [{ translateY: topPosition }], borderColor: 'white'}}>
<TouchableHighlight onPress={pushIconUp}>
<Text>daw</Text>
</TouchableHighlight>
</Animated.View>
You can also enable useNativeDriver