I'm getting an error when trying to use interpolate from react native reanimated. I want my button to go translate to to the negative Y axis when the opacity is being changed from 1 - 0. I have seen some tutorials on this but its a bit outdated. I was able to take a look at the docs and I am doing every thing correctly. I do not know where my error lies in. Please take a look:
import { TapGestureHandler,State } from 'react-native-gesture-handler';
import { StyleSheet, View,Text,Image,Dimensions } from 'react-native';
import Animated,{ useSharedValue,Easing, withTiming,useAnimatedStyle, Extrapolate,interpolate } from 'react-native-reanimated';
// import { useState } from 'react';
const {width,height} = Dimensions.get('window')
const { Value } = Animated
export default function LoginComp() {
const buttonOpacity = useSharedValue(1)
let animatedStyles = useAnimatedStyle(() => {
return {
opacity: buttonOpacity.value,
};
});
let buttonY = interpolate(buttonOpacity.value, {
inputRange:[0,1],
outputRange:[100,0],
extrapolate: Extrapolate.CLAMP
})
let bgY = interpolate(buttonOpacity.value, {
inputRange:[0,1],
outputRange:[-height / 3, 0],
extrapolate: Extrapolate.CLAMP
})
const onStateChange = ({ nativeEvent }) => {
if (nativeEvent.state === State.END) {
buttonOpacity.value = withTiming(0, {
duration: 500,
easing: Easing.out(Easing.exp),
});
}
}
// console.log(buttonOpacity.value)
return (
<View style={styles.logoContainer}>
<Animated.View style={{flex:1,justifyContent:'center', width:'100%',height:'100%',backgroundColor:'#353839',transform:[{translateY: bgY}] }}>
<Image style={styles.logo} source={require('../assets/Logo2.png')}/>
</Animated.View>
<View style={{ backgroundColor:'#353839',height:height/3 }}>
<TapGestureHandler onHandlerStateChange={onStateChange}>
<Animated.View style={[[styles.button, animatedStyles,{transform:[{translateY:buttonY}]}]]}>
<Text style={{ fontSize:25,fontWeight:'bold' }} >SIGN IN</Text>
</Animated.View>
</TapGestureHandler>
</View>
</View>
)
}
const styles = StyleSheet.create({
logoContainer: {
width: '100%',
height: '100%',
justifyContent: 'flex-end'
},
logo: {
position: 'absolute',
top: 70,
alignSelf: 'center',
width: 200,
height:200,
},
button: {
backgroundColor: '#fff',
height: 70,
marginHorizontal: 20,
borderRadius: 35,
alignItems: 'center',
justifyContent: 'center'
}
});
I have been on this for about 2 days now. I have checked everywhere but can't find any useful info. What am I missing?