I have withRepeat animation and some useState value.
const [state, setState] = useState(0);
const val = useSharedValue(1);
val.value = withRepeat(withTiming(1.5, { duration: 2000 }), -1, true);
Any state change will fix the val.value range between 1.5 and the value at rerendering moment
val.value will change in [1, 1.5] range
val.value changes in [value at the rerendering moment, 1.5] range
function App() {
const [state, setState] = useState(0);
const val = useSharedValue(1);
val.value = withRepeat(withTiming(1.5, { duration: 2000 }), -1, true);
const debug = useDerivedValue(() => {
console.log(val.value);
return val.value;
});
const style = useAnimatedStyle(() => {
return {
transform: [{ scale: val.value }],
};
});
return (
<View style={styles.container}>
<Animated.View style={[styles.element, style]} />
<Button title="useless button" onPress={() => setState(state + 1)} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
element: {
backgroundColor: "red",
width: 100,
height: 100,
marginBottom: 50,
},
});
Hello!
Congratulations! Your issue passed the validator! Thank you!
can you try this?
useEffect(() => {
val.value = withRepeat(withTiming(1.5, { duration: 2000 }), -1, true);
}, [])
T
can you try this?
useEffect(() => { val.value = withRepeat(withTiming(1.5, { duration: 2000 }), -1, true); }, [])
this works, thank you!