@plexui/react-native 0.2.21 → 0.2.22

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,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
2
3
  import { Animated, Platform, StyleSheet, View } from "react-native";
3
4
  import { useTheme, useThemeOverrides } from "../theme/ThemeProvider";
4
5
  import { blurModule, liquidGlassModule } from "./optional";
@@ -53,9 +54,35 @@ const WEB_LIQUID = {
53
54
  },
54
55
  lens: { token: "--mobile-glass-web-lens-filter", value: "blur(3px) brightness(1.12) saturate(200%)" },
55
56
  };
56
- // The lens: the glass's edge only, 14 in from its sides and 9 from its top and bottom (a small glass keeps a third)
57
- const lensMask = (inline, block) => `linear-gradient(to right, #000 0, transparent ${inline}px, transparent calc(100% - ${inline}px), #000 100%), ` +
58
- `linear-gradient(to bottom, #000 0, transparent ${block}px, transparent calc(100% - ${block}px), #000 100%)`;
57
+ /**
58
+ * The lens: the glass's edge only, fading in over 14 from its sides and 9 from its top and bottom (a small glass keeps
59
+ * a half and a third of its radius), along the glass's own shape. A ring whose hole is the glass's outline drawn
60
+ * smaller, blurred so its inner edge fades; bands across the box would leave a square in a round glass. The outline is
61
+ * the corner radius as the browser draws it, so no larger than half the glass's shorter side (a capsule's 999 is its
62
+ * height's half). A round glass (a bar button, a progress ring) keeps a thin rim of it: a ring as deep as a bar's
63
+ * reads on a small circle as a halo around a darker middle.
64
+ */
65
+ const lensMask = (width, height, radius) => {
66
+ const r = Math.max(0, Math.min(radius, width / 2, height / 2));
67
+ const round = r > 0 && Math.abs(width - height) <= 1 && r >= Math.min(width, height) / 2 - 0.5;
68
+ const inline = round ? r / 6 : Math.min(14, r > 0 ? r / 2 : 14);
69
+ const block = round ? r / 8 : Math.min(9, r > 0 ? r / 3 : 9);
70
+ const x = inline / 2;
71
+ const y = block / 2;
72
+ const w = Math.max(0, width - 2 * x);
73
+ const h = Math.max(0, height - 2 * y);
74
+ const rx = Math.max(0, Math.min(r - x, w / 2));
75
+ const ry = Math.max(0, Math.min(r - y, h / 2));
76
+ const f = (n) => +n.toFixed(2);
77
+ const hole = `M${f(x + rx)} ${f(y)}H${f(x + w - rx)}A${f(rx)} ${f(ry)} 0 0 1 ${f(x + w)} ${f(y + ry)}V${f(y + h - ry)}` +
78
+ `A${f(rx)} ${f(ry)} 0 0 1 ${f(x + w - rx)} ${f(y + h)}H${f(x + rx)}A${f(rx)} ${f(ry)} 0 0 1 ${f(x)} ${f(y + h - ry)}` +
79
+ `V${f(y + ry)}A${f(rx)} ${f(ry)} 0 0 1 ${f(x + rx)} ${f(y)}Z`;
80
+ // The outer edge stands 20 past the box, so the blur fades only the hole's edge; the glass's radius clips the rest
81
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${f(width)}" height="${f(height)}">` +
82
+ `<filter id="e" x="-1" y="-1" width="3" height="3"><feGaussianBlur stdDeviation="${f(inline / 4)} ${f(block / 4)}"/></filter>` +
83
+ `<path filter="url(#e)" fill-rule="evenodd" d="M-20 -20H${f(width + 20)}V${f(height + 20)}H-20Z${hole}"/></svg>`;
84
+ return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
85
+ };
59
86
  /** The filter and the shadow of the glass surfaces of the phone layer, by their fill (mobile-materials.css, touch.css). */
