glacia-native 0.6.2 → 0.6.3

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.
@@ -0,0 +1,19 @@
1
+ {
2
+ "android": {
3
+ "gradlePath": "src/engine/android/build.gradle",
4
+ "modules": [
5
+ "expo.modules.liquidglass.ExpoLiquidGlassModule"
6
+ ],
7
+ "path": "src/engine/android"
8
+ },
9
+ "apple": {
10
+ "modules": [
11
+ "ExpoLiquidGlassModule"
12
+ ],
13
+ "podspecPath": "src/engine/ios/ExpoLiquidGlass.podspec"
14
+ },
15
+ "platforms": [
16
+ "apple",
17
+ "android"
18
+ ]
19
+ }
@@ -10,6 +10,20 @@ const tokens_1 = require("./internal/tokens");
10
10
  const primitives_1 = require("./internal/primitives");
11
11
  const motion_1 = require("./internal/motion");
12
12
  const SIZES = { sm: 32, md: 38, lg: 44 };
13
+ /**
14
+ * The glyph size a render-function icon is handed, per button size — the
15
+ * engine's own small / regular / large icon sizes (18 / 22 / 24), so the
16
+ * fallback hands a function the same size the engine does.
17
+ */
18
+ const ICON_SIZES = { sm: 18, md: 22, lg: 24 };
19
+ /**
20
+ * The same names in the engine's vocabulary (`small` / `regular` / `large`).
21
+ * The engine reads BUTTON_SIZES[size] with no fallback, so passing the
22
+ * library's `sm` / `md` / `lg` straight through resolves to undefined and
23
+ * throws the moment the engine mounts. The fallback never saw this because
24
+ * the engine never mounted — 0.6.3 mounts it, so the map is load-bearing.
25
+ */
26
+ const ENGINE_SIZE_NAMES = { sm: "small", md: "regular", lg: "large" };
13
27
  /**
14
28
  * An icon button on Glacia's glass — ported from the engine's
15
29
  * `LiquidGlassIconButton`, which extends the engine button's design with a
@@ -24,10 +38,19 @@ exports.IconButton = (0, react_1.forwardRef)(function IconButton({ icon, onPress
24
38
  const dimension = SIZES[size];
25
39
  if (EngineIconButton && capabilities.supported) {
26
40
  const EngineIconButtonComponent = EngineIconButton;
27
- return ((0, jsx_runtime_1.jsx)(EngineIconButtonComponent, { ref: ref, onPress: disabled ? undefined : onPress, disabled: disabled, icon: icon, tint: tint, accessibilityLabel: accessibilityLabel, accessibilityState: { disabled, ...accessibilityState }, style: style, size: size, children: children }));
41
+ return ((0, jsx_runtime_1.jsx)(EngineIconButtonComponent, { ref: ref, onPress: disabled ? undefined : onPress, disabled: disabled, icon: icon, tint: tint, accessibilityLabel: accessibilityLabel, accessibilityState: { disabled, ...accessibilityState }, style: style, size: ENGINE_SIZE_NAMES[size], children: children }));
28
42
  }
29
43
  // Fallback floor: solid circle, full geometry, on the fallback material.
44
+ // The icon renders centred in the circle. A render function is handed the
45
+ // same { color, size } the engine hands it — white on a tint, the scheme's
46
+ // foreground otherwise, at the button's glyph size. A plain element renders
47
+ // as given. (The circle used to be self-closing, so the icon never painted:
48
+ // the solid blue circles with no glyphs.)
30
49
  const radius = dimension / 2;
50
+ const iconColor = tint != null ? themeColors.onTint : themeColors.foreground;
51
+ const iconNode = typeof icon === "function"
52
+ ? icon({ color: iconColor, size: ICON_SIZES[size] })
53
+ : icon;
31
54
  return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "control", isDark: isDark, tintColor: tint, style: style, testID: testID, children: (0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, disabled: disabled, onPress: disabled ? undefined : onPress, style: style, children: (0, jsx_runtime_1.jsx)(View, { style: {
32
55
  width: dimension,
33
56
  height: dimension,
@@ -36,5 +59,5 @@ exports.IconButton = (0, react_1.forwardRef)(function IconButton({ icon, onPress
36
59
  opacity: disabled ? 0.38 : 1,
37
60
  alignItems: "center",
38
61
  justifyContent: "center",
39
- } }) }) }));
62
+ }, children: iconNode }) }) }));
40
63
  });
@@ -47,6 +47,49 @@ function glassCapabilities() {
47
47
  }
48
48
  /** Whether this build renders Apple's glass. */
