$ git show copy-feedback
Copy feedback
Tap copy and the icon pops into a green check with a Copied label, then swaps back on its own.
CopyCopied
// Unchanged in Reanimated 4: entering/exiting layout animations still swap the icons
import Animated, { ZoomIn, ZoomOut, FadeIn, FadeOut } from 'react-native-reanimated';
import * as Clipboard from 'expo-clipboard';
const [copied, setCopied] = useState(false);
const timer = useRef();
const copy = async () => {
await Clipboard.setStringAsync(text);
setCopied(true);
clearTimeout(timer.current);
timer.current = setTimeout(() => setCopied(false), 1500);
};
<Pressable onPress={copy} style={styles.copyButton}>
<View style={{ width: 18, height: 18 }}>
{copied ? (
<Animated.View key="check" entering={ZoomIn.springify()} exiting={ZoomOut.duration(120)}>
<CheckIcon color="#2BA84A" />
</Animated.View>
) : (
<Animated.View key="copy" entering={ZoomIn.duration(160)} exiting={ZoomOut.duration(120)}>
<CopyIcon />
</Animated.View>
)}
</View>
<Animated.Text key={String(copied)} entering={FadeIn} exiting={FadeOut} style={styles.label}>
{copied ? 'Copied' : 'Copy'}
</Animated.Text>
</Pressable>