import React, {useCallback, useEffect, useState} from 'react' import {GestureResponderEvent, View} from 'react-native' import Animated, {FadeOutUp, ZoomIn} from 'react-native-reanimated' import * as Clipboard from 'expo-clipboard' import {Trans} from '@lingui/macro' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonProps} from '#/components/Button' import {Text} from '#/components/Typography' export function CopyButton({ style, value, onPress: onPressProp, ...props }: ButtonProps & {value: string}) { const [hasBeenCopied, setHasBeenCopied] = useState(false) const t = useTheme() useEffect(() => { if (hasBeenCopied) { const timeout = setTimeout(() => setHasBeenCopied(false), 100) return () => clearTimeout(timeout) } }, [hasBeenCopied]) const onPress = useCallback( (evt: GestureResponderEvent) => { Clipboard.setStringAsync(value) setHasBeenCopied(true) onPressProp?.(evt) }, [value, onPressProp], ) return ( {hasBeenCopied && ( Copied! )}