Countdown animation — animated number display.
Implementation:
1import { Animated, Text, StyleSheet } from "react-native";23function Countdown({ from, to, duration }) {4 const animatedValue = useRef(new Animated.Value(from)).current;5 const [displayValue, setDisplayValue] = useState(from);67 useEffect(() => {8 animatedValue.addListener(({ value }) => {9 setDisplayValue(Math.round(value));10 });1112 Animated.timing(animatedValue, {13 toValue: to,14 duration: duration * 1000,15 useNativeDriver: false,16 }).start();1718 return () => animatedValue.removeAllListeners();19 }, []);2021 const scale = animatedValue.interpolate({22 inputRange: [to, from],23 outputRange: [1, 1.5],24 });2526 return (27 <Animated.Text style={{28 fontSize: 48,29 transform: [{ scale }],30 }}>31 {displayValue}32 </Animated.Text>33 );34}