import React, { useRef, useEffect } from 'react';
import { View, Text, StyleSheet, Animated } from 'react-native';
export const test = () => {
const scaleValue = useRef(new Animated.Value(1)).current;
useEffect(() => {
const heartbeat = Animated.loop(
Animated.sequence([
Animated.timing(scaleValue, {
toValue: 1.2,
duration: 300,
useNativeDriver: true,
}),
Animated.timing(scaleValue, {
toValue: 1,
duration: 300,
useNativeDriver: true,
}),
])
);
heartbeat.start();
return () => heartbeat.stop();
}, [scaleValue]);
return (
<View style={styles.container}>
<Animated.View style={[styles.box, { transform: [{ scale: scaleValue }] }]}>
<Text style={styles.text}>❤️</Text>
</Animated.View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
box: {
width: 150,
height: 150,
justifyContent: 'center',
alignItems: 'center',
},
text: {
fontSize: 50,
},
});