import { ReactNode, useEffect, useState } from "react"; import { cn } from "../../../../../lib/utils"; import { Icon } from "../../../../Icon"; import { CheckCircle, LayersFront } from "../../../../../icons/app"; import { Pressable, View } from "react-native"; import * as Clipboard from "expo-clipboard"; import { CopyActionType } from ".."; const COPIED_SHOWN_MS = 750; export type CopyActionProps = { children: ReactNode; } & CopyActionType; export const CopyAction = ({ text, children }: CopyActionProps) => { const [copied, setCopied] = useState(false); useEffect(() => { if (copied) { const timer = setTimeout(() => setCopied(false), COPIED_SHOWN_MS); return () => clearTimeout(timer); } }, [copied]); const copyHandler = async () => { try { if (text) { await Clipboard.setStringAsync(text); setCopied(true); } } catch (error) { void error; } }; return ( {children} {!copied && ( )} {copied && ( )} ); };