Button press animation — feedback on touch.
Scale animation:
1import { Animated, TouchableOpacity, Text, StyleSheet } from "react-native";23function AnimatedButton({ onPress, title }) {4 const scaleAnim = useRef(new Animated.Value(1)).current;56 const handlePressIn = () => {7 Animated.spring(scaleAnim, {8 toValue: 0.95,9 friction: 3,10 useNativeDriver: true,11 }).start();12 };1314 const handlePressOut = () => {15 Animated.spring(scaleAnim, {16 toValue: 1,17 friction: 3,18 useNativeDriver: true,19 }).start();20 };2122 return (23 <TouchableOpacity24 onPress={onPress}25 onPressIn={handlePressIn}26 onPressOut={handlePressOut}27 activeOpacity={1}28 >29 <Animated.View30 style={[styles.button, { transform: [{ scale: scaleAnim }] }]}31 >32 <Text style={styles.buttonText}>{title}</Text>33 </Animated.View>34 </TouchableOpacity>35 );36}3738const styles = StyleSheet.create({39 button: {40 backgroundColor: "#333",41 paddingHorizontal: 24,42 paddingVertical: 12,43 borderRadius: 8,44 },45 buttonText: { color: "white", fontSize: 16 },46});