glacia-native 0.6.3 → 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/lib/module/IconButton.js
CHANGED
|
@@ -46,12 +46,17 @@ exports.IconButton = (0, react_1.forwardRef)(function IconButton({ icon, onPress
|
|
|
46
46
|
// foreground otherwise, at the button's glyph size. A plain element renders
|
|
47
47
|
// as given. (The circle used to be self-closing, so the icon never painted:
|
|
48
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.
|
|
49
54
|
const radius = dimension / 2;
|
|
50
55
|
const iconColor = tint != null ? themeColors.onTint : themeColors.foreground;
|
|
51
56
|
const iconNode = typeof icon === "function"
|
|
52
57
|
? icon({ color: iconColor, size: ICON_SIZES[size] })
|
|
53
58
|
: icon;
|
|
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: {
|
|
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: {
|
|
55
60
|
width: dimension,
|
|
56
61
|
height: dimension,
|
|
57
62
|
borderRadius: radius,
|
|
@@ -47,20 +47,77 @@ function effectiveGlassRadius(radius, width, height) {
|
|
|
47
47
|
* shape in SVG. Before layout the raw radius is used (one frame); off-device
|
|
48
48
|
* (tests, web preview) there is no layout, so the raw radius is used exactly
|
|
49
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.
|
|
50
57
|
*/
|
|
51
58
|
function GlassRim({ radius, rim, highlight }) {
|
|
52
|
-
const { Svg, Defs, Rect, LinearGradient, Stop, View
|
|
59
|
+
const { Svg, Defs, Rect, LinearGradient, Stop, View } = (0, primitives_1.primitives)();
|
|
53
60
|
const key = (0, react_1.useId)().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
54
61
|
const rimId = `rim-${key}`;
|
|
55
62
|
const highlightId = `top-${key}`;
|
|
56
63
|
const [size, setSize] = (0, react_1.useState)(null);
|
|
57
64
|
const effective = size ? effectiveGlassRadius(radius, size.width, size.height) : radius;
|
|
58
65
|
const rx = Math.max(0, effective - 0.5);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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) {
|
|
64
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);
|
|
65
122
|
}, children: svg }));
|
|
66
123
|
}
|
|
@@ -33,5 +33,12 @@ export interface GlassRimProps {
|
|
|
33
33
|
* shape in SVG. Before layout the raw radius is used (one frame); off-device
|
|
34
34
|
* (tests, web preview) there is no layout, so the raw radius is used exactly
|
|
35
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.
|
|
36
43
|
*/
|
|
37
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",
|
package/src/IconButton.tsx
CHANGED
|
@@ -94,6 +94,11 @@ export const IconButton = forwardRef<any, IconButtonProps>(function IconButton(
|
|
|
94
94
|
// foreground otherwise, at the button's glyph size. A plain element renders
|
|
95
95
|
// as given. (The circle used to be self-closing, so the icon never painted:
|
|
96
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.
|
|
97
102
|
const radius = dimension / 2;
|
|
98
103
|
const iconColor = tint != null ? themeColors.onTint : themeColors.foreground;
|
|
99
104
|
const iconNode =
|
|
@@ -106,7 +111,7 @@ export const IconButton = forwardRef<any, IconButtonProps>(function IconButton(
|
|
|
106
111
|
surface="control"
|
|
107
112
|
isDark={isDark}
|
|
108
113
|
tintColor={tint}
|
|
109
|
-
style={style}
|
|
114
|
+
style={[{ borderRadius: radius }, style]}
|
|
110
115
|
testID={testID}
|
|
111
116
|
>
|
|
112
117
|
<Pressable
|
package/src/internal/rim.tsx
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
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, useState } 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";
|
|
@@ -56,9 +56,16 @@ export interface GlassRimProps {
|
|
|
56
56
|
* shape in SVG. Before layout the raw radius is used (one frame); off-device
|
|
57
57
|
* (tests, web preview) there is no layout, so the raw radius is used exactly
|
|
58
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.
|
|
59
66
|
*/
|
|
60
67
|
export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
|
|
61
|
-
const { Svg, Defs, Rect, LinearGradient, Stop, View
|
|
68
|
+
const { Svg, Defs, Rect, LinearGradient, Stop, View } = primitives();
|
|
62
69
|
const key = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
63
70
|
const rimId = `rim-${key}`;
|
|
64
71
|
const highlightId = `top-${key}`;
|
|
@@ -66,6 +73,65 @@ export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
|
|
|
66
73
|
const effective = size ? effectiveGlassRadius(radius, size.width, size.height) : radius;
|
|
67
74
|
const rx = Math.max(0, effective - 0.5);
|
|
68
75
|
|
|
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
|
+
|
|
69
135
|
const svg = (
|
|
70
136
|
<Svg width="100%" height="100%" style={fill} pointerEvents="none">
|
|
71
137
|
<Defs>
|
|
@@ -82,8 +148,8 @@ export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
|
|
|
82
148
|
<Rect
|
|
83
149
|
x={0.5}
|
|
84
150
|
y={0.5}
|
|
85
|
-
width=
|
|
86
|
-
height=
|
|
151
|
+
width={rimWidth}
|
|
152
|
+
height={rimHeight}
|
|
87
153
|
rx={rx}
|
|
88
154
|
ry={rx}
|
|
89
155
|
fill="none"
|
|
@@ -93,8 +159,8 @@ export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
|
|
|
93
159
|
<Rect
|
|
94
160
|
x={1}
|
|
95
161
|
y={1}
|
|
96
|
-
width=
|
|
97
|
-
height=
|
|
162
|
+
width={highlightWidth}
|
|
163
|
+
height={highlightHeight}
|
|
98
164
|
rx={Math.max(0, rx - 1)}
|
|
99
165
|
ry={Math.max(0, rx - 1)}
|
|
100
166
|
fill={`url(#${highlightId})`}
|
|
@@ -102,16 +168,17 @@ export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
|
|
|
102
168
|
</Svg>
|
|
103
169
|
);
|
|
104
170
|
|
|
105
|
-
|
|
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.
|
|
106
174
|
return (
|
|
107
175
|
<View
|
|
108
176
|
style={fill}
|
|
109
177
|
pointerEvents="none"
|
|
178
|
+
ref={measureRef}
|
|
110
179
|
onLayout={(event: any) => {
|
|
111
180
|
const { width, height } = event.nativeEvent.layout;
|
|
112
|
-
|
|
113
|
-
prev && prev.width === width && prev.height === height ? prev : { width, height },
|
|
114
|
-
);
|
|
181
|
+
applySize(width, height);
|
|
115
182
|
}}
|
|
116
183
|
>
|
|
117
184
|
{svg}
|