49
49
  exports.isGlassSupported = (0, glass_routing_1.defaultRouter)().supported;
50
+ /** Merges a style prop into one object; a function style is not resolvable here. */
51
+ function flattenStyle(style) {
52
+ if (!style)
53
+ return {};
54
+ if (Array.isArray(style)) {
55
+ return style.reduce((acc, entry) => ({ ...acc, ...flattenStyle(entry) }), {});
56
+ }
57
+ if (typeof style === "function")
58
+ return {};
59
+ return style;
60
+ }
61
+ /**
62
+ * The corner radius the engine's shader should refract with, read from the
63
+ * style the container already paints with — the one shape source for the
64
+ * engine branch. The native view defaults `cornerRadius` to 0 (a rectangle),
65
+ * so without this a pill container would refract as a rectangle while its
66
+ * outline is a pill. A raw pill radius (9999) is safe to pass: the native
67
+ * side clamps it to half the shorter side, the same clamp the container
68
+ * uses. Per-corner radii pass through as an object; an explicit `cornerRadius`
69
+ * prop from the caller is read by the caller of this helper, not here.
70
+ */
71
+ function resolveCornerRadius(style) {
72
+ const flat = flattenStyle(style);
73
+ const tl = flat.borderTopLeftRadius;
74
+ const tr = flat.borderTopRightRadius;
75
+ const br = flat.borderBottomRightRadius;
76
+ const bl = flat.borderBottomLeftRadius;
77
+ const base = typeof flat.borderRadius === "number" ? flat.borderRadius : 0;
78
+ if (typeof tl === "number" ||
79
+ typeof tr === "number" ||
80
+ typeof br === "number" ||
81
+ typeof bl === "number") {
82
+ return {
83
+ topLeft: typeof tl === "number" ? tl : base,
84
+ topRight: typeof tr === "number" ? tr : base,
85
+ bottomRight: typeof br === "number" ? br : base,
86
+ bottomLeft: typeof bl === "number" ? bl : base,
87
+ };
88
+ }
89
+ if (typeof flat.borderRadius === "number")
90
+ return flat.borderRadius;
91
+ return undefined;
92
+ }
50
93
  /**
51
94
  * Platform Glass View — the single place a glass surface is chosen:
52
95
  * - iOS 26+: Real `UIGlassEffect` via the vendored engine's native view
@@ -73,10 +116,15 @@ exports.GlassView = (0, react_1.forwardRef)(function GlassView({ effect = "regul
73
116
  const LiquidGlassView = decision.LiquidGlassView;
74
117
  const variant = effect === "clear" ? "clear" : "regular";
75
118
  const glow = pressed === undefined ? props.glow : { progress: pressed ? 1 : 0, lens: true };
119
+ // The engine's shader, content clip and border all refract with the
120
+ // `cornerRadius` prop (default 0 = rectangle). Pass the radius the style
121
+ // already paints, so the glass and the container share one shape. An
122
+ // explicit `cornerRadius` prop from the caller wins.
123
+ const cornerRadius = props.cornerRadius ?? resolveCornerRadius(style);
76
124
  // The engine owns the material; Glacia's own surface parameters stop at
77
125
  // the branch. Everything else (accessibility contract, provider pairing,
78
126
  // the adaptive sensor, an externally driven press) rides through.
79
- return ((0, jsx_runtime_1.jsx)(LiquidGlassView, { ...props, ref: ref, variant: variant, tint: tintColor, interactive: interactive, glow: glow, style: style, testID: testID, children: children }));
127
+ return ((0, jsx_runtime_1.jsx)(LiquidGlassView, { ...props, ref: ref, variant: variant, tint: tintColor, interactive: interactive, glow: glow, cornerRadius: cornerRadius, style: style, testID: testID, children: children }));
80
128
  }
81
129
  // Unsupported, or a deliberate "no surface": the fallback floor renders —
82
130
  // with the same shape, states and materials as the glass would have.
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.effectiveGlassRadius = effectiveGlassRadius;
3
4
  exports.GlassRim = GlassRim;
4
5
  const jsx_runtime_1 = require("react/jsx-runtime");
5
6
  // The painted rim: light caught on the curved edge of a glass surface.
@@ -17,19 +18,49 @@ const react_1 = require("react");
17
18
  const primitives_1 = require("./primitives");
18
19
  const tokens_1 = require("./tokens");
19
20
  const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 };
21
+ /**
22
+ * The corner radius a surface actually shows, from the radius it was given
23
+ * and the box it was laid out in. React Native clamps `borderRadius` to half
24
+ * the shorter side; this is the same clamp, so the rim and the container
25
+ * agree on one shape. A pill radius (9999) on a 350x34 field is 17, not 9999.
26
+ */
27
+ function effectiveGlassRadius(radius, width, height) {
28
+ return Math.min(radius, width / 2, height / 2);
29
+ }
20
30
  /**
21
31
  * The rim light and top highlight of one surface.
22
32
  *
23
33
  * Both are stacked stops of a vertical gradient in the same colour: the eye
24
34
  * reads the brightest edge as a lit curve and the falloff as the curve turning
25
35
  * away from the light.
36
+ *
37
+ * One shape, one radius. The container's corner is a true pill/semicircle:
38
+ * React Native clamps `borderRadius` to half the shorter side. SVG does NOT
39
+ * clamp that way — it clamps `rx` to half the WIDTH and `ry` to half the
40
+ * HEIGHT independently — so a raw pill radius (9999) drew a wide flat ellipse
41
+ * (rx ~ half the width) inside a pill container. That is the oval the owner
42
+ * saw inside the search field. The rim measures the surface it paints and
43
+ * uses the same effective radius the container shows — `min(radius, half the
44
+ * shorter side)` — so the rim and the container share one shape. Measuring
45
+ * here fixes every caller (the fallback glass, the tab-bar lens, the
46
+ * segmented-control lens) because the rim is the only layer that drew its
47
+ * shape in SVG. Before layout the raw radius is used (one frame); off-device
48
+ * (tests, web preview) there is no layout, so the raw radius is used exactly
49
+ * as before.
26
50
  */
