@plexui/react-native 0.2.13 → 0.2.15
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/ScrollEdge/ScrollEdge.js +8 -3
- package/dist/es/components/SegmentedControl/SegmentedControl.js +4 -4
- package/dist/es/components/Text/Text.js +2 -4
- package/dist/es/internal/Glass.js +40 -4
- package/dist/es/theme/ThemeProvider.js +12 -5
- package/dist/types/theme/ThemeProvider.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/ScrollEdge/ScrollEdge.tsx +9 -3
- package/src/components/SegmentedControl/SegmentedControl.tsx +4 -5
- package/src/components/Text/Text.tsx +2 -4
- package/src/internal/Glass.tsx +41 -4
- package/src/theme/ThemeProvider.tsx +14 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Platform, View } from "react-native";
|
|
2
|
+
import { Platform, StyleSheet, View } from "react-native";
|
|
3
3
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
4
4
|
import { SoftBottomVeil, SoftTopEdge } from "../../internal/BarBackdrop";
|
|
5
5
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
@@ -22,6 +22,11 @@ export function ScrollEdge({ edge = "top", scrolled = false, canvasColor, testID
|
|
|
22
22
|
return null;
|
|
23
23
|
return (_jsx(View, { pointerEvents: "none", testID: testID, style: [{ position: "absolute", top: 0, left: 0, right: 0, height: insets.top }, style], children: _jsx(SoftTopEdge, { fill: canvas, blur: Platform.OS === "web" ? 6 : 0 }) }));
|
|
24
24
|
}
|
|
25
|
-
// The safe area at that edge
|
|
26
|
-
|
|
25
|
+
// The safe area at that edge, or the height the style gives the top edge (a bar's row of buttons under the status
|
|
26
|
+
// bar): the content is blurred in full down to it, and the veil and the blur ease out over the 34 past it
|
|
27
|
+
const height = StyleSheet.flatten(style)?.height;
|
|
28
|
+
const reach = top && typeof height === "number" ? height + FULL_BLUR_SHORTFALL : insets.top;
|
|
29
|
+
return (_jsx(View, { pointerEvents: "none", testID: testID, style: [{ position: "absolute", left: 0, right: 0 }, top ? { top: 0, height: insets.top } : { bottom: 0, height: insets.bottom }, style], children: top ? _jsx(SoftBottomVeil, { fill: canvas, bottom: reach }) : _jsx(SoftBottomVeil, { fill: canvas, top: 0 }) }));
|
|
27
30
|
}
|
|
31
|
+
/** The veil's blur is full 6 short of the edge it is turned over at (12 to 40 into its 34): a given height adds them. */
|
|
32
|
+
const FULL_BLUR_SHORTFALL = 6;
|
|
@@ -102,8 +102,9 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
102
102
|
// A drawn count ends a label in a capsule of its own: the thumb keeps 10 beside the label and the capsule, so the
|
|
103
103
|
// capsule does not touch the thumb's end
|
|
104
104
|
const gutter = showBadges && options.some((option) => option.badge != null) ? Math.max(look.optionGutter, 10) : look.optionGutter;
|
|
105
|
-
// The large glass control held down
|
|
106
|
-
//
|
|
105
|
+
// The large glass control held down: the held label fades to 20%, as UISegmentedControl dims a segment under the
|
|
106
|
+
// finger; the capsule stays as it is, no growth and no whitening (owner 25.11: the control must not swell and snap
|
|
107
|
+
// back on a tap)
|
|
107
108
|
const largeGlass = look.glass && look.height >= 40;
|
|
108
109
|
const [held, setHeld] = useState(null);
|
|
109
110
|
// The thumb's place from the segments in their order, so a reorder moves it even when no box changes size
|
|
@@ -164,7 +165,7 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
164
165
|
})] }));
|
|
165
166
|
if (look.glass) {
|
|
166
167
|
// The glass keeps the control's fill over it: one flat layer, no sheen (touch.css)
|
|
167
|
-
return (_jsxs(Glass, { radius: look.height / 2, fillToken: look.height >= 40 ? "--segmented-control-mobile-glass-background" : undefined,
|
|
168
|
+
return (_jsxs(Glass, { radius: look.height / 2, fillToken: look.height >= 40 ? "--segmented-control-mobile-glass-background" : undefined, style: [track, block ? styles.stretch : null], children: [look.height < 40 && look.fill ? _jsx(View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { borderRadius: look.height / 2, backgroundColor: look.fill }] }) : null, content] }));
|
|
168
169
|
}
|
|
169
170
|
return _jsx(View, { style: [track, { backgroundColor: look.fill }, block ? styles.stretch : null], children: content });
|
|
170
171
|
}
|
|
@@ -284,7 +285,6 @@ const styles = StyleSheet.create({
|
|
|
284
285
|
grow: { flex: 1 },
|
|
285
286
|
// The control is in a column: it fills the width and keeps its own height
|
|
286
287
|
stretch: { alignSelf: "stretch" },
|
|
287
|
-
heldControl: { transform: [{ scale: 1.07 }] },
|
|
288
288
|
heldLabel: { opacity: 0.2 },
|
|
289
289
|
// 18 tall, taller with a larger text size: the capsule grows round its digits
|
|
290
290
|
count: { minWidth: 18, minHeight: 18, paddingHorizontal: 5, borderRadius: 999, alignItems: "center", justifyContent: "center" },
|
|
@@ -73,10 +73,8 @@ function trackingFor(theme, style, mono) {
|
|
|
73
73
|
// On the web, Chromium and Firefox on a Mac draw text with subpixel smoothing, 11–20% heavier than an iPhone draws the
|
|
74
74
|
// same words; grayscale smoothing draws them within 1–2% of it
|
|
75
75
|
const WEB_SMOOTHING = (Platform.OS === "web" ? { WebkitFontSmoothing: "antialiased", MozOsxFontSmoothing: "grayscale" } : {});
|
|
76
|
-
// A mono face's weights:
|
|
77
|
-
const weightNumber = (weight) => (
|
|
78
|
-
? { regular: "400", medium: "500", semibold: "590", bold: "700" }
|
|
79
|
-
: { regular: "400", medium: "500", semibold: "600", bold: "700" })[weight];
|
|
76
|
+
// A mono face's weights: a browser draws a weight its face lacks (510, 590) as a synthesized bold, so the named ones
|
|
77
|
+
const weightNumber = (weight) => ({ regular: "400", medium: "500", semibold: "600", bold: "700" }[weight]);
|
|
80
78
|
/**
|
|
81
79
|
* Text in the faces, sizes and colors of Plex UI. `variant` takes the platform's text styles (Body 17 on iOS, Body
|
|
82
80
|
* Large 16 on Android); `size` the Plex UI scale. The tracking is the kit's Inter tracking at the size.
|
|
@@ -1,8 +1,38 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Animated, Platform, StyleSheet, View } from "react-native";
|
|
3
|
-
import { useTheme } from "../theme/ThemeProvider";
|
|
3
|
+
import { useTheme, useThemeOverrides } from "../theme/ThemeProvider";
|
|
4
4
|
import { blurModule, liquidGlassModule } from "./optional";
|
|
5
5
|
import { useReduceTransparency } from "./reduceTransparency";
|
|
6
|
+
/**
|
|
7
|
+
* In a browser the glass is a fill over a CSS blur, which shows far more of what is under it than iOS's own: a menu is
|
|
8
|
+
* almost opaque there, and a chip's label must read over any photo. So on the web the plain glass and the menu take
|
|
9
|
+
* these denser fills and blurs (each a token a theme may set; the shared web tokens stay as they are). A brand that
|
|
10
|
+
* sets the shared token itself keeps it.
|
|
11
|
+
*/
|
|
12
|
+
const WEB_DENSE = {
|
|
13
|
+
"--mobile-glass-background": {
|
|
14
|
+
fill: "--mobile-glass-web-background",
|
|
15
|
+
light: "rgba(243, 243, 243, 0.8)",
|
|
16
|
+
dark: "rgba(28, 28, 30, 0.7)",
|
|
17
|
+
filter: "--mobile-glass-web-backdrop-filter",
|
|
18
|
+
blur: "blur(20px)",
|
|
19
|
+
},
|
|
20
|
+
// Pressed, a step deeper, as the shared tokens step from 55% to 75%
|
|
21
|
+
"--mobile-glass-background-active": {
|
|
22
|
+
fill: "--mobile-glass-web-background-active",
|
|
23
|
+
light: "rgba(232, 232, 232, 0.9)",
|
|
24
|
+
dark: "rgba(58, 58, 60, 0.8)",
|
|
25
|
+
filter: "--mobile-glass-web-backdrop-filter",
|
|
26
|
+
blur: "blur(20px)",
|
|
27
|
+
},
|
|
28
|
+
"--menu-mobile-background": {
|
|
29
|
+
fill: "--menu-mobile-web-background",
|
|
30
|
+
light: "rgba(255, 255, 255, 0.9)",
|
|
31
|
+
dark: "rgba(28, 28, 30, 0.9)",
|
|
32
|
+
filter: "--menu-mobile-web-backdrop-filter",
|
|
33
|
+
blur: "blur(30px)",
|
|
34
|
+
},
|
|
35
|
+
};
|
|
6
36
|
/** The filter and the shadow of the glass surfaces of the phone layer, by their fill (mobile-materials.css, touch.css). */
|
|
7
37
|
const SURFACES = {
|
|
8
38
|
"--menu-mobile-background": { filter: "--menu-mobile-backdrop-filter", shadow: "--menu-shadow" },
|
|
@@ -24,6 +54,7 @@ const intensityOf = (radius) => Math.max(0, Math.min(100, Math.round(radius * 5)
|
|
|
24
54
|
export function Glass({ radius = 0, elevation = "regular", tint, interactive, fillToken, filterToken, shadowToken, blur, style, children, ...rest }) {
|
|
25
55
|
const theme = useTheme();
|
|
26
56
|
const reduceTransparency = useReduceTransparency();
|
|
57
|
+
const overrides = useThemeOverrides();
|
|
27
58
|
const shape = { borderRadius: radius, borderCurve: "continuous" };
|
|
28
59
|
const surface = fillToken ? SURFACES[fillToken] : undefined;
|
|
29
60
|
const shadow = theme.token(shadowToken ?? surface?.shadow ?? (elevation === "raised" ? "--mobile-glass-shadow-raised" : "--mobile-glass-shadow"));
|
|
@@ -34,10 +65,15 @@ export function Glass({ radius = 0, elevation = "regular", tint, interactive, fi
|
|
|
34
65
|
const { GlassView } = native;
|
|
35
66
|
return (_jsx(GlassView, { ...rest, glassEffectStyle: "regular", colorScheme: theme.scheme, tintColor: tint, isInteractive: interactive, style: [shape, style], children: children }));
|
|
36
67
|
}
|
|
37
|
-
const fill = tint ?? theme.color(fillToken ?? "--mobile-glass-background");
|
|
38
|
-
const filterValue = theme.token(filterToken ?? surface?.filter ?? "--mobile-glass-backdrop-filter");
|
|
39
|
-
const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : "blur(12px)";
|
|
40
68
|
const web = Platform.OS === "web";
|
|
69
|
+
const fillName = fillToken ?? "--mobile-glass-background";
|
|
70
|
+
const filterName = filterToken ?? surface?.filter ?? "--mobile-glass-backdrop-filter";
|
|
71
|
+
const dense = web && !theme.isAndroid ? WEB_DENSE[fillName] : undefined;
|
|
72
|
+
const denseFill = dense != null && tint == null && overrides?.[fillName] == null;
|
|
73
|
+
const denseFilter = dense != null && filterToken == null && overrides?.[filterName] == null;
|
|
74
|
+
const fill = tint ?? (denseFill ? theme.color(dense.fill, theme.scheme === "dark" ? dense.dark : dense.light) : theme.color(fillName));
|
|
75
|
+
const filterValue = denseFilter ? (theme.token(dense.filter) ?? dense.blur) : theme.token(filterName);
|
|
76
|
+
const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : "blur(12px)";
|
|
41
77
|
const module = web || Platform.OS !== "ios" ? null : blurModule();
|
|
42
78
|
const opaque = reduceTransparency || (!web && module == null);
|
|
43
79
|
if (web && !opaque) {
|
|
@@ -35,9 +35,12 @@ const ThemeSettingsContext = createContext(null);
|
|
|
35
35
|
const WEIGHTS = Platform.OS === "web"
|
|
36
36
|
? { regular: "400", medium: "510", semibold: "590", bold: "700" }
|
|
37
37
|
: { regular: "400", medium: "500", semibold: "600", bold: "700" };
|
|
38
|
-
// The web's system font (react-native-web's own stack,
|
|
39
|
-
//
|
|
40
|
-
|
|
38
|
+
// The web's system font (react-native-web's own stack, or a family that names the system's: -apple-system, system-ui):
|
|
39
|
+
// a browser has only its 500 and 600 there and draws 510 and 590 as a synthesized bold (Chromium, Safari on an iPhone:
|
|
40
|
+
// 590 heavier than 700), so Medium is 500 and Semibold 600
|
|
41
|
+
const SYSTEM_WEIGHTS = Platform.OS === "web" ? { ...WEIGHTS, medium: "500", semibold: "600" } : WEIGHTS;
|
|
42
|
+
/** Whether a font family starts with the system's face (`-apple-system, system-ui, sans-serif`), not an app's own. */
|
|
43
|
+
const isSystemFamily = (family) => /^\s*["']?(-apple-system|system-ui|BlinkMacSystemFont|ui-sans-serif|SF Pro|sans-serif)\b/i.test(family);
|
|
41
44
|
/** The platform a ThemeProvider draws by default. */
|
|
42
45
|
export function defaultPlatform() {
|
|
43
46
|
return Platform.OS === "android" ? "android" : "ios";
|
|
@@ -93,12 +96,12 @@ function warnUnresolvedColors(brand, resolver) {
|
|
|
93
96
|
function fontFor(fonts, weight) {
|
|
94
97
|
const sans = fonts?.sans;
|
|
95
98
|
if (typeof sans === "string")
|
|
96
|
-
return { fontFamily: sans, fontWeight: WEIGHTS[weight] };
|
|
99
|
+
return { fontFamily: sans, fontWeight: (isSystemFamily(sans) ? SYSTEM_WEIGHTS : WEIGHTS)[weight] };
|
|
97
100
|
const family = sans?.[weight] ?? (weight === "semibold" ? sans?.bold : undefined) ?? sans?.regular;
|
|
98
101
|
// A family per weight carries its weight: a weight on top would be synthesized on Android
|
|
99
102
|
if (family && sans?.[weight])
|
|
100
103
|
return { fontFamily: family };
|
|
101
|
-
return family ? { fontFamily: family, fontWeight: WEIGHTS[weight] } : { fontWeight: SYSTEM_WEIGHTS[weight] };
|
|
104
|
+
return family ? { fontFamily: family, fontWeight: (isSystemFamily(family) ? SYSTEM_WEIGHTS : WEIGHTS)[weight] } : { fontWeight: SYSTEM_WEIGHTS[weight] };
|
|
102
105
|
}
|
|
103
106
|
/** Builds a theme for a scheme and a platform (ThemeProvider does it for its children). */
|
|
104
107
|
export function createTheme(options) {
|
|
@@ -241,6 +244,10 @@ function defaultTheme() {
|
|
|
241
244
|
return fallbackTheme;
|
|
242
245
|
}
|
|
243
246
|
/** The theme of the nearest ThemeProvider (the light default of the device's platform without one). */
|
|
247
|
+
/** The tokens the brands of the providers around set (internal: a default that must yield to a brand's own). */
|
|
248
|
+
export function useThemeOverrides() {
|
|
249
|
+
return useContext(ThemeSettingsContext)?.overrides;
|
|
250
|
+
}
|
|
244
251
|
export function useTheme() {
|
|
245
252
|
return useContext(ThemeContext) ?? defaultTheme();
|
|
246
253
|
}
|
|
@@ -77,4 +77,6 @@ export declare function createTheme(options: {
|
|
|
77
77
|
*/
|
|
78
78
|
export declare function ThemeProvider({ scheme, platform, selectionColor, brand, fonts: fontsProp, viewportWidth, children }: ThemeProviderProps): import("react").JSX.Element;
|
|
79
79
|
/** The theme of the nearest ThemeProvider (the light default of the device's platform without one). */
|
|
80
|
+
/** The tokens the brands of the providers around set (internal: a default that must yield to a brand's own). */
|
|
81
|
+
export declare function useThemeOverrides(): Readonly<Record<string, string>> | undefined;
|
|
80
82
|
export declare function useTheme(): Theme;
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Platform, View, type StyleProp, type ViewStyle } from "react-native"
|
|
1
|
+
import { Platform, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
2
2
|
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
|
3
3
|
import { SoftBottomVeil, SoftTopEdge } from "../../internal/BarBackdrop"
|
|
4
4
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
@@ -35,14 +35,20 @@ export function ScrollEdge({ edge = "top", scrolled = false, canvasColor, testID
|
|
|
35
35
|
</View>
|
|
36
36
|
)
|
|
37
37
|
}
|
|
38
|
-
// The safe area at that edge
|
|
38
|
+
// The safe area at that edge, or the height the style gives the top edge (a bar's row of buttons under the status
|
|
39
|
+
// bar): the content is blurred in full down to it, and the veil and the blur ease out over the 34 past it
|
|
40
|
+
const height = StyleSheet.flatten(style)?.height
|
|
41
|
+
const reach = top && typeof height === "number" ? height + FULL_BLUR_SHORTFALL : insets.top
|
|
39
42
|
return (
|
|
40
43
|
<View
|
|
41
44
|
pointerEvents="none"
|
|
42
45
|
testID={testID}
|
|
43
46
|
style={[{ position: "absolute", left: 0, right: 0 }, top ? { top: 0, height: insets.top } : { bottom: 0, height: insets.bottom }, style]}
|
|
44
47
|
>
|
|
45
|
-
{top ? <SoftBottomVeil fill={canvas} bottom={
|
|
48
|
+
{top ? <SoftBottomVeil fill={canvas} bottom={reach} /> : <SoftBottomVeil fill={canvas} top={0} />}
|
|
46
49
|
</View>
|
|
47
50
|
)
|
|
48
51
|
}
|
|
52
|
+
|
|
53
|
+
/** The veil's blur is full 6 short of the edge it is turned over at (12 to 40 into its 34): a given height adds them. */
|
|
54
|
+
const FULL_BLUR_SHORTFALL = 6
|
|
@@ -225,8 +225,9 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
225
225
|
// A drawn count ends a label in a capsule of its own: the thumb keeps 10 beside the label and the capsule, so the
|
|
226
226
|
// capsule does not touch the thumb's end
|
|
227
227
|
const gutter = showBadges && options.some((option) => option.badge != null) ? Math.max(look.optionGutter, 10) : look.optionGutter
|
|
228
|
-
// The large glass control held down
|
|
229
|
-
//
|
|
228
|
+
// The large glass control held down: the held label fades to 20%, as UISegmentedControl dims a segment under the
|
|
229
|
+
// finger; the capsule stays as it is, no growth and no whitening (owner 25.11: the control must not swell and snap
|
|
230
|
+
// back on a tap)
|
|
230
231
|
const largeGlass = look.glass && look.height >= 40
|
|
231
232
|
const [held, setHeld] = useState<string | null>(null)
|
|
232
233
|
// The thumb's place from the segments in their order, so a reorder moves it even when no box changes size
|
|
@@ -338,8 +339,7 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
338
339
|
<Glass
|
|
339
340
|
radius={look.height / 2}
|
|
340
341
|
fillToken={look.height >= 40 ? "--segmented-control-mobile-glass-background" : undefined}
|
|
341
|
-
|
|
342
|
-
style={[track, block ? styles.stretch : null, largeGlass && held != null ? styles.heldControl : null]}
|
|
342
|
+
style={[track, block ? styles.stretch : null]}
|
|
343
343
|
>
|
|
344
344
|
{look.height < 40 && look.fill ? <View pointerEvents="none" style={[StyleSheet.absoluteFill, { borderRadius: look.height / 2, backgroundColor: look.fill }]} /> : null}
|
|
345
345
|
{content}
|
|
@@ -538,7 +538,6 @@ const styles = StyleSheet.create({
|
|
|
538
538
|
grow: { flex: 1 },
|
|
539
539
|
// The control is in a column: it fills the width and keeps its own height
|
|
540
540
|
stretch: { alignSelf: "stretch" },
|
|
541
|
-
heldControl: { transform: [{ scale: 1.07 }] },
|
|
542
541
|
heldLabel: { opacity: 0.2 },
|
|
543
542
|
// 18 tall, taller with a larger text size: the capsule grows round its digits
|
|
544
543
|
count: { minWidth: 18, minHeight: 18, paddingHorizontal: 5, borderRadius: 999, alignItems: "center", justifyContent: "center" },
|
|
@@ -113,11 +113,9 @@ function trackingFor(theme: Theme, style: StyleProp<TextStyle>, mono: boolean |
|
|
|
113
113
|
// same words; grayscale smoothing draws them within 1–2% of it
|
|
114
114
|
const WEB_SMOOTHING = (Platform.OS === "web" ? { WebkitFontSmoothing: "antialiased", MozOsxFontSmoothing: "grayscale" } : {}) as TextStyle
|
|
115
115
|
|
|
116
|
-
// A mono face's weights:
|
|
116
|
+
// A mono face's weights: a browser draws a weight its face lacks (510, 590) as a synthesized bold, so the named ones
|
|
117
117
|
const weightNumber = (weight: FontWeightName) =>
|
|
118
|
-
(
|
|
119
|
-
? { regular: "400", medium: "500", semibold: "590", bold: "700" } as Record<FontWeightName, string>
|
|
120
|
-
: { regular: "400", medium: "500", semibold: "600", bold: "700" })[weight] as TextStyle["fontWeight"]
|
|
118
|
+
({ regular: "400", medium: "500", semibold: "600", bold: "700" } as Record<FontWeightName, string>)[weight] as TextStyle["fontWeight"]
|
|
121
119
|
|
|
122
120
|
/**
|
|
123
121
|
* Text in the faces, sizes and colors of Plex UI. `variant` takes the platform's text styles (Body 17 on iOS, Body
|
package/src/internal/Glass.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Animated, Platform, StyleSheet, View, type StyleProp, type ViewProps, type ViewStyle } from "react-native"
|
|
2
|
-
import { useTheme } from "../theme/ThemeProvider"
|
|
2
|
+
import { useTheme, useThemeOverrides } from "../theme/ThemeProvider"
|
|
3
3
|
import { blurModule, liquidGlassModule } from "./optional"
|
|
4
4
|
import { useReduceTransparency } from "./reduceTransparency"
|
|
5
5
|
|
|
@@ -29,6 +29,37 @@ export type GlassProps = ViewProps & {
|
|
|
29
29
|
style?: StyleProp<ViewStyle>
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* In a browser the glass is a fill over a CSS blur, which shows far more of what is under it than iOS's own: a menu is
|
|
34
|
+
* almost opaque there, and a chip's label must read over any photo. So on the web the plain glass and the menu take
|
|
35
|
+
* these denser fills and blurs (each a token a theme may set; the shared web tokens stay as they are). A brand that
|
|
36
|
+
* sets the shared token itself keeps it.
|
|
37
|
+
*/
|
|
38
|
+
const WEB_DENSE: Record<string, { fill: string; light: string; dark: string; filter: string; blur: string }> = {
|
|
39
|
+
"--mobile-glass-background": {
|
|
40
|
+
fill: "--mobile-glass-web-background",
|
|
41
|
+
light: "rgba(243, 243, 243, 0.8)",
|
|
42
|
+
dark: "rgba(28, 28, 30, 0.7)",
|
|
43
|
+
filter: "--mobile-glass-web-backdrop-filter",
|
|
44
|
+
blur: "blur(20px)",
|
|
45
|
+
},
|
|
46
|
+
// Pressed, a step deeper, as the shared tokens step from 55% to 75%
|
|
47
|
+
"--mobile-glass-background-active": {
|
|
48
|
+
fill: "--mobile-glass-web-background-active",
|
|
49
|
+
light: "rgba(232, 232, 232, 0.9)",
|
|
50
|
+
dark: "rgba(58, 58, 60, 0.8)",
|
|
51
|
+
filter: "--mobile-glass-web-backdrop-filter",
|
|
52
|
+
blur: "blur(20px)",
|
|
53
|
+
},
|
|
54
|
+
"--menu-mobile-background": {
|
|
55
|
+
fill: "--menu-mobile-web-background",
|
|
56
|
+
light: "rgba(255, 255, 255, 0.9)",
|
|
57
|
+
dark: "rgba(28, 28, 30, 0.9)",
|
|
58
|
+
filter: "--menu-mobile-web-backdrop-filter",
|
|
59
|
+
blur: "blur(30px)",
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
|
|
32
63
|
/** The filter and the shadow of the glass surfaces of the phone layer, by their fill (mobile-materials.css, touch.css). */
|
|
33
64
|
const SURFACES: Record<string, { filter: string; shadow: string }> = {
|
|
34
65
|
"--menu-mobile-background": { filter: "--menu-mobile-backdrop-filter", shadow: "--menu-shadow" },
|
|
@@ -64,6 +95,7 @@ export function Glass({
|
|
|
64
95
|
}: GlassProps) {
|
|
65
96
|
const theme = useTheme()
|
|
66
97
|
const reduceTransparency = useReduceTransparency()
|
|
98
|
+
const overrides = useThemeOverrides()
|
|
67
99
|
const shape: ViewStyle = { borderRadius: radius, borderCurve: "continuous" }
|
|
68
100
|
const surface = fillToken ? SURFACES[fillToken] : undefined
|
|
69
101
|
const shadow = theme.token(shadowToken ?? surface?.shadow ?? (elevation === "raised" ? "--mobile-glass-shadow-raised" : "--mobile-glass-shadow"))
|
|
@@ -85,10 +117,15 @@ export function Glass({
|
|
|
85
117
|
</GlassView>
|
|
86
118
|
)
|
|
87
119
|
}
|
|
88
|
-
const fill = tint ?? theme.color(fillToken ?? "--mobile-glass-background")
|
|
89
|
-
const filterValue = theme.token(filterToken ?? surface?.filter ?? "--mobile-glass-backdrop-filter")
|
|
90
|
-
const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : "blur(12px)"
|
|
91
120
|
const web = Platform.OS === "web"
|
|
121
|
+
const fillName = fillToken ?? "--mobile-glass-background"
|
|
122
|
+
const filterName = filterToken ?? surface?.filter ?? "--mobile-glass-backdrop-filter"
|
|
123
|
+
const dense = web && !theme.isAndroid ? WEB_DENSE[fillName] : undefined
|
|
124
|
+
const denseFill = dense != null && tint == null && overrides?.[fillName] == null
|
|
125
|
+
const denseFilter = dense != null && filterToken == null && overrides?.[filterName] == null
|
|
126
|
+
const fill = tint ?? (denseFill ? theme.color(dense.fill, theme.scheme === "dark" ? dense.dark : dense.light) : theme.color(fillName))
|
|
127
|
+
const filterValue = denseFilter ? (theme.token(dense.filter) ?? dense.blur) : theme.token(filterName)
|
|
128
|
+
const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : "blur(12px)"
|
|
92
129
|
const module = web || Platform.OS !== "ios" ? null : blurModule()
|
|
93
130
|
const opaque = reduceTransparency || (!web && module == null)
|
|
94
131
|
if (web && !opaque) {
|
|
@@ -90,10 +90,14 @@ const WEIGHTS: Record<FontWeightName, TextStyle["fontWeight"]> =
|
|
|
90
90
|
Platform.OS === "web"
|
|
91
91
|
? { regular: "400", medium: "510" as TextStyle["fontWeight"], semibold: "590" as TextStyle["fontWeight"], bold: "700" }
|
|
92
92
|
: { regular: "400", medium: "500", semibold: "600", bold: "700" }
|
|
93
|
-
// The web's system font (react-native-web's own stack,
|
|
94
|
-
//
|
|
93
|
+
// The web's system font (react-native-web's own stack, or a family that names the system's: -apple-system, system-ui):
|
|
94
|
+
// a browser has only its 500 and 600 there and draws 510 and 590 as a synthesized bold (Chromium, Safari on an iPhone:
|
|
95
|
+
// 590 heavier than 700), so Medium is 500 and Semibold 600
|
|
95
96
|
const SYSTEM_WEIGHTS: Record<FontWeightName, TextStyle["fontWeight"]> =
|
|
96
|
-
Platform.OS === "web" ? { ...WEIGHTS, medium: "500" } : WEIGHTS
|
|
97
|
+
Platform.OS === "web" ? { ...WEIGHTS, medium: "500", semibold: "600" } : WEIGHTS
|
|
98
|
+
|
|
99
|
+
/** Whether a font family starts with the system's face (`-apple-system, system-ui, sans-serif`), not an app's own. */
|
|
100
|
+
const isSystemFamily = (family: string) => /^\s*["']?(-apple-system|system-ui|BlinkMacSystemFont|ui-sans-serif|SF Pro|sans-serif)\b/i.test(family)
|
|
97
101
|
|
|
98
102
|
/** The platform a ThemeProvider draws by default. */
|
|
99
103
|
export function defaultPlatform(): PlatformStyle {
|
|
@@ -148,11 +152,11 @@ function warnUnresolvedColors(brand: BrandTheme | undefined, resolver: TokenReso
|
|
|
148
152
|
|
|
149
153
|
function fontFor(fonts: FontFamilies | undefined, weight: FontWeightName) {
|
|
150
154
|
const sans = fonts?.sans
|
|
151
|
-
if (typeof sans === "string") return { fontFamily: sans, fontWeight: WEIGHTS[weight] }
|
|
155
|
+
if (typeof sans === "string") return { fontFamily: sans, fontWeight: (isSystemFamily(sans) ? SYSTEM_WEIGHTS : WEIGHTS)[weight] }
|
|
152
156
|
const family = sans?.[weight] ?? (weight === "semibold" ? sans?.bold : undefined) ?? sans?.regular
|
|
153
157
|
// A family per weight carries its weight: a weight on top would be synthesized on Android
|
|
154
158
|
if (family && sans?.[weight]) return { fontFamily: family }
|
|
155
|
-
return family ? { fontFamily: family, fontWeight: WEIGHTS[weight] } : { fontWeight: SYSTEM_WEIGHTS[weight] }
|
|
159
|
+
return family ? { fontFamily: family, fontWeight: (isSystemFamily(family) ? SYSTEM_WEIGHTS : WEIGHTS)[weight] } : { fontWeight: SYSTEM_WEIGHTS[weight] }
|
|
156
160
|
}
|
|
157
161
|
|
|
158
162
|
/** Builds a theme for a scheme and a platform (ThemeProvider does it for its children). */
|
|
@@ -319,6 +323,11 @@ function defaultTheme(): Theme {
|
|
|
319
323
|
}
|
|
320
324
|
|
|
321
325
|
/** The theme of the nearest ThemeProvider (the light default of the device's platform without one). */
|
|
326
|
+
/** The tokens the brands of the providers around set (internal: a default that must yield to a brand's own). */
|
|
327
|
+
export function useThemeOverrides(): Readonly<Record<string, string>> | undefined {
|
|
328
|
+
return useContext(ThemeSettingsContext)?.overrides
|
|
329
|
+
}
|
|
330
|
+
|
|
322
331
|
export function useTheme(): Theme {
|
|
323
332
|
return useContext(ThemeContext) ?? defaultTheme()
|
|
324
333
|
}
|