I have a button that if I click (which will be setting state to true), I want to set the transform value to a certain number
const [openShop, setOpenShop] = useState(false);
const [containerHeight, setContainerHeight] = useState('');
const [translateY, setTranslateY] = useState(0);
// ... more code where I set containerHeight
const onShopPress = () => {
setOpenShop(!openShop);
if (openShop) {
setTranslateY(-containerHeight);
} else {
setTranslateY(0);
}
console.log('shopping pressed');
};
<TouchableOpacity style={styles.shopBtn} onPress={onShopPress}>
<Animated.View
style={[styles.shopBtnView, {transform: [{translateY}]}]}>
<Text>Shop</Text>
</Animated.View>
</TouchableOpacity>
Right now, I have to press the button twice to actually get into openShop
block. The first click, it just goes to the else block.