@farcaster/snap 2.0.3 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
- export declare function SnapCellGrid({ element: { props }, }: {
1
+ export declare function SnapCellGrid({ element: { props, on }, emit, }: {
2
2
  element: {
3
3
  props: Record<string, unknown>;
4
+ on?: Record<string, unknown>;
4
5
  };
6
+ emit: (name: string) => void;
5
7
  }): import("react/jsx-runtime").JSX.Element;
@@ -4,14 +4,16 @@ import { useStateStore } from "@json-render/react";
4
4
  import { cn } from "@neynar/ui/utils";
5
5
  import { POST_GRID_TAP_KEY } from "@farcaster/snap";
6
6
  import { useSnapColors } from "../hooks/use-snap-colors.js";
7
- export function SnapCellGrid({ element: { props }, }) {
7
+ export function SnapCellGrid({ element: { props, on }, emit, }) {
8
8
  const { get, set } = useStateStore();
9
9
  const colors = useSnapColors();
10
10
  const cols = Number(props.cols ?? 2);
11
11
  const rows = Number(props.rows ?? 2);
12
12
  const select = String(props.select ?? "off");
13
- const interactive = select !== "off";
14
13
  const isMultiple = select === "multiple";
14
+ const isSelectable = select !== "off";
15
+ const hasPressAction = Boolean(on?.press);
16
+ const interactive = isSelectable || hasPressAction;
15
17
  const cells = Array.isArray(props.cells) ? props.cells : [];
16
18
  const gap = String(props.gap ?? "sm");
17
19
  const gapMap = { none: 0, sm: 1, md: 2, lg: 4 };
@@ -28,7 +30,7 @@ export function SnapCellGrid({ element: { props }, }) {
28
30
  selectedSet.add(part);
29
31
  }
30
32
  }
31
- const isSelected = (r, c) => selectedSet.has(`${r},${c}`);
33
+ const isSelected = (r, c) => isSelectable && selectedSet.has(`${r},${c}`);
32
34
  const handleTap = (r, c) => {
33
35
  const key = `${r},${c}`;
34
36
  if (isMultiple) {
@@ -42,6 +44,8 @@ export function SnapCellGrid({ element: { props }, }) {
42
44
  else {
43
45
  set(tapPath, key);
44
46
  }
47
+ if (hasPressAction)
48
+ emit("press");
45
49
  };
46
50
  const cellMap = new Map();
47
51
  for (const c of cells) {
@@ -72,7 +76,7 @@ export function SnapCellGrid({ element: { props }, }) {
72
76
  }, children: cell?.content ?? "" }, `${r}-${c}`));
73
77
  }
74
78
  }
75
- const selectionLabel = interactive && selectedSet.size > 0
79
+ const selectionLabel = isSelectable && selectedSet.size > 0
76
80
  ? `inputs.${name}: ${[...selectedSet].join(isMultiple ? " | " : "")}`
77
81
  : null;
78
82
  return (_jsxs("div", { children: [_jsx("div", { style: {
@@ -155,7 +155,12 @@ export function SnapViewCore({ snap, handlers, loading = false, appearance = "da
155
155
  useEffect(() => {
156
156
  setPageKey((k) => k + 1);
157
157
  }, [spec]);
158
- const showConfetti = snap.effects?.includes("confetti");
158
+ const showConfetti = snap.effects?.includes("confetti") ?? false;
159
+ const [confettiKey, setConfettiKey] = useState(0);
160
+ useEffect(() => {
161
+ if (showConfetti)
162
+ setConfettiKey((k) => k + 1);
163
+ }, [showConfetti, snap]);
159
164
  const accentName = snap.theme?.accent ?? "purple";
160
165
  const accentHex = useMemo(() => resolveSnapPaletteHex(accentName, appearance), [accentName, appearance]);
161
166
  const previewSurfaceStyle = useMemo(() => {
@@ -221,7 +226,7 @@ export function SnapViewCore({ snap, handlers, loading = false, appearance = "da
221
226
  break;
222
227
  }
223
228
  }, [handlers]);
224
- return (_jsxs("div", { style: { position: "relative", width: "100%" }, children: [showConfetti && _jsx(ConfettiOverlay, {}), loadingOverlay === undefined ? (_jsx(SnapLoadingOverlay, { appearance: appearance, accentHex: accentHex, active: loading })) : loading ? (_jsx(_Fragment, { children: loadingOverlay })) : null, _jsx("div", { style: previewSurfaceStyle, children: _jsx(SnapPreviewAccentProvider, { pageAccent: snap.theme?.accent, appearance: appearance, children: _jsx(SnapCatalogView, { spec: spec, state: initialState, loading: false, onStateChange: (changes) => {
229
+ return (_jsxs("div", { style: { position: "relative", width: "100%" }, children: [showConfetti && _jsx(ConfettiOverlay, {}, confettiKey), loadingOverlay === undefined ? (_jsx(SnapLoadingOverlay, { appearance: appearance, accentHex: accentHex, active: loading })) : loading ? (_jsx(_Fragment, { children: loadingOverlay })) : null, _jsx("div", { style: previewSurfaceStyle, children: _jsx(SnapPreviewAccentProvider, { pageAccent: snap.theme?.accent, appearance: appearance, children: _jsx(SnapCatalogView, { spec: spec, state: initialState, loading: false, onStateChange: (changes) => {
225
230
  applyStatePaths(stateRef.current, changes);
226
231
  }, onAction: handleAction }, pageKey) }) })] }));
227
232
  }
@@ -49,40 +49,46 @@ export function SnapCardV1({ snap, handlers, loading = false, appearance = "dark
49
49
  position: "relative",
50
50
  width: "100%",
51
51
  maxWidth,
52
- overflow: "hidden",
53
- ...(plain ? {} : {
54
- borderRadius: 16,
55
- border: `1px solid ${borderColor}`,
56
- backgroundColor: surfaceBg,
57
- }),
58
- }, children: [_jsx("div", { style: isClipped
59
- ? {
60
- maxHeight: SNAP_MAX_HEIGHT,
61
- overflow: "hidden",
62
- }
63
- : undefined, children: _jsx("div", { ref: contentRef, style: plain ? undefined : { padding: 16 }, children: _jsx(SnapViewV1, { snap: snap, handlers: handlers, loading: loading, appearance: appearance, loadingOverlay: null }) }) }), loadingOverlay === undefined ? (_jsx(SnapLoadingOverlay, { appearance: appearance, accentHex: accentHex, active: loading })) : loading ? (_jsx(_Fragment, { children: loadingOverlay })) : null, isExpandable ? (_jsx("div", { style: {
64
- display: "flex",
65
- justifyContent: "center",
66
- padding: plain ? "8px 0 0" : "10px 16px 12px",
67
- ...(plain
68
- ? {}
69
- : { borderTop: `1px solid ${borderColor}` }),
70
- }, children: _jsx("button", { type: "button", "aria-expanded": isExpanded, onClick: () => setIsExpanded((value) => !value), style: {
71
- appearance: "none",
72
- border: "none",
73
- borderRadius: 9999,
74
- backgroundColor: toggleBg,
75
- color: toggleText,
76
- padding: "6px 10px",
77
- fontSize: 13,
78
- lineHeight: "18px",
79
- fontWeight: 600,
80
- cursor: "pointer",
81
- }, onMouseEnter: (event) => {
82
- event.currentTarget.style.backgroundColor = toggleBgHover;
83
- }, onMouseLeave: (event) => {
84
- event.currentTarget.style.backgroundColor = toggleBg;
85
- }, children: isExpanded ? "Show less" : "Show more" }) })) : null, actionError && (_jsx("div", { style: {
52
+ }, children: [_jsxs("div", { style: {
53
+ position: "relative",
54
+ overflow: "hidden",
55
+ ...(plain ? {} : {
56
+ borderRadius: 16,
57
+ border: `1px solid ${borderColor}`,
58
+ backgroundColor: surfaceBg,
59
+ }),
60
+ }, children: [_jsx("div", { style: isClipped
61
+ ? {
62
+ maxHeight: SNAP_MAX_HEIGHT,
63
+ overflow: "hidden",
64
+ }
65
+ : undefined, children: _jsx("div", { ref: contentRef, style: plain ? undefined : { padding: 16 }, children: _jsx(SnapViewV1, { snap: snap, handlers: handlers, loading: loading, appearance: appearance, loadingOverlay: null }) }) }), loadingOverlay === undefined ? (_jsx(SnapLoadingOverlay, { appearance: appearance, accentHex: accentHex, active: loading })) : loading ? (_jsx(_Fragment, { children: loadingOverlay })) : null] }), isExpandable ? (_jsx("button", { type: "button", "aria-expanded": isExpanded, onClick: () => setIsExpanded((value) => !value), style: {
66
+ position: "absolute",
67
+ bottom: 0,
68
+ left: "50%",
69
+ transform: "translate(-50%, 50%)",
70
+ appearance: "none",
71
+ border: `1px solid ${borderColor}`,
72
+ borderRadius: 9999,
73
+ backgroundColor: isDark ? "rgba(30,30,30,0.6)" : "rgba(255,255,255,0.6)",
74
+ backdropFilter: "blur(12px) saturate(180%)",
75
+ WebkitBackdropFilter: "blur(12px) saturate(180%)",
76
+ color: toggleText,
77
+ padding: "2px 10px",
78
+ fontSize: 12,
79
+ lineHeight: "16px",
80
+ fontWeight: 600,
81
+ cursor: "pointer",
82
+ zIndex: 11,
83
+ }, onMouseEnter: (event) => {
84
+ event.currentTarget.style.backgroundColor = isDark
85
+ ? "rgba(50,50,50,0.7)"
86
+ : "rgba(245,245,245,0.75)";
87
+ }, onMouseLeave: (event) => {
88
+ event.currentTarget.style.backgroundColor = isDark
89
+ ? "rgba(30,30,30,0.6)"
90
+ : "rgba(255,255,255,0.6)";
91
+ }, children: isExpanded ? "Show less" : "Show more" })) : null, actionError && (_jsx("div", { style: {
86
92
  padding: "8px 12px",
87
93
  fontSize: 13,
88
94
  color: appearance === "dark"
@@ -1,11 +1,12 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useMemo } from "react";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
4
  import { validateSnapResponse } from "../../validator.js";
5
5
  import { SnapViewCore, SnapLoadingOverlay } from "../snap-view-core.js";
6
6
  import { resolveSnapPaletteHex } from "../lib/resolve-palette-hex.js";
7
7
  const SNAP_MAX_HEIGHT = 500;
8
8
  const SNAP_WARNING_HEIGHT = 700;
9
+ const SHOW_MORE_OVERHANG = 14;
9
10
  // ─── Default validation error fallback ────────────────
10
11
  function SnapValidationFallback({ appearance, message, }) {
11
12
  const isDark = appearance === "dark";
@@ -44,45 +45,110 @@ export function SnapViewV2({ snap, handlers, loading = false, appearance = "dark
44
45
  }
45
46
  // ─── SnapCardV2 ──────────────────────────────────────
46
47
  export function SnapCardV2({ snap, handlers, loading = false, appearance = "dark", maxWidth = 480, showOverflowWarning = false, onValidationError, validationErrorFallback, actionError, plain = false, loadingOverlay, }) {
47
- const maxHeight = showOverflowWarning ? SNAP_WARNING_HEIGHT : SNAP_MAX_HEIGHT;
48
48
  const isDark = appearance === "dark";
49
49
  const bg = isDark ? "rgba(0,0,0,0.85)" : "rgba(255,255,255,0.9)";
50
50
  const borderColor = isDark ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)";
51
51
  const surfaceBg = isDark ? "rgba(255,255,255,0.05)" : "rgba(0,0,0,0.02)";
52
+ const toggleBg = isDark ? "rgba(255,255,255,0.06)" : "rgba(0,0,0,0.05)";
53
+ const toggleBgHover = isDark
54
+ ? "rgba(255,255,255,0.1)"
55
+ : "rgba(0,0,0,0.08)";
56
+ const toggleText = isDark ? "rgba(255,255,255,0.82)" : "rgba(0,0,0,0.72)";
52
57
  const accentHex = useMemo(() => resolveSnapPaletteHex(snap.theme?.accent ?? "purple", appearance), [snap.theme?.accent, appearance]);
53
- return (_jsxs(_Fragment, { children: [_jsxs("div", { style: {
58
+ const contentRef = useRef(null);
59
+ const [isExpandable, setIsExpandable] = useState(false);
60
+ const [isExpanded, setIsExpanded] = useState(false);
61
+ useEffect(() => {
62
+ setIsExpanded(false);
63
+ }, [snap]);
64
+ useEffect(() => {
65
+ const node = contentRef.current;
66
+ if (!node)
67
+ return;
68
+ const measure = () => {
69
+ setIsExpandable(node.scrollHeight > SNAP_MAX_HEIGHT + 1);
70
+ };
71
+ measure();
72
+ if (typeof ResizeObserver === "undefined")
73
+ return;
74
+ const observer = new ResizeObserver(() => {
75
+ measure();
76
+ });
77
+ observer.observe(node);
78
+ return () => observer.disconnect();
79
+ }, [snap, plain, showOverflowWarning]);
80
+ useEffect(() => {
81
+ if (!isExpandable) {
82
+ setIsExpanded(false);
83
+ }
84
+ }, [isExpandable]);
85
+ const isClipped = !showOverflowWarning && isExpandable && !isExpanded;
86
+ const containerMaxHeight = showOverflowWarning ? SNAP_WARNING_HEIGHT : undefined;
87
+ return (_jsxs("div", { style: {
88
+ paddingBottom: !showOverflowWarning && isExpandable ? SHOW_MORE_OVERHANG : 0,
89
+ }, children: [_jsxs("div", { style: {
54
90
  position: "relative",
55
91
  width: "100%",
56
92
  maxWidth,
57
- maxHeight,
58
- overflow: "hidden",
59
- ...(plain ? {} : {
60
- borderRadius: 16,
61
- border: `1px solid ${borderColor}`,
62
- backgroundColor: surfaceBg,
63
- }),
64
- }, children: [_jsx("div", { style: plain ? undefined : { padding: 16 }, children: _jsx(SnapViewV2, { snap: snap, handlers: handlers, loading: loading, appearance: appearance, onValidationError: onValidationError, validationErrorFallback: validationErrorFallback, loadingOverlay: null }) }), loadingOverlay === undefined ? (_jsx(SnapLoadingOverlay, { appearance: appearance, accentHex: accentHex, active: loading })) : loading ? (_jsx(_Fragment, { children: loadingOverlay })) : null, showOverflowWarning && (_jsxs("div", { style: {
93
+ }, children: [_jsxs("div", { style: {
94
+ position: "relative",
95
+ maxHeight: containerMaxHeight,
96
+ overflow: "hidden",
97
+ ...(plain ? {} : {
98
+ borderRadius: 16,
99
+ border: `1px solid ${borderColor}`,
100
+ backgroundColor: surfaceBg,
101
+ }),
102
+ }, children: [_jsx("div", { style: isClipped
103
+ ? { maxHeight: SNAP_MAX_HEIGHT, overflow: "hidden" }
104
+ : undefined, children: _jsx("div", { ref: contentRef, style: plain ? undefined : { padding: 16 }, children: _jsx(SnapViewV2, { snap: snap, handlers: handlers, loading: loading, appearance: appearance, onValidationError: onValidationError, validationErrorFallback: validationErrorFallback, loadingOverlay: null }) }) }), loadingOverlay === undefined ? (_jsx(SnapLoadingOverlay, { appearance: appearance, accentHex: accentHex, active: loading })) : loading ? (_jsx(_Fragment, { children: loadingOverlay })) : null, showOverflowWarning && (_jsxs("div", { style: {
105
+ position: "absolute",
106
+ top: SNAP_MAX_HEIGHT,
107
+ left: 0,
108
+ right: 0,
109
+ bottom: 0,
110
+ pointerEvents: "none",
111
+ zIndex: 10,
112
+ }, children: [_jsx("div", { style: { borderTop: "1px dashed rgba(255,100,100,0.6)", position: "relative" }, children: _jsxs("span", { style: {
113
+ position: "absolute",
114
+ top: -10,
115
+ right: 0,
116
+ fontSize: 10,
117
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
118
+ color: "rgba(255,100,100,0.7)",
119
+ background: bg,
120
+ padding: "1px 4px",
121
+ borderRadius: 3,
122
+ }, children: [SNAP_MAX_HEIGHT, "px"] }) }), _jsx("div", { style: {
123
+ height: "100%",
124
+ background: "repeating-linear-gradient(-45deg, transparent, transparent 8px, rgba(255,100,100,0.06) 8px, rgba(255,100,100,0.06) 16px)",
125
+ } })] }))] }), !showOverflowWarning && isExpandable ? (_jsx("button", { type: "button", "aria-expanded": isExpanded, onClick: () => setIsExpanded((value) => !value), style: {
65
126
  position: "absolute",
66
- top: SNAP_MAX_HEIGHT,
67
- left: 0,
68
- right: 0,
69
127
  bottom: 0,
70
- pointerEvents: "none",
71
- zIndex: 10,
72
- }, children: [_jsx("div", { style: { borderTop: "1px dashed rgba(255,100,100,0.6)", position: "relative" }, children: _jsxs("span", { style: {
73
- position: "absolute",
74
- top: -10,
75
- right: 0,
76
- fontSize: 10,
77
- fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
78
- color: "rgba(255,100,100,0.7)",
79
- background: bg,
80
- padding: "1px 4px",
81
- borderRadius: 3,
82
- }, children: [SNAP_MAX_HEIGHT, "px"] }) }), _jsx("div", { style: {
83
- height: "100%",
84
- background: "repeating-linear-gradient(-45deg, transparent, transparent 8px, rgba(255,100,100,0.06) 8px, rgba(255,100,100,0.06) 16px)",
85
- } })] }))] }), actionError && (_jsx("div", { style: {
128
+ left: "50%",
129
+ transform: "translate(-50%, 50%)",
130
+ appearance: "none",
131
+ border: `1px solid ${borderColor}`,
132
+ borderRadius: 9999,
133
+ backgroundColor: isDark ? "rgba(30,30,30,0.6)" : "rgba(255,255,255,0.6)",
134
+ backdropFilter: "blur(12px) saturate(180%)",
135
+ WebkitBackdropFilter: "blur(12px) saturate(180%)",
136
+ color: toggleText,
137
+ padding: "2px 10px",
138
+ fontSize: 12,
139
+ lineHeight: "16px",
140
+ fontWeight: 600,
141
+ cursor: "pointer",
142
+ zIndex: 11,
143
+ }, onMouseEnter: (event) => {
144
+ event.currentTarget.style.backgroundColor = isDark
145
+ ? "rgba(50,50,50,0.7)"
146
+ : "rgba(245,245,245,0.75)";
147
+ }, onMouseLeave: (event) => {
148
+ event.currentTarget.style.backgroundColor = isDark
149
+ ? "rgba(30,30,30,0.6)"
150
+ : "rgba(255,255,255,0.6)";
151
+ }, children: isExpanded ? "Show less" : "Show more" })) : null] }), actionError && (_jsx("div", { style: {
86
152
  maxWidth,
87
153
  padding: "8px 12px",
88
154
  fontSize: 13,
@@ -1,2 +1,2 @@
1
1
  import type { ComponentRenderProps } from "@json-render/react-native";
2
- export declare function SnapCellGrid({ element: { props }, }: ComponentRenderProps<Record<string, unknown>>): import("react").JSX.Element;
2
+ export declare function SnapCellGrid({ element, emit, }: ComponentRenderProps<Record<string, unknown>>): import("react").JSX.Element;
@@ -4,7 +4,9 @@ import { useStateStore } from "@json-render/react-native";
4
4
  import { useSnapPalette } from "../use-snap-palette.js";
5
5
  import { useSnapTheme } from "../theme.js";
6
6
  import { POST_GRID_TAP_KEY } from "@farcaster/snap";
7
- export function SnapCellGrid({ element: { props }, }) {
7
+ export function SnapCellGrid({ element, emit, }) {
8
+ const { props } = element;
9
+ const on = element.on;
8
10
  const { hex, appearance } = useSnapPalette();
9
11
  const { colors } = useSnapTheme();
10
12
  const { get, set } = useStateStore();
@@ -16,8 +18,10 @@ export function SnapCellGrid({ element: { props }, }) {
16
18
  const gapMap = { none: 0, sm: 1, md: 2, lg: 4 };
17
19
  const gapPx = gapMap[gap] ?? 1;
18
20
  const select = String(props.select ?? "off");
19
- const interactive = select !== "off";
20
21
  const isMultiple = select === "multiple";
22
+ const isSelectable = select !== "off";
23
+ const hasPressAction = Boolean(on?.press);
24
+ const interactive = isSelectable || hasPressAction;
21
25
  const name = props.name ? String(props.name) : POST_GRID_TAP_KEY;
22
26
  const tapPath = `/inputs/${name}`;
23
27
  const tapRaw = get(tapPath);
@@ -28,7 +32,7 @@ export function SnapCellGrid({ element: { props }, }) {
28
32
  selectedSet.add(part);
29
33
  }
30
34
  }
31
- const isSelected = (r, c) => selectedSet.has(`${r},${c}`);
35
+ const isSelected = (r, c) => isSelectable && selectedSet.has(`${r},${c}`);
32
36
  const handleTap = (r, c) => {
33
37
  const key = `${r},${c}`;
34
38
  if (isMultiple) {
@@ -42,6 +46,8 @@ export function SnapCellGrid({ element: { props }, }) {
42
46
  else {
43
47
  set(tapPath, key);
44
48
  }
49
+ if (hasPressAction)
50
+ emit("press");
45
51
  };
46
52
  const cellMap = new Map();
47
53
  for (const c of cells) {
@@ -69,7 +75,7 @@ export function SnapCellGrid({ element: { props }, }) {
69
75
  }
70
76
  rowEls.push(_jsx(View, { style: [styles.gridRow, { gap: gapPx }], children: rowCells }, r));
71
77
  }
72
- const selectionLabel = interactive && selectedSet.size > 0
78
+ const selectionLabel = isSelectable && selectedSet.size > 0
73
79
  ? `inputs.${name}: ${[...selectedSet].join(isMultiple ? " | " : "")}`
74
80
  : null;
75
81
  return (_jsxs(View, { style: [styles.wrap, { gap: gapPx, backgroundColor: colors.muted, padding: 4, borderRadius: 8 }], children: [rowEls, selectionLabel ? (_jsx(Text, { style: [styles.selectionText, { color: colors.textSecondary }], children: selectionLabel })) : null] }));
@@ -20,63 +20,60 @@ export function ConfettiOverlay() {
20
20
  color: CONFETTI_COLORS[Math.floor(Math.random() * CONFETTI_COLORS.length)],
21
21
  size: 6 + Math.random() * 8,
22
22
  startRotation: Math.random() * 360,
23
- driftX: (Math.random() > 0.5 ? 1 : -1) * Math.random() * 40,
23
+ // Per-piece swirl: amplitude, frequency (full oscillations), phase.
24
+ swirlAmp: 20 + Math.random() * 40,
25
+ swirlFreq: 1 + Math.random() * 1.5,
26
+ swirlPhase: Math.random() * Math.PI * 2,
24
27
  })),
25
28
  // width captured once on mount; intentional stable dep
26
29
  // eslint-disable-next-line react-hooks/exhaustive-deps
27
30
  []);
28
31
  const anims = useRef(pieces.map(() => ({
29
- translateY: new Animated.Value(-20),
30
- opacity: new Animated.Value(1),
31
- rotate: new Animated.Value(0),
32
- translateX: new Animated.Value(0),
32
+ progress: new Animated.Value(0),
33
33
  }))).current;
34
34
  useEffect(() => {
35
35
  const animations = pieces.map((piece, i) => {
36
36
  const anim = anims[i];
37
- anim.translateY.setValue(-20);
38
- anim.opacity.setValue(1);
39
- anim.rotate.setValue(0);
40
- anim.translateX.setValue(0);
37
+ anim.progress.setValue(0);
41
38
  return Animated.sequence([
42
39
  Animated.delay(piece.delay),
43
- Animated.parallel([
44
- Animated.timing(anim.translateY, {
45
- toValue: height + 20,
46
- duration: piece.duration,
47
- useNativeDriver: true,
48
- }),
49
- Animated.timing(anim.opacity, {
50
- toValue: 0,
51
- duration: piece.duration,
52
- useNativeDriver: true,
53
- }),
54
- Animated.timing(anim.rotate, {
55
- toValue: 720,
56
- duration: piece.duration,
57
- useNativeDriver: true,
58
- }),
59
- Animated.timing(anim.translateX, {
60
- toValue: piece.driftX,
61
- duration: piece.duration,
62
- useNativeDriver: true,
63
- }),
64
- ]),
40
+ Animated.timing(anim.progress, {
41
+ toValue: 1,
42
+ duration: piece.duration,
43
+ useNativeDriver: true,
44
+ }),
65
45
  ]);
66
46
  });
67
47
  const composite = Animated.parallel(animations);
68
48
  composite.start();
69
49
  return () => composite.stop();
70
50
  }, [pieces, anims, height]);
51
+ // Sample the sine curve at fixed progress points to build an interpolation
52
+ // that drives horizontal swirl on the native driver.
53
+ const SAMPLE_COUNT = 21;
54
+ const samplePoints = Array.from({ length: SAMPLE_COUNT }, (_, k) => k / (SAMPLE_COUNT - 1));
71
55
  return (_jsx(View, { style: [StyleSheet.absoluteFill, styles.container], pointerEvents: "none", children: pieces.map((piece, i) => {
72
56
  const anim = anims[i];
73
- const rotate = anim.rotate.interpolate({
74
- inputRange: [0, 720],
57
+ const translateY = anim.progress.interpolate({
58
+ inputRange: [0, 1],
59
+ outputRange: [-20, height + 20],
60
+ });
61
+ const rotate = anim.progress.interpolate({
62
+ inputRange: [0, 1],
75
63
  outputRange: [
76
64
  `${piece.startRotation}deg`,
77
65
  `${piece.startRotation + 720}deg`,
78
66
  ],
79
67
  });
68
+ const opacity = anim.progress.interpolate({
69
+ inputRange: [0, 0.5, 1],
70
+ outputRange: [1, 1, 0],
71
+ });
72
+ const translateX = anim.progress.interpolate({
73
+ inputRange: samplePoints,
74
+ outputRange: samplePoints.map((t) => Math.sin(t * piece.swirlFreq * Math.PI * 2 + piece.swirlPhase) *
75
+ piece.swirlAmp),
76
+ });
80
77
  return (_jsx(Animated.View, { style: [
81
78
  styles.piece,
82
79
  {
@@ -84,10 +81,10 @@ export function ConfettiOverlay() {
84
81
  width: piece.size,
85
82
  height: piece.size * 0.6,
86
83
  backgroundColor: piece.color,
87
- opacity: anim.opacity,
84
+ opacity,
88
85
  transform: [
89
- { translateY: anim.translateY },
90
- { translateX: anim.translateX },
86
+ { translateY },
87
+ { translateX },
91
88
  { rotate },
92
89
  ],
93
90
  },
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { snapJsonRenderCatalog } from "@farcaster/snap/ui";
3
3
  import { SnapCatalogView } from "./catalog-renderer.js";
4
+ import { ConfettiOverlay } from "./confetti-overlay.js";
4
5
  import { useSnapTheme } from "./theme.js";
5
6
  import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
6
7
  import { ActivityIndicator, StyleSheet, View } from "react-native";
@@ -79,6 +80,12 @@ export function SnapViewCoreInner({ snap, handlers, loading = false, loadingOver
79
80
  useEffect(() => {
80
81
  setPageKey((k) => k + 1);
81
82
  }, [spec]);
83
+ const showConfetti = snap.effects?.includes("confetti") ?? false;
84
+ const [confettiKey, setConfettiKey] = useState(0);
85
+ useEffect(() => {
86
+ if (showConfetti)
87
+ setConfettiKey((k) => k + 1);
88
+ }, [showConfetti, snap]);
82
89
  const handlersRef = useRef(handlers);
83
90
  handlersRef.current = handlers;
84
91
  const handleAction = useCallback((name, params) => {
@@ -140,7 +147,7 @@ export function SnapViewCoreInner({ snap, handlers, loading = false, loadingOver
140
147
  : loadingOverlay
141
148
  : null, _jsx(SnapCatalogView, { spec: spec, state: initialState, loading: false, onStateChange: (changes) => {
142
149
  applyStatePaths(stateRef.current, changes);
143
- }, onAction: handleAction }, pageKey)] }));
150
+ }, onAction: handleAction }, pageKey), showConfetti && _jsx(ConfettiOverlay, {}, confettiKey)] }));
144
151
  }
145
152
  export function SnapLoadingOverlay({ appearance, accentHex, }) {
146
153
  return (_jsx(View, { style: [
@@ -23,39 +23,36 @@ function SnapCardV1Inner({ snap, handlers, loading = false, borderRadius, action
23
23
  }, [snap]);
24
24
  const isExpandable = contentHeight > SNAP_MAX_HEIGHT + 1;
25
25
  const isClipped = isExpandable && !isExpanded;
26
- return (_jsxs(_Fragment, { children: [_jsx(View, { style: cardStyles.frameRing, children: _jsxs(View, { style: [
27
- plain ? undefined : cardStyles.card,
28
- plain ? undefined : {
29
- borderRadius,
30
- borderColor: colors.border,
31
- backgroundColor: colors.surface,
32
- },
33
- ], children: [_jsx(View, { style: isClipped ? { maxHeight: SNAP_MAX_HEIGHT, overflow: "hidden" } : undefined, children: _jsx(View, { collapsable: false, onLayout: (event) => {
34
- const nextHeight = Math.round(event.nativeEvent.layout.height);
35
- setContentHeight((currentHeight) => isClipped
36
- ? Math.max(currentHeight, nextHeight)
37
- : currentHeight === nextHeight
38
- ? currentHeight
39
- : nextHeight);
40
- }, style: plain ? undefined : cardStyles.body, children: _jsx(SnapViewV1Inner, { snap: snap, handlers: handlers, loading: loading, loadingOverlay: null }) }) }), loading
41
- ? loadingOverlay === undefined
42
- ? _jsx(SnapLoadingOverlay, { appearance: mode, accentHex: accentHex })
43
- : loadingOverlay
44
- : null, isExpandable ? (_jsx(View, { style: [
45
- cardStyles.expandRow,
46
- plain
47
- ? cardStyles.expandRowPlain
48
- : { borderTopColor: colors.border },
49
- ], children: _jsx(Pressable, { style: ({ pressed }) => [
50
- cardStyles.expandButton,
51
- {
52
- backgroundColor: pressed
53
- ? colors.mutedHover
54
- : colors.muted,
55
- },
56
- ], onPress: () => {
57
- setIsExpanded((value) => !value);
58
- }, children: _jsx(Text, { style: [cardStyles.expandButtonText, { color: colors.text }], children: isExpanded ? "Show less" : "Show more" }) }) })) : null] }) }), actionError && (_jsx(Text, { style: [
26
+ const isDark = mode === "dark";
27
+ const pillBg = isDark ? "rgba(40,40,40,0.92)" : "rgba(255,255,255,0.92)";
28
+ const pillBgPressed = isDark ? "rgba(60,60,60,0.95)" : "rgba(240,240,240,0.95)";
29
+ return (_jsxs(_Fragment, { children: [_jsxs(View, { style: cardStyles.frameRing, children: [_jsxs(View, { style: [
30
+ plain ? undefined : cardStyles.card,
31
+ plain ? undefined : {
32
+ borderRadius,
33
+ borderColor: colors.border,
34
+ backgroundColor: colors.surface,
35
+ },
36
+ ], children: [_jsx(View, { style: isClipped ? { maxHeight: SNAP_MAX_HEIGHT, overflow: "hidden" } : undefined, children: _jsx(View, { collapsable: false, onLayout: (event) => {
37
+ const nextHeight = Math.round(event.nativeEvent.layout.height);
38
+ setContentHeight((currentHeight) => isClipped
39
+ ? Math.max(currentHeight, nextHeight)
40
+ : currentHeight === nextHeight
41
+ ? currentHeight
42
+ : nextHeight);
43
+ }, style: plain ? undefined : cardStyles.body, children: _jsx(SnapViewV1Inner, { snap: snap, handlers: handlers, loading: loading, loadingOverlay: null }) }) }), loading
44
+ ? loadingOverlay === undefined
45
+ ? _jsx(SnapLoadingOverlay, { appearance: mode, accentHex: accentHex })
46
+ : loadingOverlay
47
+ : null] }), isExpandable ? (_jsx(View, { pointerEvents: "box-none", style: cardStyles.expandFloat, children: _jsx(Pressable, { style: ({ pressed }) => [
48
+ cardStyles.expandButton,
49
+ {
50
+ backgroundColor: pressed ? pillBgPressed : pillBg,
51
+ borderColor: colors.border,
52
+ },
53
+ ], onPress: () => {
54
+ setIsExpanded((value) => !value);
55
+ }, children: _jsx(Text, { style: [cardStyles.expandButtonText, { color: colors.text }], children: isExpanded ? "Show less" : "Show more" }) }) })) : null] }), actionError && (_jsx(Text, { style: [
59
56
  cardStyles.actionError,
60
57
  {
61
58
  color: appearance === "dark"
@@ -71,30 +68,27 @@ const cardStyles = StyleSheet.create({
71
68
  frameRing: { alignSelf: "stretch" },
72
69
  card: { overflow: "hidden", borderWidth: 1, minHeight: 120 },
73
70
  body: { paddingHorizontal: 16, paddingVertical: 16 },
74
- expandRow: {
71
+ expandFloat: {
72
+ position: "absolute",
73
+ left: 0,
74
+ right: 0,
75
+ bottom: -14,
76
+ height: 28,
75
77
  alignItems: "center",
76
- paddingHorizontal: 16,
77
- paddingTop: 10,
78
- paddingBottom: 12,
79
- borderTopWidth: StyleSheet.hairlineWidth,
80
- },
81
- expandRowPlain: {
82
- paddingHorizontal: 0,
83
- paddingTop: 8,
84
- paddingBottom: 0,
85
- borderTopWidth: 0,
78
+ justifyContent: "center",
86
79
  },
87
80
  expandButton: {
88
81
  minWidth: 92,
89
82
  alignItems: "center",
90
83
  justifyContent: "center",
91
84
  borderRadius: 9999,
85
+ borderWidth: 1,
92
86
  paddingHorizontal: 10,
93
- paddingVertical: 6,
87
+ paddingVertical: 4,
94
88
  },
95
89
  expandButtonText: {
96
- fontSize: 13,
97
- lineHeight: 18,
90
+ fontSize: 12,
91
+ lineHeight: 16,
98
92
  fontWeight: "600",
99
93
  },
100
94
  actionError: { paddingHorizontal: 12, paddingVertical: 8, fontSize: 13 },