I have a code that will move the box up a bit when clicked on the 4th box, but I’m in trouble with the error I get, I keep getting the same error, error message = ERROR TypeError: undefined is not a constructor (evaluating ‘new _reactNativeReanimated.Value(0)’)
This error is located at:your text
in AnimatedProductList
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in mosquitosrep(RootComponent)
ERROR TypeError: undefined is not a constructor (evaluating ‘new _reactNativeReanimated.Value(0)’)
This error is located at:
in AnimatedProductList
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in mosquitosrep(RootComponent)
Methods I tried and it didn’t work:
cd android & gradlew clean
remove node_modules and npm i
hermes to false
npm start –reset-cache
my code
import React from 'react';
import { View, Text, StyleSheet, Dimensions, TouchableOpacity } from 'react-native';
import Animated, { Easing, timing, Value } from 'react-native-reanimated';
const { width } = Dimensions.get('window');
const AnimatedProductList = () => {
const translateY = new Value(0);
const animationDuration = 3000; // 3 seconds
const startAnimation = () => {
// Move the square 10 pixels up
timing(translateY, {
toValue: -10,
duration: animationDuration / 2,
easing: Easing.inOut(Easing.ease),
}).start(() => {
// After the first animation, return the square to its original position
timing(translateY, {
toValue: 0,
duration: animationDuration / 2,
easing: Easing.inOut(Easing.ease),
}).start();
});
};
return (
<View style={styles.container}>
<View style={styles.productBox}>
<Text style={styles.productName}>Product 1</Text>
</View>
<View style={styles.productBox}>
<Text style={styles.productName}>Product 2</Text>
</View>
<View style={styles.productBox}>
<Text style={styles.productName}>Product 3</Text>
</View>
<TouchableOpacity onPress={startAnimation}>
<Animated.View
style={[
styles.animatedContainer,
{
transform: [{ translateY }],
},
]}
>
<Text style={styles.productName}>Animated Product</Text>
</Animated.View>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-between',
padding: 15,
},
productBox: {
width: width / 2.2,
height: 100,
backgroundColor: 'lightgray',
marginBottom: 10,
alignItems: 'center',
justifyContent: 'center',
},
productName: {
fontSize: 18,
fontWeight: 'bold',
},
animatedContainer: {
width: width / 2.2,
height: 100,
backgroundColor: 'lightgray',
marginBottom: 10,
alignItems: 'center',
justifyContent: 'center',
},
});
export default AnimatedProductList;
my reanimated version 3.4.2(last version)
react-native-cli: 2.0.1
react-native: 0.72.4
I can’t use the reanimated module please help