glacia-native 0.6.2 → 0.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.
- package/expo-module.config.json +19 -0
- package/lib/module/IconButton.js +31 -3
- package/lib/module/internal/GlassView.js +49 -1
- package/lib/module/internal/rim.js +92 -4
- package/lib/typescript/internal/rim.d.ts +28 -0
- package/package.json +3 -2
- package/src/IconButton.tsx +36 -3
- package/src/internal/GlassView.tsx +52 -0
- package/src/internal/rim.tsx +117 -9
|
@@ -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
|
+
}
|
package/lib/module/IconButton.js
CHANGED
|
@@ -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,11 +38,25 @@ 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.)
|
|
49
|
+
// The shell is a circle, like the fill inside it: the Glass style carries
|
|
50
|
+
// borderRadius = dimension/2, so the shell's corner arc and the fill's edge
|
|
51
|
+
// are the same curve. Without it the shell defaulted to radii.md (14) — a
|
|
52
|
+
// rounded square around a circle — and its corners stuck out past the fill
|
|
53
|
+
// at the diagonals (the halo). A caller's own borderRadius still wins.
|
|
30
54
|
const radius = dimension / 2;
|
|
31
|
-
|
|
55
|
+
const iconColor = tint != null ? themeColors.onTint : themeColors.foreground;
|
|
56
|
+
const iconNode = typeof icon === "function"
|
|
57
|
+
? icon({ color: iconColor, size: ICON_SIZES[size] })
|
|
58
|
+
: icon;
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "control", isDark: isDark, tintColor: tint, style: [{ borderRadius: radius }, 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
60
|
width: dimension,
|
|
33
61
|
height: dimension,
|
|
34
62
|
borderRadius: radius,
|
|
@@ -36,5 +64,5 @@ exports.IconButton = (0, react_1.forwardRef)(function IconButton({ icon, onPress
|
|
|
36
64
|
opacity: disabled ? 0.38 : 1,
|
|
37
65
|
alignItems: "center",
|
|
38
66
|
justifyContent: "center",
|
|
39
|
-
} }) }) }));
|
|
67
|
+
}, children: iconNode }) }) }));
|
|
40
68
|
});
|
|
@@ -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,106 @@ 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.
|
|
50
|
+
*
|
|
51
|
+
* The rects are sized the same way — in absolute pixels from the measured
|
|
52
|
+
* box. They used to be `width="99%"`, meant as a 0.5px inset, but 1% of a
|
|
53
|
+
* 342px card is 3.4px, so the rim sat ~2px inside the border on the right
|
|
54
|
+
* and bottom and drew a second line there. The wrapper measures on a device
|
|
55
|
+
* through onLayout and in the web preview through a DOM ref, so the mirror
|
|
56
|
+
* gets the fix too.
|
|
26
57
|
*/
|
|
27
58
|
function GlassRim({ radius, rim, highlight }) {
|
|
28
|
-
const { Svg, Defs, Rect, LinearGradient, Stop } = (0, primitives_1.primitives)();
|
|
59
|
+
const { Svg, Defs, Rect, LinearGradient, Stop, View } = (0, primitives_1.primitives)();
|
|
29
60
|
const key = (0, react_1.useId)().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
30
61
|
const rimId = `rim-${key}`;
|
|
31
62
|
const highlightId = `top-${key}`;
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
63
|
+
const [size, setSize] = (0, react_1.useState)(null);
|
|
64
|
+
const effective = size ? effectiveGlassRadius(radius, size.width, size.height) : radius;
|
|
65
|
+
const rx = Math.max(0, effective - 0.5);
|
|
66
|
+
// The rects are sized in absolute pixels from the measured box, not in
|
|
67
|
+
// percentages. width="99%" was meant as a 0.5px inset, but 1% of a 342px
|
|
68
|
+
// card is 3.4px, so the rim sat ~2px inside the border on the right and
|
|
69
|
+
// bottom and drew a second line there — while the left and top, which
|
|
70
|
+
// start at 0.5 and overlap the border, read as one clean line. Before any
|
|
71
|
+
// measurement there is no box, so the percentage rects are the first frame.
|
|
72
|
+
const rimWidth = size ? Math.max(0, size.width - 1) : "99%";
|
|
73
|
+
const rimHeight = size ? Math.max(0, size.height - 1) : "99%";
|
|
74
|
+
const highlightWidth = size ? Math.max(0, size.width - 2) : "98%";
|
|
75
|
+
const highlightHeight = size ? Math.round(size.height * 0.4 * 10) / 10 : "40%";
|
|
76
|
+
const applySize = (0, react_1.useCallback)((width, height) => {
|
|
77
|
+
if (width > 0 && height > 0) {
|
|
78
|
+
setSize((prev) => prev && prev.width === width && prev.height === height ? prev : { width, height });
|
|
79
|
+
}
|
|
80
|
+
}, []);
|
|
81
|
+
/**
|
|
82
|
+
* DOM measurement for the web mirror / preview.
|
|
83
|
+
*
|
|
84
|
+
* The native path measures through onLayout below. Off-device there is no
|
|
85
|
+
* layout event — the DOM stand-in drops onLayout — so the rim measures its
|
|
86
|
+
* own box the way Slider does: a ref on the wrapper, getBoundingClientRect
|
|
87
|
+
* on mount, and a ResizeObserver for later resizes. Without this the mirror
|
|
88
|
+
* would keep the percentage rects (and the double line) forever, because
|
|
89
|
+
* the mirror never fires a layout event. The guard is what keeps this a
|
|
90
|
+
* no-op on a device: a native view has no getBoundingClientRect.
|
|
91
|
+
*/
|
|
92
|
+
const observerRef = (0, react_1.useRef)(null);
|
|
93
|
+
const measureRef = (0, react_1.useCallback)((node) => {
|
|
94
|
+
if (observerRef.current) {
|
|
95
|
+
observerRef.current.disconnect();
|
|
96
|
+
observerRef.current = null;
|
|
97
|
+
}
|
|
98
|
+
if (!node || typeof node.getBoundingClientRect !== "function")
|
|
99
|
+
return;
|
|
100
|
+
const rect = node.getBoundingClientRect();
|
|
101
|
+
applySize(rect.width, rect.height);
|
|
102
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
103
|
+
const observer = new ResizeObserver(() => {
|
|
104
|
+
const next = node.getBoundingClientRect();
|
|
105
|
+
applySize(next.width, next.height);
|
|
106
|
+
});
|
|
107
|
+
observer.observe(node);
|
|
108
|
+
observerRef.current = observer;
|
|
109
|
+
}
|
|
110
|
+
}, [applySize]);
|
|
111
|
+
(0, react_1.useEffect)(() => () => {
|
|
112
|
+
if (observerRef.current)
|
|
113
|
+
observerRef.current.disconnect();
|
|
114
|
+
}, []);
|
|
115
|
+
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: rimWidth, height: rimHeight, rx: rx, ry: rx, fill: "none", stroke: `url(#${rimId})`, strokeWidth: 1 }), (0, jsx_runtime_1.jsx)(Rect, { x: 1, y: 1, width: highlightWidth, height: highlightHeight, rx: Math.max(0, rx - 1), ry: Math.max(0, rx - 1), fill: `url(#${highlightId})` })] }));
|
|
116
|
+
// One wrapper for both paths: onLayout measures on a device (the DOM
|
|
117
|
+
// stand-in drops onLayout), the ref measures in the web preview. The
|
|
118
|
+
// wrapper is an absolute fill either way, so it changes no layout.
|
|
119
|
+
return ((0, jsx_runtime_1.jsx)(View, { style: fill, pointerEvents: "none", ref: measureRef, onLayout: (event) => {
|
|
120
|
+
const { width, height } = event.nativeEvent.layout;
|
|
121
|
+
applySize(width, height);
|
|
122
|
+
}, children: svg }));
|
|
35
123
|
}
|
|
@@ -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,26 @@ 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.
|
|
36
|
+
*
|
|
37
|
+
* The rects are sized the same way — in absolute pixels from the measured
|
|
38
|
+
* box. They used to be `width="99%"`, meant as a 0.5px inset, but 1% of a
|
|
39
|
+
* 342px card is 3.4px, so the rim sat ~2px inside the border on the right
|
|
40
|
+
* and bottom and drew a second line there. The wrapper measures on a device
|
|
41
|
+
* through onLayout and in the web preview through a DOM ref, so the mirror
|
|
42
|
+
* gets the fix too.
|
|
15
43
|
*/
|
|
16
44
|
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.
|
|
3
|
+
"version": "0.6.4",
|
|
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",
|
package/src/IconButton.tsx
CHANGED
|
@@ -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,14 +89,29 @@ 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.)
|
|
97
|
+
// The shell is a circle, like the fill inside it: the Glass style carries
|
|
98
|
+
// borderRadius = dimension/2, so the shell's corner arc and the fill's edge
|
|
99
|
+
// are the same curve. Without it the shell defaulted to radii.md (14) — a
|
|
100
|
+
// rounded square around a circle — and its corners stuck out past the fill
|
|
101
|
+
// at the diagonals (the halo). A caller's own borderRadius still wins.
|
|
76
102
|
const radius = dimension / 2;
|
|
103
|
+
const iconColor = tint != null ? themeColors.onTint : themeColors.foreground;
|
|
104
|
+
const iconNode =
|
|
105
|
+
typeof icon === "function"
|
|
106
|
+
? icon({ color: iconColor, size: ICON_SIZES[size] })
|
|
107
|
+
: icon;
|
|
77
108
|
return (
|
|
78
109
|
<Glass
|
|
79
110
|
effect="regular"
|
|
80
111
|
surface="control"
|
|
81
112
|
isDark={isDark}
|
|
82
113
|
tintColor={tint}
|
|
83
|
-
style={style}
|
|
114
|
+
style={[{ borderRadius: radius }, style]}
|
|
84
115
|
testID={testID}
|
|
85
116
|
>
|
|
86
117
|
<Pressable
|
|
@@ -103,7 +134,9 @@ export const IconButton = forwardRef<any, IconButtonProps>(function IconButton(
|
|
|
103
134
|
alignItems: "center",
|
|
104
135
|
justifyContent: "center",
|
|
105
136
|
}}
|
|
106
|
-
|
|
137
|
+
>
|
|
138
|
+
{iconNode}
|
|
139
|
+
</View>
|
|
107
140
|
</Pressable>
|
|
108
141
|
</Glass>
|
|
109
142
|
);
|
|
@@ -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}
|
package/src/internal/rim.tsx
CHANGED
|
@@ -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 { useCallback, useEffect, useId, useRef, 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,97 @@ 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.
|
|
59
|
+
*
|
|
60
|
+
* The rects are sized the same way — in absolute pixels from the measured
|
|
61
|
+
* box. They used to be `width="99%"`, meant as a 0.5px inset, but 1% of a
|
|
62
|
+
* 342px card is 3.4px, so the rim sat ~2px inside the border on the right
|
|
63
|
+
* and bottom and drew a second line there. The wrapper measures on a device
|
|
64
|
+
* through onLayout and in the web preview through a DOM ref, so the mirror
|
|
65
|
+
* gets the fix too.
|
|
35
66
|
*/
|
|
36
67
|
export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
|
|
37
|
-
const { Svg, Defs, Rect, LinearGradient, Stop } = primitives();
|
|
68
|
+
const { Svg, Defs, Rect, LinearGradient, Stop, View } = primitives();
|
|
38
69
|
const key = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
39
70
|
const rimId = `rim-${key}`;
|
|
40
71
|
const highlightId = `top-${key}`;
|
|
41
|
-
|
|
42
|
-
const
|
|
72
|
+
const [size, setSize] = useState<{ width: number; height: number } | null>(null);
|
|
73
|
+
const effective = size ? effectiveGlassRadius(radius, size.width, size.height) : radius;
|
|
74
|
+
const rx = Math.max(0, effective - 0.5);
|
|
43
75
|
|
|
44
|
-
|
|
76
|
+
// The rects are sized in absolute pixels from the measured box, not in
|
|
77
|
+
// percentages. width="99%" was meant as a 0.5px inset, but 1% of a 342px
|
|
78
|
+
// card is 3.4px, so the rim sat ~2px inside the border on the right and
|
|
79
|
+
// bottom and drew a second line there — while the left and top, which
|
|
80
|
+
// start at 0.5 and overlap the border, read as one clean line. Before any
|
|
81
|
+
// measurement there is no box, so the percentage rects are the first frame.
|
|
82
|
+
const rimWidth = size ? Math.max(0, size.width - 1) : "99%";
|
|
83
|
+
const rimHeight = size ? Math.max(0, size.height - 1) : "99%";
|
|
84
|
+
const highlightWidth = size ? Math.max(0, size.width - 2) : "98%";
|
|
85
|
+
const highlightHeight = size ? Math.round(size.height * 0.4 * 10) / 10 : "40%";
|
|
86
|
+
|
|
87
|
+
const applySize = useCallback((width: number, height: number) => {
|
|
88
|
+
if (width > 0 && height > 0) {
|
|
89
|
+
setSize((prev) =>
|
|
90
|
+
prev && prev.width === width && prev.height === height ? prev : { width, height },
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* DOM measurement for the web mirror / preview.
|
|
97
|
+
*
|
|
98
|
+
* The native path measures through onLayout below. Off-device there is no
|
|
99
|
+
* layout event — the DOM stand-in drops onLayout — so the rim measures its
|
|
100
|
+
* own box the way Slider does: a ref on the wrapper, getBoundingClientRect
|
|
101
|
+
* on mount, and a ResizeObserver for later resizes. Without this the mirror
|
|
102
|
+
* would keep the percentage rects (and the double line) forever, because
|
|
103
|
+
* the mirror never fires a layout event. The guard is what keeps this a
|
|
104
|
+
* no-op on a device: a native view has no getBoundingClientRect.
|
|
105
|
+
*/
|
|
106
|
+
const observerRef = useRef<any>(null);
|
|
107
|
+
const measureRef = useCallback(
|
|
108
|
+
(node: any) => {
|
|
109
|
+
if (observerRef.current) {
|
|
110
|
+
observerRef.current.disconnect();
|
|
111
|
+
observerRef.current = null;
|
|
112
|
+
}
|
|
113
|
+
if (!node || typeof node.getBoundingClientRect !== "function") return;
|
|
114
|
+
const rect = node.getBoundingClientRect();
|
|
115
|
+
applySize(rect.width, rect.height);
|
|
116
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
117
|
+
const observer = new ResizeObserver(() => {
|
|
118
|
+
const next = node.getBoundingClientRect();
|
|
119
|
+
applySize(next.width, next.height);
|
|
120
|
+
});
|
|
121
|
+
observer.observe(node);
|
|
122
|
+
observerRef.current = observer;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
[applySize],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
useEffect(
|
|
129
|
+
() => () => {
|
|
130
|
+
if (observerRef.current) observerRef.current.disconnect();
|
|
131
|
+
},
|
|
132
|
+
[],
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const svg = (
|
|
45
136
|
<Svg width="100%" height="100%" style={fill} pointerEvents="none">
|
|
46
137
|
<Defs>
|
|
47
138
|
<LinearGradient id={rimId} x1="0" y1="0" x2="0" y2="1">
|
|
@@ -57,8 +148,8 @@ export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
|
|
|
57
148
|
<Rect
|
|
58
149
|
x={0.5}
|
|
59
150
|
y={0.5}
|
|
60
|
-
width=
|
|
61
|
-
height=
|
|
151
|
+
width={rimWidth}
|
|
152
|
+
height={rimHeight}
|
|
62
153
|
rx={rx}
|
|
63
154
|
ry={rx}
|
|
64
155
|
fill="none"
|
|
@@ -68,12 +159,29 @@ export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
|
|
|
68
159
|
<Rect
|
|
69
160
|
x={1}
|
|
70
161
|
y={1}
|
|
71
|
-
width=
|
|
72
|
-
height=
|
|
162
|
+
width={highlightWidth}
|
|
163
|
+
height={highlightHeight}
|
|
73
164
|
rx={Math.max(0, rx - 1)}
|
|
74
165
|
ry={Math.max(0, rx - 1)}
|
|
75
166
|
fill={`url(#${highlightId})`}
|
|
76
167
|
/>
|
|
77
168
|
</Svg>
|
|
78
169
|
);
|
|
170
|
+
|
|
171
|
+
// One wrapper for both paths: onLayout measures on a device (the DOM
|
|
172
|
+
// stand-in drops onLayout), the ref measures in the web preview. The
|
|
173
|
+
// wrapper is an absolute fill either way, so it changes no layout.
|
|
174
|
+
return (
|
|
175
|
+
<View
|
|
176
|
+
style={fill}
|
|
177
|
+
pointerEvents="none"
|
|
178
|
+
ref={measureRef}
|
|
179
|
+
onLayout={(event: any) => {
|
|
180
|
+
const { width, height } = event.nativeEvent.layout;
|
|
181
|
+
applySize(width, height);
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
{svg}
|
|
185
|
+
</View>
|
|
186
|
+
);
|
|
79
187
|
}
|