import { useEffect, useRef, useState, type ReactNode } from "react"; import { Pressable, StyleSheet, Text, View } from "react-native"; import { IconSwap, TextMorph, type IconSwapVariant } from "torph-reactnative"; import { CheckCircle, ChevronIcon, CopyIcon, HeartIcon, IconMorph, LockIcon, PlusCloseIcon, ProgressCheck, SendIcon, StarIcon, TrashIcon, circlePath, rectPath, type ProgressState, } from "torph-reactnative/icons"; import { C, Chip, Section } from "../../ui"; function Cell({ label, onPress, children }: { label: string; onPress: () => void; children: ReactNode }) { return ( [styles.cell, pressed && { transform: [{ scale: 0.96 }] }]}> {children} {label} ); } /** Videos 11 · 34 · 35 · 42 · 43: the animated icons Family uses — tap each one. */ export function AnimatedIconsDemo() { const [locked, setLocked] = useState(true); const [progress, setProgress] = useState("idle"); const [checked, setChecked] = useState(false); const [expanded, setExpanded] = useState(false); const [open, setOpen] = useState(false); const [star, setStar] = useState(false); const [heart, setHeart] = useState(true); const [trash, setTrash] = useState(false); const [sent, setSent] = useState(0); const [copied, setCopied] = useState(false); const timers = useRef[]>([]); useEffect(() => () => timers.current.forEach(clearTimeout), []); const later = (fn: () => void, ms: number) => timers.current.push(setTimeout(fn, ms)); return (
setLocked((v) => !v)}> { setProgress("loading"); later(() => setProgress("success"), 1500); later(() => setProgress("idle"), 3600); }} > setChecked((v) => !v)}> setExpanded((v) => !v)}> setOpen((v) => !v)}> setStar((v) => !v)}> setHeart((v) => !v)}> { setTrash(true); later(() => setTrash(false), 900); }} > setSent((n) => n + 1)}> { setCopied(true); later(() => setCopied(false), 1400); }} >
); } // Icons as plain path data on a 24 grid — any icon set's paths work the same way. const SHAPES = { menu: ["M4 6h16", "M4 12h16", "M4 18h16"], close: ["M6 6l12 12", "M18 6L6 18"], check: ["M5 12.5l4.5 4.5L19 7"], arrow: ["M5 12h14", "M13 6l6 6-6 6"], plus: ["M12 5v14", "M5 12h14"], play: ["M8 5.5v13l10.5-6.5z"], pause: [rectPath(6.5, 5, 4, 14, 1.2), rectPath(13.5, 5, 4, 14, 1.2)], circle: [circlePath(12, 12, 8)], lock: [rectPath(5, 11, 14, 10, 2.5), "M8 11V7a4 4 0 0 1 8 0v4"], heart: [ "M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7z", ], } as const; type ShapeName = keyof typeof SHAPES; const ORDER = Object.keys(SHAPES) as ShapeName[]; /** Any icon into any icon: path morphing written from scratch, no flubber. */ export function IconMorphDemo() { const [shape, setShape] = useState("menu"); return (
setShape((s) => ORDER[(ORDER.indexOf(s) + 1) % ORDER.length]!)} style={styles.morphStage} > {ORDER.map((name) => ( setShape(name)} /> ))}
); } const EMOJI = ["😀", "😳", "🎉", "👀", "🔥", "👨‍👩‍👧", "🇮🇳", "👍🏽"]; const VARIANTS: IconSwapVariant[] = ["scale", "slide-up", "slide-down", "rotate"]; /** Emoji and glyph swaps — the replace transition, including multi-code-point emoji. */ export function EmojiDemo() { const [i, setI] = useState(0); const [variant, setVariant] = useState("scale"); const [mood, setMood] = useState(0); const moods = ["Still not enough ETH 😳", "Feedback Shared 🎉", "gm ☀️", "gn 🌙"]; return (
setI((n) => (n + 1) % EMOJI.length)} style={styles.emojiStage}> {EMOJI[i]} {VARIANTS.map((v) => ( setVariant(v)} /> ))} setMood((m) => (m + 1) % moods.length)} style={{ marginTop: 18 }}> {moods[mood]!} tap the line
); } const styles = StyleSheet.create({ grid: { flexDirection: "row", flexWrap: "wrap", justifyContent: "space-between", rowGap: 10 }, cell: { width: "31.5%", height: 92, backgroundColor: "#fff", borderRadius: 20, alignItems: "center", justifyContent: "center", gap: 8, }, cellIcon: { height: 32, alignItems: "center", justifyContent: "center" }, cellLabel: { fontSize: 12, fontWeight: "600", color: C.muted, textAlign: "center" }, morphStage: { height: 150, backgroundColor: "#fff", borderRadius: 24, alignItems: "center", justifyContent: "center", }, chips: { flexDirection: "row", flexWrap: "wrap", gap: 8, marginTop: 14 }, emojiStage: { height: 120, backgroundColor: "#fff", borderRadius: 24, alignItems: "center", justifyContent: "center", }, emoji: { fontSize: 56 }, moodText: { fontSize: 18, fontWeight: "600", color: C.ink }, hint: { fontSize: 11, color: C.faint, marginTop: 4 }, });