27
51
  function GlassRim({ radius, rim, highlight }) {
28
- const { Svg, Defs, Rect, LinearGradient, Stop } = (0, primitives_1.primitives)();
52
+ const { Svg, Defs, Rect, LinearGradient, Stop, View, isNative } = (0, primitives_1.primitives)();
29
53
  const key = (0, react_1.useId)().replace(/[^a-zA-Z0-9_-]/g, "");
30
54
  const rimId = `rim-${key}`;
31
55
  const highlightId = `top-${key}`;
32
- // SVG clamps rx/ry to half the side, so a pill radius simply becomes a pill.
33
- const rx = Math.max(0, radius - 0.5);
34
- return ((0, jsx_runtime_1.jsxs)(Svg, { width: "100%", height: "100%", style: fill, pointerEvents: "none", children: [(0, jsx_runtime_1.jsxs)(Defs, { children: [(0, jsx_runtime_1.jsxs)(LinearGradient, { id: rimId, x1: "0", y1: "0", x2: "0", y2: "1", children: [(0, jsx_runtime_1.jsx)(Stop, { offset: "0", stopColor: tokens_1.material.rimColor, stopOpacity: rim }), (0, jsx_runtime_1.jsx)(Stop, { offset: "0.55", stopColor: tokens_1.material.rimColor, stopOpacity: rim * 0.35 }), (0, jsx_runtime_1.jsx)(Stop, { offset: "1", stopColor: tokens_1.material.rimColor, stopOpacity: rim * 0.08 })] }), (0, jsx_runtime_1.jsxs)(LinearGradient, { id: highlightId, x1: "0", y1: "0", x2: "0", y2: "1", children: [(0, jsx_runtime_1.jsx)(Stop, { offset: "0", stopColor: tokens_1.material.rimColor, stopOpacity: highlight }), (0, jsx_runtime_1.jsx)(Stop, { offset: "1", stopColor: tokens_1.material.rimColor, stopOpacity: 0 })] })] }), (0, jsx_runtime_1.jsx)(Rect, { x: 0.5, y: 0.5, width: "99%", height: "99%", rx: rx, ry: rx, fill: "none", stroke: `url(#${rimId})`, strokeWidth: 1 }), (0, jsx_runtime_1.jsx)(Rect, { x: 1, y: 1, width: "98%", height: "40%", rx: Math.max(0, rx - 1), ry: Math.max(0, rx - 1), fill: `url(#${highlightId})` })] }));
56
+ const [size, setSize] = (0, react_1.useState)(null);
57
+ const effective = size ? effectiveGlassRadius(radius, size.width, size.height) : radius;
58
+ const rx = Math.max(0, effective - 0.5);
59
+ const svg = ((0, jsx_runtime_1.jsxs)(Svg, { width: "100%", height: "100%", style: fill, pointerEvents: "none", children: [(0, jsx_runtime_1.jsxs)(Defs, { children: [(0, jsx_runtime_1.jsxs)(LinearGradient, { id: rimId, x1: "0", y1: "0", x2: "0", y2: "1", children: [(0, jsx_runtime_1.jsx)(Stop, { offset: "0", stopColor: tokens_1.material.rimColor, stopOpacity: rim }), (0, jsx_runtime_1.jsx)(Stop, { offset: "0.55", stopColor: tokens_1.material.rimColor, stopOpacity: rim * 0.35 }), (0, jsx_runtime_1.jsx)(Stop, { offset: "1", stopColor: tokens_1.material.rimColor, stopOpacity: rim * 0.08 })] }), (0, jsx_runtime_1.jsxs)(LinearGradient, { id: highlightId, x1: "0", y1: "0", x2: "0", y2: "1", children: [(0, jsx_runtime_1.jsx)(Stop, { offset: "0", stopColor: tokens_1.material.rimColor, stopOpacity: highlight }), (0, jsx_runtime_1.jsx)(Stop, { offset: "1", stopColor: tokens_1.material.rimColor, stopOpacity: 0 })] })] }), (0, jsx_runtime_1.jsx)(Rect, { x: 0.5, y: 0.5, width: "99%", height: "99%", rx: rx, ry: rx, fill: "none", stroke: `url(#${rimId})`, strokeWidth: 1 }), (0, jsx_runtime_1.jsx)(Rect, { x: 1, y: 1, width: "98%", height: "40%", rx: Math.max(0, rx - 1), ry: Math.max(0, rx - 1), fill: `url(#${highlightId})` })] }));
60
+ if (!isNative)
61
+ return svg;
62
+ return ((0, jsx_runtime_1.jsx)(View, { style: fill, pointerEvents: "none", onLayout: (event) => {
63
+ const { width, height } = event.nativeEvent.layout;
64
+ setSize((prev) => prev && prev.width === width && prev.height === height ? prev : { width, height });
65
+ }, children: svg }));
35
66
  }