60
87
  const SURFACES = {
61
88
  "--menu-mobile-background": { filter: "--menu-mobile-backdrop-filter", shadow: "--menu-shadow" },
@@ -76,6 +103,8 @@ const intensityOf = (radius) => Math.max(0, Math.min(100, Math.round(radius * 5)
76
103
  */
77
104
  export function Glass({ radius = 0, elevation = "regular", tint, interactive, fillToken, filterToken, shadowToken, blur, style, children, ...rest }) {
78
105
  const theme = useTheme();
106
+ // The web lens's mask follows the glass's shape, so it needs the glass's size
107
+ const [size, setSize] = useState(null);
79
108
  const reduceTransparency = useReduceTransparency();
80
109
  const overrides = useThemeOverrides();
81
110
  const shape = { borderRadius: radius, borderCurve: "continuous" };
@@ -117,17 +146,24 @@ export function Glass({ radius = 0, elevation = "regular", tint, interactive, fi
117
146
  const sheen = liquid && tint == null ? own(WEB_LIQUID.sheen) : undefined;
118
147
  const lensToken = theme.token(WEB_LIQUID.lens.token);
119
148
  const lensFilter = typeof lensToken === "string" ? lensToken : WEB_LIQUID.lens.value;
120
- const mask = lensMask(Math.min(14, radius > 0 ? radius / 2 : 14), Math.min(9, radius > 0 ? radius / 3 : 9));
149
+ const mask = size != null && size.width > 0 && size.height > 0 ? lensMask(size.width, size.height, radius) : undefined;
121
150
  // An Animated.View, so a panel can move its own glass (a transform above the blur would stop it)
122
151
  return (_jsxs(Animated.View, { ...rest, style: [
123
152
  shape,
124
153
  { backgroundColor: fill, boxShadow: liquidShadow },
125
154
  { backdropFilter: filter, WebkitBackdropFilter: filter, backgroundImage: sheen },
126
155
  style,
127
- ], children: [liquid && lensFilter !== "none" ? (_jsx(View, { pointerEvents: "none", "aria-hidden": true, style: [
156
+ ], children: [liquid && lensFilter !== "none" ? (_jsx(View, { pointerEvents: "none", "aria-hidden": true, onLayout: (event) => {
157
+ const { width, height } = event.nativeEvent.layout;
158
+ if (size?.width !== width || size?.height !== height)
159
+ setSize({ width, height });
160
+ }, style: [
128
161
  StyleSheet.absoluteFill,
129
162
  shape,
130
- { backdropFilter: lensFilter, WebkitBackdropFilter: lensFilter, maskImage: mask, WebkitMaskImage: mask },
163
+ // Until the glass has a size, no lens: a lens unmasked would blur the whole glass
164
+ mask == null
165
+ ? null
166
+ : { backdropFilter: lensFilter, WebkitBackdropFilter: lensFilter, maskImage: mask, WebkitMaskImage: mask, maskSize: "100% 100%", WebkitMaskSize: "100% 100%" },
131
167
  ] })) : null, children] }));
132
168
  }
133
169
  const radiusPx = Number(/blur\(\s*([\d.]+)px\s*\)/.exec(filter)?.[1] ?? 12);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/react-native",
3
- "version": "0.2.21",
3
+ "version": "0.2.22",
4
4
  "description": "Plex UI components for React Native and Expo: iOS 26 and Material 3, on the shared @plexui/styles tokens",
5
5
  "license": "MIT",
6
6
  "homepage": "https://plexui.com",
@@ -1,3 +1,4 @@
1
+ import { useState } from "react"
1
2
  import { Animated, Platform, StyleSheet, View, type StyleProp, type ViewProps, type ViewStyle } from "react-native"
2
3
  import { useTheme, useThemeOverrides } from "../theme/ThemeProvider"
3
4
  import { blurModule, liquidGlassModule } from "./optional"
@@ -83,10 +84,37 @@ const WEB_LIQUID = {
83
84
  lens: { token: "--mobile-glass-web-lens-filter", value: "blur(3px) brightness(1.12) saturate(200%)" },
84
85
  }
85
86
 
86
- // The lens: the glass's edge only, 14 in from its sides and 9 from its top and bottom (a small glass keeps a third)
87
- const lensMask = (inline: number, block: number) =>
88
- `linear-gradient(to right, #000 0, transparent ${inline}px, transparent calc(100% - ${inline}px), #000 100%), ` +
89
- `linear-gradient(to bottom, #000 0, transparent ${block}px, transparent calc(100% - ${block}px), #000 100%)`
87
+ /**
88
+ * The lens: the glass's edge only, fading in over 14 from its sides and 9 from its top and bottom (a small glass keeps
89
+ * a half and a third of its radius), along the glass's own shape. A ring whose hole is the glass's outline drawn
90
+ * smaller, blurred so its inner edge fades; bands across the box would leave a square in a round glass. The outline is
91
+ * the corner radius as the browser draws it, so no larger than half the glass's shorter side (a capsule's 999 is its
92
+ * height's half). A round glass (a bar button, a progress ring) keeps a thin rim of it: a ring as deep as a bar's
93
+ * reads on a small circle as a halo around a darker middle.
94
+ */
95
+ const lensMask = (width: number, height: number, radius: number) => {
96
+ const r = Math.max(0, Math.min(radius, width / 2, height / 2))
97
+ const round = r > 0 && Math.abs(width - height) <= 1 && r >= Math.min(width, height) / 2 - 0.5
98
+ const inline = round ? r / 6 : Math.min(14, r > 0 ? r / 2 : 14)
99
+ const block = round ? r / 8 : Math.min(9, r > 0 ? r / 3 : 9)
100
+ const x = inline / 2
101
+ const y = block / 2
102
+ const w = Math.max(0, width - 2 * x)
103
+ const h = Math.max(0, height - 2 * y)
104
+ const rx = Math.max(0, Math.min(r - x, w / 2))
105
+ const ry = Math.max(0, Math.min(r - y, h / 2))
106
+ const f = (n: number) => +n.toFixed(2)
107
+ const hole =
108
+ `M${f(x + rx)} ${f(y)}H${f(x + w - rx)}A${f(rx)} ${f(ry)} 0 0 1 ${f(x + w)} ${f(y + ry)}V${f(y + h - ry)}` +
109
+ `A${f(rx)} ${f(ry)} 0 0 1 ${f(x + w - rx)} ${f(y + h)}H${f(x + rx)}A${f(rx)} ${f(ry)} 0 0 1 ${f(x)} ${f(y + h - ry)}` +
110
+ `V${f(y + ry)}A${f(rx)} ${f(ry)} 0 0 1 ${f(x + rx)} ${f(y)}Z`
111
+ // The outer edge stands 20 past the box, so the blur fades only the hole's edge; the glass's radius clips the rest
112
+ const svg =
113
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${f(width)}" height="${f(height)}">` +
114
+ `<filter id="e" x="-1" y="-1" width="3" height="3"><feGaussianBlur stdDeviation="${f(inline / 4)} ${f(block / 4)}"/></filter>` +
115
+ `<path filter="url(#e)" fill-rule="evenodd" d="M-20 -20H${f(width + 20)}V${f(height + 20)}H-20Z${hole}"/></svg>`
116
+ return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`
117
+ }
90
118
 
91
119
  /** The filter and the shadow of the glass surfaces of the phone layer, by their fill (mobile-materials.css, touch.css). */
92
120
  const SURFACES: Record<string, { filter: string; shadow: string }> = {
@@ -122,6 +150,8 @@ export function Glass({
122
150
  ...rest
123
151
  }: GlassProps) {
124
152
  const theme = useTheme()
153
+ // The web lens's mask follows the glass's shape, so it needs the glass's size
154
+ const [size, setSize] = useState<{ width: number; height: number } | null>(null)
125
155
  const reduceTransparency = useReduceTransparency()
126
156
  const overrides = useThemeOverrides()
127
157
  const shape: ViewStyle = { borderRadius: radius, borderCurve: "continuous" }
@@ -174,7 +204,7 @@ export function Glass({
174
204
  const sheen = liquid && tint == null ? own(WEB_LIQUID.sheen) : undefined
175
205
  const lensToken = theme.token(WEB_LIQUID.lens.token)
176
206
  const lensFilter = typeof lensToken === "string" ? lensToken : WEB_LIQUID.lens.value
177
- const mask = lensMask(Math.min(14, radius > 0 ? radius / 2 : 14), Math.min(9, radius > 0 ? radius / 3 : 9))
207
+ const mask = size != null && size.width > 0 && size.height > 0 ? lensMask(size.width, size.height, radius) : undefined
178
208
  // An Animated.View, so a panel can move its own glass (a transform above the blur would stop it)
179
209
  return (
180
210
  <Animated.View
@@ -190,10 +220,17 @@ export function Glass({
190
220
  <View
191
221
  pointerEvents="none"
192
222
  aria-hidden
223
+ onLayout={(event) => {
224
+ const { width, height } = event.nativeEvent.layout
225
+ if (size?.width !== width || size?.height !== height) setSize({ width, height })
226
+ }}
193
227
  style={[
194
228
  StyleSheet.absoluteFill,
195
229
  shape,
196
- { backdropFilter: lensFilter, WebkitBackdropFilter: lensFilter, maskImage: mask, WebkitMaskImage: mask } as ViewStyle,
230
+ // Until the glass has a size, no lens: a lens unmasked would blur the whole glass
231
+ mask == null
232
+ ? null
233
+ : ({ backdropFilter: lensFilter, WebkitBackdropFilter: lensFilter, maskImage: mask, WebkitMaskImage: mask, maskSize: "100% 100%", WebkitMaskSize: "100% 100%" } as ViewStyle),
197
234
  ]}
198
235
  />
199
236
  ) : null}