@farcaster/snap 2.6.2 → 2.6.4

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,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Image } from "expo-image";
3
+ import { useCallback, useState } from "react";
3
4
  import { StyleSheet, Text, View } from "react-native";
4
5
  import { useSnapStackDirection } from "../stack-direction-context.js";
5
6
  function aspectToRatio(aspect) {
@@ -17,10 +18,16 @@ export function SnapImage({ element: { props }, }) {
17
18
  const ratio = aspectToRatio(String(props.aspect ?? "1:1"));
18
19
  const stackDir = useSnapStackDirection();
19
20
  const inHorizontalStack = stackDir === "horizontal";
20
- return (_jsxs(View, { style: [
21
+ const [frameWidth, setFrameWidth] = useState(0);
22
+ const measuredHeight = frameWidth > 0 ? frameWidth / ratio : undefined;
23
+ const handleLayout = useCallback((event) => {
24
+ const nextWidth = Math.round(event.nativeEvent.layout.width);
25
+ setFrameWidth((currentWidth) => currentWidth !== nextWidth ? nextWidth : currentWidth);
26
+ }, []);
27
+ return (_jsxs(View, { onLayout: handleLayout, style: [
21
28
  styles.frame,
22
29
  inHorizontalStack ? styles.frameInHorizontalRow : styles.frameFullWidth,
23
- { aspectRatio: ratio },
30
+ measuredHeight ? { height: measuredHeight } : { aspectRatio: ratio },
24
31
  ], children: [_jsx(Image, { source: { uri: url }, style: StyleSheet.absoluteFill, contentFit: "cover", accessibilityLabel: alt || undefined }), hasOverlay ? (_jsx(View, { style: styles.overlay, pointerEvents: "none", children: _jsxs(View, { style: styles.overlayContent, children: [title ? (_jsx(Text, { numberOfLines: 1, style: styles.title, children: title })) : null, subtitle ? (_jsx(Text, { numberOfLines: 1, style: styles.subtitle, children: subtitle })) : null] }) })) : null] }));
25
32
  }
26
33
  const styles = StyleSheet.create({
@@ -82,7 +82,7 @@ export function SnapCardV1({ snap, handlers, loading = false, appearance = "dark
82
82
  const cardStyles = StyleSheet.create({
83
83
  frameRing: { alignSelf: "stretch" },
84
84
  card: { overflow: "hidden", borderWidth: 1, minHeight: 120 },
85
- body: { paddingHorizontal: 16, paddingVertical: 16 },
85
+ body: { paddingHorizontal: 8, paddingVertical: 8 },
86
86
  expandFloat: {
87
87
  position: "absolute",
88
88
  left: 0,
@@ -123,7 +123,7 @@ function SnapCardV2Inner({ snap, handlers, loading, borderRadius, showOverflowWa
123
123
  : current === nextHeight
124
124
  ? current
125
125
  : nextHeight);
126
- }, style: { paddingHorizontal: 16, paddingVertical: 16 }, children: content }), expansion.showOverflowWarning && contentHeight > SNAP_MAX_HEIGHT && (_jsxs(View, { style: { position: "absolute", top: SNAP_MAX_HEIGHT, left: 0, right: 0, height: overflowAmount, zIndex: 10, pointerEvents: "none" }, children: [_jsx(View, { style: { height: 1, borderTopWidth: 1, borderStyle: "dashed", borderColor: "rgba(255,100,100,0.6)" } }), _jsx(View, { style: { position: "absolute", top: -10, right: 4, backgroundColor: "rgba(0,0,0,0.7)", paddingHorizontal: 4, paddingVertical: 1, borderRadius: 3 }, children: _jsxs(Text, { style: { fontSize: 10, color: "rgba(255,100,100,0.7)", fontFamily: Platform.select({ ios: "Menlo", default: "monospace" }) }, children: [SNAP_MAX_HEIGHT, "px"] }) }), _jsx(View, { style: { flex: 1, backgroundColor: "rgba(255,50,50,0.15)" } })] })), loading
126
+ }, style: cardStyles.body, children: content }), expansion.showOverflowWarning && contentHeight > SNAP_MAX_HEIGHT && (_jsxs(View, { style: { position: "absolute", top: SNAP_MAX_HEIGHT, left: 0, right: 0, height: overflowAmount, zIndex: 10, pointerEvents: "none" }, children: [_jsx(View, { style: { height: 1, borderTopWidth: 1, borderStyle: "dashed", borderColor: "rgba(255,100,100,0.6)" } }), _jsx(View, { style: { position: "absolute", top: -10, right: 4, backgroundColor: "rgba(0,0,0,0.7)", paddingHorizontal: 4, paddingVertical: 1, borderRadius: 3 }, children: _jsxs(Text, { style: { fontSize: 10, color: "rgba(255,100,100,0.7)", fontFamily: Platform.select({ ios: "Menlo", default: "monospace" }) }, children: [SNAP_MAX_HEIGHT, "px"] }) }), _jsx(View, { style: { flex: 1, backgroundColor: "rgba(255,50,50,0.15)" } })] })), loading
127
127
  ? loadingOverlay === undefined
128
128
  ? _jsx(SnapLoadingOverlay, { appearance: mode, accentHex: accentHex })
129
129
  : loadingOverlay
@@ -157,7 +157,7 @@ export function SnapCardV2({ snap, handlers, loading = false, appearance = "dark
157
157
  const cardStyles = StyleSheet.create({
158
158
  frameRing: { alignSelf: "stretch" },
159
159
  card: { borderWidth: 1, minHeight: 120, overflow: "hidden" },
160
- body: { paddingHorizontal: 16, paddingVertical: 16 },
160
+ body: { paddingHorizontal: 8, paddingVertical: 8 },
161
161
  actionError: { paddingHorizontal: 12, paddingVertical: 8, fontSize: 13 },
162
162
  expandFloat: {
163
163
  position: "absolute",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farcaster/snap",
3
- "version": "2.6.2",
3
+ "version": "2.6.4",
4
4
  "description": "Farcaster Snaps 🫰",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,7 @@
1
1
  import type { ComponentRenderProps } from "@json-render/react-native";
2
2
  import { Image } from "expo-image";
3
+ import { useCallback, useState } from "react";
4
+ import type { ViewProps } from "react-native";
3
5
  import { StyleSheet, Text, View } from "react-native";
4
6
  import { useSnapStackDirection } from "../stack-direction-context";
5
7
 
@@ -20,13 +22,22 @@ export function SnapImage({
20
22
  const ratio = aspectToRatio(String(props.aspect ?? "1:1"));
21
23
  const stackDir = useSnapStackDirection();
22
24
  const inHorizontalStack = stackDir === "horizontal";
25
+ const [frameWidth, setFrameWidth] = useState(0);
26
+ const measuredHeight = frameWidth > 0 ? frameWidth / ratio : undefined;
27
+ const handleLayout = useCallback<NonNullable<ViewProps["onLayout"]>>((event) => {
28
+ const nextWidth = Math.round(event.nativeEvent.layout.width);
29
+ setFrameWidth((currentWidth) =>
30
+ currentWidth !== nextWidth ? nextWidth : currentWidth,
31
+ );
32
+ }, []);
23
33
 
24
34
  return (
25
35
  <View
36
+ onLayout={handleLayout}
26
37
  style={[
27
38
  styles.frame,
28
39
  inHorizontalStack ? styles.frameInHorizontalRow : styles.frameFullWidth,
29
- { aspectRatio: ratio },
40
+ measuredHeight ? { height: measuredHeight } : { aspectRatio: ratio },
30
41
  ]}
31
42
  >
32
43
  <Image
@@ -263,7 +263,7 @@ export function SnapCardV1({
263
263
  const cardStyles = StyleSheet.create({
264
264
  frameRing: { alignSelf: "stretch" },
265
265
  card: { overflow: "hidden", borderWidth: 1, minHeight: 120 },
266
- body: { paddingHorizontal: 16, paddingVertical: 16 },
266
+ body: { paddingHorizontal: 8, paddingVertical: 8 },
267
267
  expandFloat: {
268
268
  position: "absolute",
269
269
  left: 0,
@@ -289,7 +289,7 @@ function SnapCardV2Inner({
289
289
  : nextHeight,
290
290
  );
291
291
  }}
292
- style={{ paddingHorizontal: 16, paddingVertical: 16 }}
292
+ style={cardStyles.body}
293
293
  >
294
294
  {content}
295
295
  </View>
@@ -421,7 +421,7 @@ export function SnapCardV2({
421
421
  const cardStyles = StyleSheet.create({
422
422
  frameRing: { alignSelf: "stretch" },
423
423
  card: { borderWidth: 1, minHeight: 120, overflow: "hidden" },
424
- body: { paddingHorizontal: 16, paddingVertical: 16 },
424
+ body: { paddingHorizontal: 8, paddingVertical: 8 },
425
425
  actionError: { paddingHorizontal: 12, paddingVertical: 8, fontSize: 13 },
426
426
  expandFloat: {
427
427
  position: "absolute",