@@ -1,3 +1,10 @@
1
+ /**
2
+ * The corner radius a surface actually shows, from the radius it was given
3
+ * and the box it was laid out in. React Native clamps `borderRadius` to half
4
+ * the shorter side; this is the same clamp, so the rim and the container
5
+ * agree on one shape. A pill radius (9999) on a 350x34 field is 17, not 9999.
6
+ */
7
+ export declare function effectiveGlassRadius(radius: number, width: number, height: number): number;
1
8
  export interface GlassRimProps {
2
9
  /** The surface's corner radius, so the rim follows the shape. */
3
10
  radius: number;
@@ -12,5 +19,19 @@ export interface GlassRimProps {
12
19
  * Both are stacked stops of a vertical gradient in the same colour: the eye
13
20
  * reads the brightest edge as a lit curve and the falloff as the curve turning
14
21
  * away from the light.
22
+ *
23
+ * One shape, one radius. The container's corner is a true pill/semicircle:
24
+ * React Native clamps `borderRadius` to half the shorter side. SVG does NOT
25
+ * clamp that way — it clamps `rx` to half the WIDTH and `ry` to half the
26
+ * HEIGHT independently — so a raw pill radius (9999) drew a wide flat ellipse
27
+ * (rx ~ half the width) inside a pill container. That is the oval the owner
28
+ * saw inside the search field. The rim measures the surface it paints and
29
+ * uses the same effective radius the container shows — `min(radius, half the
30
+ * shorter side)` — so the rim and the container share one shape. Measuring
31
+ * here fixes every caller (the fallback glass, the tab-bar lens, the
32
+ * segmented-control lens) because the rim is the only layer that drew its
33
+ * shape in SVG. Before layout the raw radius is used (one frame); off-device
34
+ * (tests, web preview) there is no layout, so the raw radius is used exactly
35
+ * as before.
15
36
  */
16
37
  export declare function GlassRim({ radius, rim, highlight }: GlassRimProps): import("react").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glacia-native",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Liquid Glass UI components for React Native \u2014 real iOS 26 glass, with a clean fallback on Android and older iOS.",
5
5
  "author": "Binyam Feyissa (https://github.com/binyamfeyissa)",
6
6
  "license": "MIT",
@@ -19,7 +19,8 @@
19
19
  "react-native": "src/index.ts",
20
20
  "files": [
21
21
  "lib",
22
- "src"
22
+ "src",
23
+ "expo-module.config.json"
23
24
  ],
24
25
  "scripts": {
25
26
  "build": "tsc --project tsconfig.build.json",
@@ -25,6 +25,22 @@ export interface IconButtonProps {
25
25
 
26
26
  const SIZES = { sm: 32, md: 38, lg: 44 } as const;
27
27
 
28
+ /**
29
+ * The glyph size a render-function icon is handed, per button size — the
30
+ * engine's own small / regular / large icon sizes (18 / 22 / 24), so the
31
+ * fallback hands a function the same size the engine does.
32
+ */
33
+ const ICON_SIZES = { sm: 18, md: 22, lg: 24 } as const;
34
+
35
+ /**
36
+ * The same names in the engine's vocabulary (`small` / `regular` / `large`).
37
+ * The engine reads BUTTON_SIZES[size] with no fallback, so passing the
38
+ * library's `sm` / `md` / `lg` straight through resolves to undefined and
39
+ * throws the moment the engine mounts. The fallback never saw this because
40
+ * the engine never mounted — 0.6.3 mounts it, so the map is load-bearing.
41
+ */
42
+ const ENGINE_SIZE_NAMES = { sm: "small", md: "regular", lg: "large" } as const;
43
+
28
44
  /**
29
45
  * An icon button on Glacia's glass — ported from the engine's
30
46
  * `LiquidGlassIconButton`, which extends the engine button's design with a
@@ -65,7 +81,7 @@ export const IconButton = forwardRef<any, IconButtonProps>(function IconButton(
65
81
  accessibilityLabel={accessibilityLabel}
66
82
  accessibilityState={{ disabled, ...accessibilityState }}
67
83
  style={style}
68
- size={size}
84
+ size={ENGINE_SIZE_NAMES[size]}
69
85
  >
70
86
  {children}
71
87
  </EngineIconButtonComponent>
@@ -73,7 +89,17 @@ export const IconButton = forwardRef<any, IconButtonProps>(function IconButton(
73
89
  }
74
90
 
75
91
  // Fallback floor: solid circle, full geometry, on the fallback material.
92
+ // The icon renders centred in the circle. A render function is handed the
93
+ // same { color, size } the engine hands it — white on a tint, the scheme's
94
+ // foreground otherwise, at the button's glyph size. A plain element renders
95
+ // as given. (The circle used to be self-closing, so the icon never painted:
96
+ // the solid blue circles with no glyphs.)
76
97
  const radius = dimension / 2;
98
+ const iconColor = tint != null ? themeColors.onTint : themeColors.foreground;
99
+ const iconNode =
100
+ typeof icon === "function"
101
+ ? icon({ color: iconColor, size: ICON_SIZES[size] })
102
+ : icon;
77
103
  return (
78
104
  <Glass
79
105
  effect="regular"
@@ -103,7 +129,9 @@ export const IconButton = forwardRef<any, IconButtonProps>(function IconButton(
103
129
  alignItems: "center",
104
130
  justifyContent: "center",
105
131
  }}
106
- />
132
+ >
133
+ {iconNode}
134
+ </View>
107
135
  </Pressable>
108
136
  </Glass>
109
137
  );
@@ -82,6 +82,52 @@ export function glassCapabilities(): GlassCapabilities {
82
82
  /** Whether this build renders Apple's glass. */
83
83
  export const isGlassSupported = defaultRouter().supported;
84
84
 
85
+ /** Merges a style prop into one object; a function style is not resolvable here. */
86
+ function flattenStyle(style: any): ViewStyle {
87
+ if (!style) return {};
88
+ if (Array.isArray(style)) {
89
+ return style.reduce<ViewStyle>((acc, entry) => ({ ...acc, ...flattenStyle(entry) }), {});
90
+ }
91
+ if (typeof style === "function") return {};
92
+ return style as ViewStyle;
93
+ }
94
+
95
+ /**
96
+ * The corner radius the engine's shader should refract with, read from the
97
+ * style the container already paints with — the one shape source for the
98
+ * engine branch. The native view defaults `cornerRadius` to 0 (a rectangle),
99
+ * so without this a pill container would refract as a rectangle while its
100
+ * outline is a pill. A raw pill radius (9999) is safe to pass: the native
101
+ * side clamps it to half the shorter side, the same clamp the container
102
+ * uses. Per-corner radii pass through as an object; an explicit `cornerRadius`
103
+ * prop from the caller is read by the caller of this helper, not here.
104
+ */
105
+ function resolveCornerRadius(
106
+ style: StyleProp<ViewStyle>,
107
+ ): number | { topLeft: number; topRight: number; bottomRight: number; bottomLeft: number } | undefined {
108
+ const flat = flattenStyle(style);
109
+ const tl = (flat as any).borderTopLeftRadius;
110
+ const tr = (flat as any).borderTopRightRadius;
111
+ const br = (flat as any).borderBottomRightRadius;
112
+ const bl = (flat as any).borderBottomLeftRadius;
113
+ const base = typeof flat.borderRadius === "number" ? flat.borderRadius : 0;
114
+ if (
115
+ typeof tl === "number" ||
116
+ typeof tr === "number" ||
117
+ typeof br === "number" ||
118
+ typeof bl === "number"
119
+ ) {
120
+ return {
121
+ topLeft: typeof tl === "number" ? tl : base,
122
+ topRight: typeof tr === "number" ? tr : base,
123
+ bottomRight: typeof br === "number" ? br : base,
124
+ bottomLeft: typeof bl === "number" ? bl : base,
125
+ };
126
+ }
127
+ if (typeof flat.borderRadius === "number") return flat.borderRadius;
128
+ return undefined;
129
+ }
130
+
85
131
  /**
86
132
  * Platform Glass View — the single place a glass surface is chosen:
87
133
  * - iOS 26+: Real `UIGlassEffect` via the vendored engine's native view
@@ -124,6 +170,11 @@ export const GlassView = forwardRef<any, NativeGlassProps>(function GlassView(
124
170
  const LiquidGlassView = decision.LiquidGlassView;
125
171
  const variant = effect === "clear" ? "clear" : "regular";
126
172
  const glow = pressed === undefined ? props.glow : { progress: pressed ? 1 : 0, lens: true };
173
+ // The engine's shader, content clip and border all refract with the
174
+ // `cornerRadius` prop (default 0 = rectangle). Pass the radius the style
175
+ // already paints, so the glass and the container share one shape. An
176
+ // explicit `cornerRadius` prop from the caller wins.
177
+ const cornerRadius = (props as any).cornerRadius ?? resolveCornerRadius(style);
127
178
 
128
179
  // The engine owns the material; Glacia's own surface parameters stop at
129
180
  // the branch. Everything else (accessibility contract, provider pairing,
@@ -136,6 +187,7 @@ export const GlassView = forwardRef<any, NativeGlassProps>(function GlassView(
136
187
  tint={tintColor}
137
188
  interactive={interactive}
138
189
  glow={glow}
190
+ cornerRadius={cornerRadius}
139
191
  style={style}
140
192
  testID={testID}
141
193
  children={children}
@@ -10,13 +10,23 @@
10
10
  // and share the same resolver: no new native dependency, and it works
11
11
  // identically on iOS and Android.
12
12
 
13
- import { useId } from "react";
13
+ import { useId, useState } from "react";
14
14
 
15
15
  import { primitives } from "./primitives";
16
16
  import { material } from "./tokens";
17
17
 
18
18
  const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } as const;
19
19
 
20
+ /**
21
+ * The corner radius a surface actually shows, from the radius it was given
22
+ * and the box it was laid out in. React Native clamps `borderRadius` to half
23
+ * the shorter side; this is the same clamp, so the rim and the container
24
+ * agree on one shape. A pill radius (9999) on a 350x34 field is 17, not 9999.
25
+ */
26
+ export function effectiveGlassRadius(radius: number, width: number, height: number): number {
27
+ return Math.min(radius, width / 2, height / 2);
28
+ }
29
+
20
30
  export interface GlassRimProps {
21
31
  /** The surface's corner radius, so the rim follows the shape. */
22
32
  radius: number;
@@ -32,16 +42,31 @@ export interface GlassRimProps {
32
42
  * Both are stacked stops of a vertical gradient in the same colour: the eye
33
43
  * reads the brightest edge as a lit curve and the falloff as the curve turning
34
44
  * away from the light.
45
+ *
46
+ * One shape, one radius. The container's corner is a true pill/semicircle:
47
+ * React Native clamps `borderRadius` to half the shorter side. SVG does NOT
48
+ * clamp that way — it clamps `rx` to half the WIDTH and `ry` to half the
49
+ * HEIGHT independently — so a raw pill radius (9999) drew a wide flat ellipse
50
+ * (rx ~ half the width) inside a pill container. That is the oval the owner
51
+ * saw inside the search field. The rim measures the surface it paints and
52
+ * uses the same effective radius the container shows — `min(radius, half the
53
+ * shorter side)` — so the rim and the container share one shape. Measuring
54
+ * here fixes every caller (the fallback glass, the tab-bar lens, the
55
+ * segmented-control lens) because the rim is the only layer that drew its
56
+ * shape in SVG. Before layout the raw radius is used (one frame); off-device
57
+ * (tests, web preview) there is no layout, so the raw radius is used exactly
58
+ * as before.
35
59
  */
36
60
  export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
37
- const { Svg, Defs, Rect, LinearGradient, Stop } = primitives();
61
+ const { Svg, Defs, Rect, LinearGradient, Stop, View, isNative } = primitives();
38
62
  const key = useId().replace(/[^a-zA-Z0-9_-]/g, "");
39
63
  const rimId = `rim-${key}`;
40
64
  const highlightId = `top-${key}`;
41
- // SVG clamps rx/ry to half the side, so a pill radius simply becomes a pill.
42
- const rx = Math.max(0, radius - 0.5);
65
+ const [size, setSize] = useState<{ width: number; height: number } | null>(null);
66
+ const effective = size ? effectiveGlassRadius(radius, size.width, size.height) : radius;
67
+ const rx = Math.max(0, effective - 0.5);
43
68
 
44
- return (
69
+ const svg = (
45
70
  <Svg width="100%" height="100%" style={fill} pointerEvents="none">
46
71
  <Defs>
47
72
  <LinearGradient id={rimId} x1="0" y1="0" x2="0" y2="1">
@@ -76,4 +101,20 @@ export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
76
101
  />
77
102
  </Svg>
78
103
  );
104
+
105
+ if (!isNative) return svg;
106
+ return (
107
+ <View
108
+ style={fill}
109
+ pointerEvents="none"
110
+ onLayout={(event: any) => {
111
+ const { width, height } = event.nativeEvent.layout;
112
+ setSize((prev) =>
113
+ prev && prev.width === width && prev.height === height ? prev : { width, height },
114
+ );
115
+ }}
116
+ >
117
+ {svg}
118
+ </View>
119
+ );
79
120
  }