@plexui/react-native 0.2.17 → 0.2.19
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/dist/es/components/SegmentedControl/SegmentedControl.js +9 -5
- package/dist/es/components/TabBar/TabBar.js +16 -3
- package/dist/es/internal/CssSlide.js +35 -0
- package/dist/es/internal/Glass.js +53 -7
- package/dist/types/internal/CssSlide.d.ts +22 -0
- package/package.json +1 -1
- package/src/components/SegmentedControl/SegmentedControl.tsx +28 -5
- package/src/components/TabBar/TabBar.tsx +25 -3
- package/src/internal/CssSlide.tsx +54 -0
- package/src/internal/Glass.tsx +65 -7
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, isValidElement, useContext, useEffect, useRef, useState } from "react";
|
|
3
|
-
import { Animated, Easing, StyleSheet, View } from "react-native";
|
|
3
|
+
import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
4
4
|
import { Pressable } from "../../internal/Pressable";
|
|
5
|
+
import { CssSlide } from "../../internal/CssSlide";
|
|
5
6
|
import { childrenOfType, isRenderable, textOf } from "../../internal/children";
|
|
6
7
|
import { Glass } from "../../internal/Glass";
|
|
7
8
|
import { curves } from "../../internal/motion";
|
|
@@ -118,7 +119,8 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
118
119
|
const [width] = useState(() => new Animated.Value(0));
|
|
119
120
|
const placed = useRef(false);
|
|
120
121
|
useEffect(() => {
|
|
121
|
-
|
|
122
|
+
// The web's thumb slides in CSS
|
|
123
|
+
if (selectedX == null || selectedWidth == null || Platform.OS === "web")
|
|
122
124
|
return;
|
|
123
125
|
if (!placed.current || theme.reducedMotion) {
|
|
124
126
|
x.setValue(selectedX);
|
|
@@ -146,7 +148,9 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
146
148
|
};
|
|
147
149
|
// UISegmentedControl keeps its type at a large text size; a label here grows until it fills its segment
|
|
148
150
|
const maxScale = look.height / look.lineHeight;
|
|
149
|
-
const content = (_jsxs(_Fragment, { children: [selected
|
|
151
|
+
const content = (_jsxs(_Fragment, { children: [selected && Platform.OS === "web" ? (
|
|
152
|
+
// The web slides the thumb in CSS, off the JavaScript thread
|
|
153
|
+
_jsx(CssSlide, { x: selected.x, width: selected.width, side: "left", duration: look.duration, easing: "cubic-bezier(0.25, 0.1, 0.25, 1)", still: theme.reducedMotion, style: [styles.thumb, { top: look.gutter, bottom: look.gutter, borderRadius: optionRadius, backgroundColor: look.thumb }] })) : selected ? (_jsx(Animated.View, { pointerEvents: "none", style: [styles.thumb, { top: look.gutter, bottom: look.gutter, left: x, width, borderRadius: optionRadius, backgroundColor: look.thumb }] })) : null, options.map((option) => {
|
|
150
154
|
const isSelected = option.value === value;
|
|
151
155
|
const off = disabled || !!option.disabled;
|
|
152
156
|
const color = off ? theme.color("--alpha-20") : theme.colors.text;
|
|
@@ -204,7 +208,7 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
|
|
|
204
208
|
const frameWidth = measured ? widths[options[index].value] : undefined;
|
|
205
209
|
const frame = frameX != null;
|
|
206
210
|
useEffect(() => {
|
|
207
|
-
if (frameX == null || frameWidth == null)
|
|
211
|
+
if (frameX == null || frameWidth == null || Platform.OS === "web")
|
|
208
212
|
return;
|
|
209
213
|
if (!placed.current || theme.reducedMotion) {
|
|
210
214
|
x.setValue(frameX);
|
|
@@ -219,7 +223,7 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
|
|
|
219
223
|
styles.androidRow,
|
|
220
224
|
{ height, borderRadius: height / 2, backgroundColor: barSurface(m, theme.scheme), boxShadow: barShadow(theme.scheme) },
|
|
221
225
|
block ? styles.stretch : null,
|
|
222
|
-
], children: [frame ? (_jsx(Animated.View, { pointerEvents: "none", style: [styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12), left: x, width }] })) : null, options.map((option) => (_jsx(AndroidSegment, { option: option, selected: option.value === value, off: disabled || !!option.disabled, framed: frame, showBadges: showBadges, badgeColor: badgeColor, height: inner,
|
|
226
|
+
], children: [frame && Platform.OS === "web" ? (_jsx(CssSlide, { x: frameX, width: frameWidth, side: "left", duration: ANDROID_MOVE.duration, easing: "cubic-bezier(0.23, 1, 0.32, 1)", still: theme.reducedMotion, style: [styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12) }] })) : frame ? (_jsx(Animated.View, { pointerEvents: "none", style: [styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12), left: x, width }] })) : null, options.map((option) => (_jsx(AndroidSegment, { option: option, selected: option.value === value, off: disabled || !!option.disabled, framed: frame, showBadges: showBadges, badgeColor: badgeColor, height: inner,
|
|
223
227
|
// In a filled row equal segments share the width and the others take their label and share what is left; a
|
|
224
228
|
// control that hugs its segments gives equal ones the widest one's width
|
|
225
229
|
size: block ? (equal ? styles.grow : styles.share) : widest ? { minWidth: widest } : null, keys: keys, select: select, onWidth: (w) => setWidths((prev) => (prev[option.value] === w ? prev : { ...prev, [option.value]: w })) }, option.value)))] }));
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
-
import { Animated, Easing, StyleSheet, View } from "react-native";
|
|
3
|
+
import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
4
4
|
import { Pressable } from "../../internal/Pressable";
|
|
5
|
+
import { CssSlide } from "../../internal/CssSlide";
|
|
5
6
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
6
7
|
import Search from "../../icons/plex/Search";
|
|
7
8
|
import { BarBackdrop, SoftBottomEdge, TabBarFade, ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, glassBarBlur, useAndroidGlass } from "../../internal/BarBackdrop";
|
|
@@ -11,7 +12,7 @@ import { Glass } from "../../internal/Glass";
|
|
|
11
12
|
import { curves } from "../../internal/motion";
|
|
12
13
|
import { useTabKeys } from "../../internal/tabKeys";
|
|
13
14
|
import { barSurface, mix, stateLayer, withAlpha } from "../../theme/material";
|
|
14
|
-
import { useTheme } from "../../theme/ThemeProvider";
|
|
15
|
+
import { useTheme, useThemeOverrides } from "../../theme/ThemeProvider";
|
|
15
16
|
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
16
17
|
import { Text, textStyle } from "../Text/Text";
|
|
17
18
|
const TabBarContext = createContext(null);
|
|
@@ -381,6 +382,12 @@ function TabBarRoot({ value: valueProp, defaultValue, onValueChange, search, pro
|
|
|
381
382
|
slidingPill: pillFrame ? value : undefined,
|
|
382
383
|
};
|
|
383
384
|
const pillOutset = theme.length("--tab-bar-pill-outset", 6);
|
|
385
|
+
// The web's selected pill in the dark is a shade of the glass, deeper at its top and lifting toward its bottom, as
|
|
386
|
+
// iOS 26 draws it; a brand that sets the pill's token keeps its color
|
|
387
|
+
const overrides = useThemeOverrides();
|
|
388
|
+
const webPill = theme.scheme === "dark" && overrides?.["--tab-bar-item-background-selected"] == null
|
|
389
|
+
? { backgroundColor: "transparent", backgroundImage: "linear-gradient(to bottom, rgb(0 0 0 / 22%), rgb(255 255 255 / 8%))" }
|
|
390
|
+
: { backgroundColor: theme.color("--tab-bar-item-background-selected") };
|
|
384
391
|
const [pillX] = useState(() => new Animated.Value(0));
|
|
385
392
|
const [pillWidth] = useState(() => new Animated.Value(0));
|
|
386
393
|
const pillShown = useRef(false);
|
|
@@ -392,6 +399,9 @@ function TabBarRoot({ value: valueProp, defaultValue, onValueChange, search, pro
|
|
|
392
399
|
pillShown.current = false;
|
|
393
400
|
return;
|
|
394
401
|
}
|
|
402
|
+
// The web's pill slides in CSS
|
|
403
|
+
if (Platform.OS === "web")
|
|
404
|
+
return;
|
|
395
405
|
// It appears in place (the first frame, back from a minimized bar or the circle's tab), then slides: CSS `ease`
|
|
396
406
|
// over 300ms, as SegmentedControl's thumb
|
|
397
407
|
if (!pillShown.current || theme.reducedMotion) {
|
|
@@ -437,7 +447,10 @@ function TabBarRoot({ value: valueProp, defaultValue, onValueChange, search, pro
|
|
|
437
447
|
{ paddingTop: padTop + (accessory ? accessoryHeight + accessoryGap : 0), paddingBottom },
|
|
438
448
|
physicalPadding(sideLeft, sideRight),
|
|
439
449
|
style,
|
|
440
|
-
], children: [backdrop, accessory ? (_jsx(Glass, { radius: accessoryHeight / 2, elevation: "raised", style: [styles.accessory, accessoryPlace], children: accessory }, "accessory")) : null, _jsxs(View, { style: [styles.iosRow, { gap: theme.length("--tab-bar-gap", 8), justifyContent: circle || minimized ? "space-between" : "center" }], children: [_jsxs(Glass, { radius: 999, elevation: "raised", style: [styles.capsule, minimized ? { padding: capsulePadding } : { paddingVertical: capsulePadding, paddingHorizontal: theme.length("--tab-bar-capsule-padding-inline", 10) }], children: [pillFrame
|
|
450
|
+
], children: [backdrop, accessory ? (_jsx(Glass, { radius: accessoryHeight / 2, elevation: "raised", style: [styles.accessory, accessoryPlace], children: accessory }, "accessory")) : null, _jsxs(View, { style: [styles.iosRow, { gap: theme.length("--tab-bar-gap", 8), justifyContent: circle || minimized ? "space-between" : "center" }], children: [_jsxs(Glass, { radius: 999, elevation: "raised", style: [styles.capsule, minimized ? { padding: capsulePadding } : { paddingVertical: capsulePadding, paddingHorizontal: theme.length("--tab-bar-capsule-padding-inline", 10) }], children: [pillFrame && Platform.OS === "web" ? (
|
|
451
|
+
// The web slides the pill in CSS, off the JavaScript thread, so a screen mounting under the new tab
|
|
452
|
+
// does not stop it
|
|
453
|
+
_jsx(CssSlide, { x: pillLeft, width: pillSpan, side: "start", duration: 300, easing: "cubic-bezier(0.25, 0.1, 0.25, 1)", still: theme.reducedMotion, style: [styles.pill, { top: pillFrame.y, height: pillFrame.height }, webPill] })) : pillFrame ? (_jsx(Animated.View, { pointerEvents: "none", style: [
|
|
441
454
|
styles.pill,
|
|
442
455
|
{ top: pillFrame.y, height: pillFrame.height, start: pillX, width: pillWidth, backgroundColor: theme.color("--tab-bar-item-background-selected") },
|
|
443
456
|
] })) : null, visible.map((tab) => (_jsx(Tab, { ...tab, context: context }, tab.value)))] }), circle ? (_jsx(Glass, { radius: circleSize / 2, elevation: "raised", style: { width: circleSize, height: circleSize }, children: _jsx(Tab, { ...circle, context: { ...context, minimized: false }, kind: "circle", hideLabel: true }) })) : null] })] }) }));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
// A fill at the start of a right-to-left row moves the other way: the CSS direction turns the sign of its offset, so
|
|
4
|
+
// a row whose direction changes moves it over at once, as it moves `start`
|
|
5
|
+
const RULE = "[data-plex-slide=start]:dir(rtl){--plex-slide-sign:-1}";
|
|
6
|
+
let ruled = false;
|
|
7
|
+
function addRule() {
|
|
8
|
+
if (ruled)
|
|
9
|
+
return;
|
|
10
|
+
const dom = globalThis;
|
|
11
|
+
const sheet = dom.document?.createElement("style");
|
|
12
|
+
if (sheet == null || dom.document?.head == null)
|
|
13
|
+
return;
|
|
14
|
+
ruled = true;
|
|
15
|
+
sheet.textContent = RULE;
|
|
16
|
+
dom.document.head.appendChild(sheet);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The web's sliding fill (a segmented control's thumb, a tab bar's pill): its place a `translateX` and its width a CSS
|
|
20
|
+
* transition, so the browser runs the slide itself. A slide driven from JavaScript stops for a frame as long as the
|
|
21
|
+
* page's work in it (a screen mounting under the tab it slides to) and then jumps; the compositor keeps the move going.
|
|
22
|
+
* A fill that mounts stands at its place, since a transition starts from a style the browser has already drawn.
|
|
23
|
+
*/
|
|
24
|
+
export function CssSlide({ x, width, side, duration, easing, still = false, style }) {
|
|
25
|
+
if (side === "start")
|
|
26
|
+
addRule();
|
|
27
|
+
const time = still ? "0ms" : `${duration}ms`;
|
|
28
|
+
const motion = {
|
|
29
|
+
transform: side === "start" ? `translateX(calc(var(--plex-slide-sign, 1) * ${x}px))` : `translateX(${x}px)`,
|
|
30
|
+
transitionProperty: "transform, width",
|
|
31
|
+
transitionDuration: `${time}, ${time}`,
|
|
32
|
+
transitionTimingFunction: `${easing}, ${easing}`,
|
|
33
|
+
};
|
|
34
|
+
return (_jsx(View, { ...{ dataSet: { plexSlide: side } }, pointerEvents: "none", style: [style, side === "left" ? { left: 0 } : { start: 0 }, { width }, motion] }));
|
|
35
|
+
}
|
|
@@ -12,18 +12,18 @@ import { useReduceTransparency } from "./reduceTransparency";
|
|
|
12
12
|
const WEB_DENSE = {
|
|
13
13
|
"--mobile-glass-background": {
|
|
14
14
|
fill: "--mobile-glass-web-background",
|
|
15
|
-
light: "rgba(
|
|
16
|
-
dark: "rgba(
|
|
15
|
+
light: "rgba(250, 250, 252, 0.62)",
|
|
16
|
+
dark: "rgba(52, 52, 56, 0.74)",
|
|
17
17
|
filter: "--mobile-glass-web-backdrop-filter",
|
|
18
|
-
blur: "blur(
|
|
18
|
+
blur: "blur(8px) saturate(180%)",
|
|
19
19
|
},
|
|
20
20
|
// Pressed, a step deeper, as the shared tokens step from 55% to 75%
|
|
21
21
|
"--mobile-glass-background-active": {
|
|
22
22
|
fill: "--mobile-glass-web-background-active",
|
|
23
|
-
light: "rgba(
|
|
24
|
-
dark: "rgba(
|
|
23
|
+
light: "rgba(238, 238, 242, 0.8)",
|
|
24
|
+
dark: "rgba(72, 72, 76, 0.84)",
|
|
25
25
|
filter: "--mobile-glass-web-backdrop-filter",
|
|
26
|
-
blur: "blur(
|
|
26
|
+
blur: "blur(8px) saturate(180%)",
|
|
27
27
|
},
|
|
28
28
|
"--menu-mobile-background": {
|
|
29
29
|
fill: "--menu-mobile-web-background",
|
|
@@ -33,6 +33,29 @@ const WEB_DENSE = {
|
|
|
33
33
|
blur: "blur(30px)",
|
|
34
34
|
},
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* The web's plain glass drawn as iOS 26's Liquid Glass reads (measured on its tab bars and bar buttons): a lighter fill
|
|
38
|
+
* than a tint of white in the dark, a sheen down the glass (a shade under its top edge in the light, a lift toward its
|
|
39
|
+
* bottom in the dark), a bright rim on every side, and a lens at the edge, where what is under the glass is blurred and
|
|
40
|
+
* lit more, as Liquid Glass bends it there (a browser cannot bend it). Each part a token a theme may set.
|
|
41
|
+
*/
|
|
42
|
+
const WEB_LIQUID = {
|
|
43
|
+
sheen: { token: "--mobile-glass-web-sheen", light: "linear-gradient(to bottom, rgb(0 0 0 / 3.5%), rgb(0 0 0 / 0) 35%)", dark: "linear-gradient(to bottom, rgb(255 255 255 / 0), rgb(255 255 255 / 5%))" },
|
|
44
|
+
shadow: {
|
|
45
|
+
token: "--mobile-glass-web-shadow",
|
|
46
|
+
light: "0 8px 24px rgb(0 0 0 / 6%), 0 0 0 0.5px rgb(0 0 0 / 12%), inset 0 1px 0 rgb(255 255 255), inset 0 -1px 0 rgb(255 255 255 / 90%), inset 1px 0 0 rgb(255 255 255 / 70%), inset -1px 0 0 rgb(255 255 255 / 70%)",
|
|
47
|
+
dark: "0 8px 24px rgb(0 0 0 / 25%), inset 0 1px 0 rgb(255 255 255 / 36%), inset 0 -1px 0 rgb(255 255 255 / 20%), inset 1px 0 0 rgb(255 255 255 / 12%), inset -1px 0 0 rgb(255 255 255 / 12%)",
|
|
48
|
+
},
|
|
49
|
+
shadowRaised: {
|
|
50
|
+
token: "--mobile-glass-web-shadow-raised",
|
|
51
|
+
light: "0 8px 40px rgb(0 0 0 / 12%), 0 0 0 0.5px rgb(0 0 0 / 12%), inset 0 1px 0 rgb(255 255 255), inset 0 -1px 0 rgb(255 255 255 / 90%), inset 1px 0 0 rgb(255 255 255 / 70%), inset -1px 0 0 rgb(255 255 255 / 70%)",
|
|
52
|
+
dark: "0 8px 40px rgb(0 0 0 / 30%), inset 0 1px 0 rgb(255 255 255 / 36%), inset 0 -1px 0 rgb(255 255 255 / 20%), inset 1px 0 0 rgb(255 255 255 / 12%), inset -1px 0 0 rgb(255 255 255 / 12%)",
|
|
53
|
+
},
|
|
54
|
+
lens: { token: "--mobile-glass-web-lens-filter", value: "blur(3px) brightness(1.12) saturate(200%)" },
|
|
55
|
+
};
|
|
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%)`;
|
|
36
59
|
/** The filter and the shadow of the glass surfaces of the phone layer, by their fill (mobile-materials.css, touch.css). */
|
|
37
60
|
const SURFACES = {
|
|
38
61
|
"--menu-mobile-background": { filter: "--menu-mobile-backdrop-filter", shadow: "--menu-shadow" },
|
|
@@ -81,8 +104,31 @@ export function Glass({ radius = 0, elevation = "regular", tint, interactive, fi
|
|
|
81
104
|
const module = web || Platform.OS !== "ios" ? null : blurModule();
|
|
82
105
|
const opaque = reduceTransparency || (!web && module == null);
|
|
83
106
|
if (web && !opaque) {
|
|
107
|
+
// The plain glass (bars, bar buttons, the tab bar, the large segmented control) reads as Liquid Glass; menus,
|
|
108
|
+
// toasts and alerts keep their frosted panels
|
|
109
|
+
const liquid = !theme.isAndroid && (fillName === "--mobile-glass-background" || fillName === "--mobile-glass-background-active" || plainFilter);
|
|
110
|
+
const scheme = theme.scheme === "dark" ? "dark" : "light";
|
|
111
|
+
const own = (part) => {
|
|
112
|
+
const value = theme.token(part.token);
|
|
113
|
+
return typeof value === "string" ? value : part[scheme];
|
|
114
|
+
};
|
|
115
|
+
const ownShadow = shadowToken == null && surface == null && overrides?.["--mobile-glass-shadow"] == null && overrides?.["--mobile-glass-shadow-raised"] == null;
|
|
116
|
+
const liquidShadow = liquid && ownShadow ? own(elevation === "raised" ? WEB_LIQUID.shadowRaised : WEB_LIQUID.shadow) : boxShadow;
|
|
117
|
+
const sheen = liquid && tint == null ? own(WEB_LIQUID.sheen) : undefined;
|
|
118
|
+
const lensToken = theme.token(WEB_LIQUID.lens.token);
|
|
119
|
+
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));
|
|
84
121
|
// An Animated.View, so a panel can move its own glass (a transform above the blur would stop it)
|
|
85
|
-
return (
|
|
122
|
+
return (_jsxs(Animated.View, { ...rest, style: [
|
|
123
|
+
shape,
|
|
124
|
+
{ backgroundColor: fill, boxShadow: liquidShadow },
|
|
125
|
+
{ backdropFilter: filter, WebkitBackdropFilter: filter, backgroundImage: sheen },
|
|
126
|
+
style,
|
|
127
|
+
], children: [liquid && lensFilter !== "none" ? (_jsx(View, { pointerEvents: "none", "aria-hidden": true, style: [
|
|
128
|
+
StyleSheet.absoluteFill,
|
|
129
|
+
shape,
|
|
130
|
+
{ backdropFilter: lensFilter, WebkitBackdropFilter: lensFilter, maskImage: mask, WebkitMaskImage: mask },
|
|
131
|
+
] })) : null, children] }));
|
|
86
132
|
}
|
|
87
133
|
const radiusPx = Number(/blur\(\s*([\d.]+)px\s*\)/.exec(filter)?.[1] ?? 12);
|
|
88
134
|
return (_jsxs(View, { ...rest, style: [shape, { boxShadow }, style], children: [_jsxs(View, { style: [StyleSheet.absoluteFill, shape, { overflow: "hidden" }], pointerEvents: "none", children: [opaque ? (_jsx(View, { style: [StyleSheet.absoluteFill, { backgroundColor: theme.color("--mobile-surface-elevated-plain-primary", theme.colors.surfaceElevated) }] })) : module ? (_jsx(module.BlurView, { intensity: intensityOf(radiusPx), tint: theme.scheme === "dark" ? "systemChromeMaterialDark" : "systemChromeMaterialLight", style: StyleSheet.absoluteFill })) : null, _jsx(View, { style: [StyleSheet.absoluteFill, { backgroundColor: fill }] })] }), children] }));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
2
|
+
type CssSlideProps = {
|
|
3
|
+
/** The offset from the side, in points. */
|
|
4
|
+
x: number;
|
|
5
|
+
width: number;
|
|
6
|
+
/** `left` keeps the screen's left; `start` follows the row's direction (the right in a right-to-left row). */
|
|
7
|
+
side: "left" | "start";
|
|
8
|
+
duration: number;
|
|
9
|
+
/** A CSS timing function: `cubic-bezier(…)`. */
|
|
10
|
+
easing: string;
|
|
11
|
+
/** No slide: the fill moves at once (reduced motion). */
|
|
12
|
+
still?: boolean;
|
|
13
|
+
style?: StyleProp<ViewStyle>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The web's sliding fill (a segmented control's thumb, a tab bar's pill): its place a `translateX` and its width a CSS
|
|
17
|
+
* transition, so the browser runs the slide itself. A slide driven from JavaScript stops for a frame as long as the
|
|
18
|
+
* page's work in it (a screen mounting under the tab it slides to) and then jumps; the compositor keeps the move going.
|
|
19
|
+
* A fill that mounts stands at its place, since a transition starts from a style the browser has already drawn.
|
|
20
|
+
*/
|
|
21
|
+
export declare function CssSlide({ x, width, side, duration, easing, still, style }: CssSlideProps): import("react").JSX.Element;
|
|
22
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createContext, isValidElement, useContext, useEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
|
|
2
|
-
import { Animated, Easing, StyleSheet, View, type LayoutChangeEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
2
|
+
import { Animated, Easing, Platform, StyleSheet, View, type LayoutChangeEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
3
|
import { Pressable } from "../../internal/Pressable"
|
|
4
|
+
import { CssSlide } from "../../internal/CssSlide"
|
|
4
5
|
import { childrenOfType, isRenderable, textOf } from "../../internal/children"
|
|
5
6
|
import { Glass } from "../../internal/Glass"
|
|
6
7
|
import { curves } from "../../internal/motion"
|
|
@@ -250,7 +251,8 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
250
251
|
const [width] = useState(() => new Animated.Value(0))
|
|
251
252
|
const placed = useRef(false)
|
|
252
253
|
useEffect(() => {
|
|
253
|
-
|
|
254
|
+
// The web's thumb slides in CSS
|
|
255
|
+
if (selectedX == null || selectedWidth == null || Platform.OS === "web") return
|
|
254
256
|
if (!placed.current || theme.reducedMotion) {
|
|
255
257
|
x.setValue(selectedX)
|
|
256
258
|
width.setValue(selectedWidth)
|
|
@@ -279,7 +281,18 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
279
281
|
const maxScale = look.height / look.lineHeight
|
|
280
282
|
const content = (
|
|
281
283
|
<>
|
|
282
|
-
{selected ? (
|
|
284
|
+
{selected && Platform.OS === "web" ? (
|
|
285
|
+
// The web slides the thumb in CSS, off the JavaScript thread
|
|
286
|
+
<CssSlide
|
|
287
|
+
x={selected.x}
|
|
288
|
+
width={selected.width}
|
|
289
|
+
side="left"
|
|
290
|
+
duration={look.duration}
|
|
291
|
+
easing="cubic-bezier(0.25, 0.1, 0.25, 1)"
|
|
292
|
+
still={theme.reducedMotion}
|
|
293
|
+
style={[styles.thumb, { top: look.gutter, bottom: look.gutter, borderRadius: optionRadius, backgroundColor: look.thumb }]}
|
|
294
|
+
/>
|
|
295
|
+
) : selected ? (
|
|
283
296
|
<Animated.View
|
|
284
297
|
pointerEvents="none"
|
|
285
298
|
style={[styles.thumb, { top: look.gutter, bottom: look.gutter, left: x, width, borderRadius: optionRadius, backgroundColor: look.thumb }]}
|
|
@@ -395,7 +408,7 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
|
|
|
395
408
|
const frameWidth = measured ? widths[options[index].value] : undefined
|
|
396
409
|
const frame = frameX != null
|
|
397
410
|
useEffect(() => {
|
|
398
|
-
if (frameX == null || frameWidth == null) return
|
|
411
|
+
if (frameX == null || frameWidth == null || Platform.OS === "web") return
|
|
399
412
|
if (!placed.current || theme.reducedMotion) {
|
|
400
413
|
x.setValue(frameX)
|
|
401
414
|
width.setValue(frameWidth)
|
|
@@ -413,7 +426,17 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
|
|
|
413
426
|
block ? styles.stretch : null,
|
|
414
427
|
]}
|
|
415
428
|
>
|
|
416
|
-
{frame ? (
|
|
429
|
+
{frame && Platform.OS === "web" ? (
|
|
430
|
+
<CssSlide
|
|
431
|
+
x={frameX}
|
|
432
|
+
width={frameWidth!}
|
|
433
|
+
side="left"
|
|
434
|
+
duration={ANDROID_MOVE.duration}
|
|
435
|
+
easing="cubic-bezier(0.23, 1, 0.32, 1)"
|
|
436
|
+
still={theme.reducedMotion}
|
|
437
|
+
style={[styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12) }]}
|
|
438
|
+
/>
|
|
439
|
+
) : frame ? (
|
|
417
440
|
<Animated.View
|
|
418
441
|
pointerEvents="none"
|
|
419
442
|
style={[styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12), left: x, width }]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
|
|
2
|
-
import { Animated, Easing, StyleSheet, View, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent, type StyleProp, type ViewProps, type ViewStyle } from "react-native"
|
|
2
|
+
import { Animated, Easing, Platform, StyleSheet, View, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent, type StyleProp, type ViewProps, type ViewStyle } from "react-native"
|
|
3
3
|
import { Pressable } from "../../internal/Pressable"
|
|
4
|
+
import { CssSlide } from "../../internal/CssSlide"
|
|
4
5
|
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
|
5
6
|
import Search from "../../icons/plex/Search"
|
|
6
7
|
import { BarBackdrop, SoftBottomEdge, TabBarFade, ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, glassBarBlur, useAndroidGlass } from "../../internal/BarBackdrop"
|
|
@@ -10,7 +11,7 @@ import { Glass } from "../../internal/Glass"
|
|
|
10
11
|
import { curves } from "../../internal/motion"
|
|
11
12
|
import { useTabKeys } from "../../internal/tabKeys"
|
|
12
13
|
import { barSurface, mix, stateLayer, withAlpha } from "../../theme/material"
|
|
13
|
-
import { useTheme } from "../../theme/ThemeProvider"
|
|
14
|
+
import { useTheme, useThemeOverrides } from "../../theme/ThemeProvider"
|
|
14
15
|
import type { Theme } from "../../theme/types"
|
|
15
16
|
import { IconDefaultsProvider } from "../Icon/createIcon"
|
|
16
17
|
import { Text, textStyle } from "../Text/Text"
|
|
@@ -731,6 +732,13 @@ function TabBarRoot({
|
|
|
731
732
|
slidingPill: pillFrame ? value : undefined,
|
|
732
733
|
}
|
|
733
734
|
const pillOutset = theme.length("--tab-bar-pill-outset", 6)
|
|
735
|
+
// The web's selected pill in the dark is a shade of the glass, deeper at its top and lifting toward its bottom, as
|
|
736
|
+
// iOS 26 draws it; a brand that sets the pill's token keeps its color
|
|
737
|
+
const overrides = useThemeOverrides()
|
|
738
|
+
const webPill: ViewStyle =
|
|
739
|
+
theme.scheme === "dark" && overrides?.["--tab-bar-item-background-selected"] == null
|
|
740
|
+
? ({ backgroundColor: "transparent", backgroundImage: "linear-gradient(to bottom, rgb(0 0 0 / 22%), rgb(255 255 255 / 8%))" } as ViewStyle)
|
|
741
|
+
: { backgroundColor: theme.color("--tab-bar-item-background-selected") }
|
|
734
742
|
const [pillX] = useState(() => new Animated.Value(0))
|
|
735
743
|
const [pillWidth] = useState(() => new Animated.Value(0))
|
|
736
744
|
const pillShown = useRef(false)
|
|
@@ -742,6 +750,8 @@ function TabBarRoot({
|
|
|
742
750
|
pillShown.current = false
|
|
743
751
|
return
|
|
744
752
|
}
|
|
753
|
+
// The web's pill slides in CSS
|
|
754
|
+
if (Platform.OS === "web") return
|
|
745
755
|
// It appears in place (the first frame, back from a minimized bar or the circle's tab), then slides: CSS `ease`
|
|
746
756
|
// over 300ms, as SegmentedControl's thumb
|
|
747
757
|
if (!pillShown.current || theme.reducedMotion) {
|
|
@@ -832,7 +842,19 @@ function TabBarRoot({
|
|
|
832
842
|
elevation="raised"
|
|
833
843
|
style={[styles.capsule, minimized ? { padding: capsulePadding } : { paddingVertical: capsulePadding, paddingHorizontal: theme.length("--tab-bar-capsule-padding-inline", 10) }]}
|
|
834
844
|
>
|
|
835
|
-
{pillFrame ? (
|
|
845
|
+
{pillFrame && Platform.OS === "web" ? (
|
|
846
|
+
// The web slides the pill in CSS, off the JavaScript thread, so a screen mounting under the new tab
|
|
847
|
+
// does not stop it
|
|
848
|
+
<CssSlide
|
|
849
|
+
x={pillLeft!}
|
|
850
|
+
width={pillSpan!}
|
|
851
|
+
side="start"
|
|
852
|
+
duration={300}
|
|
853
|
+
easing="cubic-bezier(0.25, 0.1, 0.25, 1)"
|
|
854
|
+
still={theme.reducedMotion}
|
|
855
|
+
style={[styles.pill, { top: pillFrame.y, height: pillFrame.height }, webPill]}
|
|
856
|
+
/>
|
|
857
|
+
) : pillFrame ? (
|
|
836
858
|
<Animated.View
|
|
837
859
|
pointerEvents="none"
|
|
838
860
|
style={[
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from "react-native"
|
|
2
|
+
import { View } from "react-native"
|
|
3
|
+
|
|
4
|
+
type CssSlideProps = {
|
|
5
|
+
/** The offset from the side, in points. */
|
|
6
|
+
x: number
|
|
7
|
+
width: number
|
|
8
|
+
/** `left` keeps the screen's left; `start` follows the row's direction (the right in a right-to-left row). */
|
|
9
|
+
side: "left" | "start"
|
|
10
|
+
duration: number
|
|
11
|
+
/** A CSS timing function: `cubic-bezier(…)`. */
|
|
12
|
+
easing: string
|
|
13
|
+
/** No slide: the fill moves at once (reduced motion). */
|
|
14
|
+
still?: boolean
|
|
15
|
+
style?: StyleProp<ViewStyle>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// A fill at the start of a right-to-left row moves the other way: the CSS direction turns the sign of its offset, so
|
|
19
|
+
// a row whose direction changes moves it over at once, as it moves `start`
|
|
20
|
+
const RULE = "[data-plex-slide=start]:dir(rtl){--plex-slide-sign:-1}"
|
|
21
|
+
let ruled = false
|
|
22
|
+
function addRule() {
|
|
23
|
+
if (ruled) return
|
|
24
|
+
const dom = globalThis as unknown as { document?: { createElement: (tag: string) => { textContent: string }; head?: { appendChild: (node: unknown) => void } } }
|
|
25
|
+
const sheet = dom.document?.createElement("style")
|
|
26
|
+
if (sheet == null || dom.document?.head == null) return
|
|
27
|
+
ruled = true
|
|
28
|
+
sheet.textContent = RULE
|
|
29
|
+
dom.document.head.appendChild(sheet)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The web's sliding fill (a segmented control's thumb, a tab bar's pill): its place a `translateX` and its width a CSS
|
|
34
|
+
* transition, so the browser runs the slide itself. A slide driven from JavaScript stops for a frame as long as the
|
|
35
|
+
* page's work in it (a screen mounting under the tab it slides to) and then jumps; the compositor keeps the move going.
|
|
36
|
+
* A fill that mounts stands at its place, since a transition starts from a style the browser has already drawn.
|
|
37
|
+
*/
|
|
38
|
+
export function CssSlide({ x, width, side, duration, easing, still = false, style }: CssSlideProps) {
|
|
39
|
+
if (side === "start") addRule()
|
|
40
|
+
const time = still ? "0ms" : `${duration}ms`
|
|
41
|
+
const motion = {
|
|
42
|
+
transform: side === "start" ? `translateX(calc(var(--plex-slide-sign, 1) * ${x}px))` : `translateX(${x}px)`,
|
|
43
|
+
transitionProperty: "transform, width",
|
|
44
|
+
transitionDuration: `${time}, ${time}`,
|
|
45
|
+
transitionTimingFunction: `${easing}, ${easing}`,
|
|
46
|
+
} as unknown as ViewStyle
|
|
47
|
+
return (
|
|
48
|
+
<View
|
|
49
|
+
{...({ dataSet: { plexSlide: side } } as object)}
|
|
50
|
+
pointerEvents="none"
|
|
51
|
+
style={[style, side === "left" ? { left: 0 } : { start: 0 }, { width }, motion]}
|
|
52
|
+
/>
|
|
53
|
+
)
|
|
54
|
+
}
|
package/src/internal/Glass.tsx
CHANGED
|
@@ -38,18 +38,18 @@ export type GlassProps = ViewProps & {
|
|
|
38
38
|
const WEB_DENSE: Record<string, { fill: string; light: string; dark: string; filter: string; blur: string }> = {
|
|
39
39
|
"--mobile-glass-background": {
|
|
40
40
|
fill: "--mobile-glass-web-background",
|
|
41
|
-
light: "rgba(
|
|
42
|
-
dark: "rgba(
|
|
41
|
+
light: "rgba(250, 250, 252, 0.62)",
|
|
42
|
+
dark: "rgba(52, 52, 56, 0.74)",
|
|
43
43
|
filter: "--mobile-glass-web-backdrop-filter",
|
|
44
|
-
blur: "blur(
|
|
44
|
+
blur: "blur(8px) saturate(180%)",
|
|
45
45
|
},
|
|
46
46
|
// Pressed, a step deeper, as the shared tokens step from 55% to 75%
|
|
47
47
|
"--mobile-glass-background-active": {
|
|
48
48
|
fill: "--mobile-glass-web-background-active",
|
|
49
|
-
light: "rgba(
|
|
50
|
-
dark: "rgba(
|
|
49
|
+
light: "rgba(238, 238, 242, 0.8)",
|
|
50
|
+
dark: "rgba(72, 72, 76, 0.84)",
|
|
51
51
|
filter: "--mobile-glass-web-backdrop-filter",
|
|
52
|
-
blur: "blur(
|
|
52
|
+
blur: "blur(8px) saturate(180%)",
|
|
53
53
|
},
|
|
54
54
|
"--menu-mobile-background": {
|
|
55
55
|
fill: "--menu-mobile-web-background",
|
|
@@ -60,6 +60,34 @@ const WEB_DENSE: Record<string, { fill: string; light: string; dark: string; fil
|
|
|
60
60
|
},
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The web's plain glass drawn as iOS 26's Liquid Glass reads (measured on its tab bars and bar buttons): a lighter fill
|
|
65
|
+
* than a tint of white in the dark, a sheen down the glass (a shade under its top edge in the light, a lift toward its
|
|
66
|
+
* bottom in the dark), a bright rim on every side, and a lens at the edge, where what is under the glass is blurred and
|
|
67
|
+
* lit more, as Liquid Glass bends it there (a browser cannot bend it). Each part a token a theme may set.
|
|
68
|
+
*/
|
|
69
|
+
const WEB_LIQUID = {
|
|
70
|
+
sheen: { token: "--mobile-glass-web-sheen", light: "linear-gradient(to bottom, rgb(0 0 0 / 3.5%), rgb(0 0 0 / 0) 35%)", dark: "linear-gradient(to bottom, rgb(255 255 255 / 0), rgb(255 255 255 / 5%))" },
|
|
71
|
+
shadow: {
|
|
72
|
+
token: "--mobile-glass-web-shadow",
|
|
73
|
+
light:
|
|
74
|
+
"0 8px 24px rgb(0 0 0 / 6%), 0 0 0 0.5px rgb(0 0 0 / 12%), inset 0 1px 0 rgb(255 255 255), inset 0 -1px 0 rgb(255 255 255 / 90%), inset 1px 0 0 rgb(255 255 255 / 70%), inset -1px 0 0 rgb(255 255 255 / 70%)",
|
|
75
|
+
dark: "0 8px 24px rgb(0 0 0 / 25%), inset 0 1px 0 rgb(255 255 255 / 36%), inset 0 -1px 0 rgb(255 255 255 / 20%), inset 1px 0 0 rgb(255 255 255 / 12%), inset -1px 0 0 rgb(255 255 255 / 12%)",
|
|
76
|
+
},
|
|
77
|
+
shadowRaised: {
|
|
78
|
+
token: "--mobile-glass-web-shadow-raised",
|
|
79
|
+
light:
|
|
80
|
+
"0 8px 40px rgb(0 0 0 / 12%), 0 0 0 0.5px rgb(0 0 0 / 12%), inset 0 1px 0 rgb(255 255 255), inset 0 -1px 0 rgb(255 255 255 / 90%), inset 1px 0 0 rgb(255 255 255 / 70%), inset -1px 0 0 rgb(255 255 255 / 70%)",
|
|
81
|
+
dark: "0 8px 40px rgb(0 0 0 / 30%), inset 0 1px 0 rgb(255 255 255 / 36%), inset 0 -1px 0 rgb(255 255 255 / 20%), inset 1px 0 0 rgb(255 255 255 / 12%), inset -1px 0 0 rgb(255 255 255 / 12%)",
|
|
82
|
+
},
|
|
83
|
+
lens: { token: "--mobile-glass-web-lens-filter", value: "blur(3px) brightness(1.12) saturate(200%)" },
|
|
84
|
+
}
|
|
85
|
+
|
|
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%)`
|
|
90
|
+
|
|
63
91
|
/** The filter and the shadow of the glass surfaces of the phone layer, by their fill (mobile-materials.css, touch.css). */
|
|
64
92
|
const SURFACES: Record<string, { filter: string; shadow: string }> = {
|
|
65
93
|
"--menu-mobile-background": { filter: "--menu-mobile-backdrop-filter", shadow: "--menu-shadow" },
|
|
@@ -133,12 +161,42 @@ export function Glass({
|
|
|
133
161
|
const module = web || Platform.OS !== "ios" ? null : blurModule()
|
|
134
162
|
const opaque = reduceTransparency || (!web && module == null)
|
|
135
163
|
if (web && !opaque) {
|
|
164
|
+
// The plain glass (bars, bar buttons, the tab bar, the large segmented control) reads as Liquid Glass; menus,
|
|
165
|
+
// toasts and alerts keep their frosted panels
|
|
166
|
+
const liquid = !theme.isAndroid && (fillName === "--mobile-glass-background" || fillName === "--mobile-glass-background-active" || plainFilter)
|
|
167
|
+
const scheme = theme.scheme === "dark" ? "dark" : "light"
|
|
168
|
+
const own = (part: { token: string; light: string; dark: string }) => {
|
|
169
|
+
const value = theme.token(part.token)
|
|
170
|
+
return typeof value === "string" ? value : part[scheme]
|
|
171
|
+
}
|
|
172
|
+
const ownShadow = shadowToken == null && surface == null && overrides?.["--mobile-glass-shadow"] == null && overrides?.["--mobile-glass-shadow-raised"] == null
|
|
173
|
+
const liquidShadow = liquid && ownShadow ? own(elevation === "raised" ? WEB_LIQUID.shadowRaised : WEB_LIQUID.shadow) : boxShadow
|
|
174
|
+
const sheen = liquid && tint == null ? own(WEB_LIQUID.sheen) : undefined
|
|
175
|
+
const lensToken = theme.token(WEB_LIQUID.lens.token)
|
|
176
|
+
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))
|
|
136
178
|
// An Animated.View, so a panel can move its own glass (a transform above the blur would stop it)
|
|
137
179
|
return (
|
|
138
180
|
<Animated.View
|
|
139
181
|
{...rest}
|
|
140
|
-
style={[
|
|
182
|
+
style={[
|
|
183
|
+
shape,
|
|
184
|
+
{ backgroundColor: fill, boxShadow: liquidShadow },
|
|
185
|
+
{ backdropFilter: filter, WebkitBackdropFilter: filter, backgroundImage: sheen } as ViewStyle,
|
|
186
|
+
style,
|
|
187
|
+
]}
|
|
141
188
|
>
|
|
189
|
+
{liquid && lensFilter !== "none" ? (
|
|
190
|
+
<View
|
|
191
|
+
pointerEvents="none"
|
|
192
|
+
aria-hidden
|
|
193
|
+
style={[
|
|
194
|
+
StyleSheet.absoluteFill,
|
|
195
|
+
shape,
|
|
196
|
+
{ backdropFilter: lensFilter, WebkitBackdropFilter: lensFilter, maskImage: mask, WebkitMaskImage: mask } as ViewStyle,
|
|
197
|
+
]}
|
|
198
|
+
/>
|
|
199
|
+
) : null}
|
|
142
200
|
{children}
|
|
143
201
|
</Animated.View>
|
|
144
202
|
)
|