glacia-native 0.3.4 → 0.4.0
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/Button.js +15 -2
- package/lib/module/Card.js +29 -14
- package/lib/module/Dialog.js +43 -32
- package/lib/module/Form.js +51 -12
- package/lib/module/Glass.js +11 -2
- package/lib/module/Input.js +19 -7
- package/lib/module/SegmentedControl.js +65 -21
- package/lib/module/Slider.js +121 -25
- package/lib/module/Switch.js +33 -15
- package/lib/module/TabBar.js +63 -25
- package/lib/module/Table.js +24 -6
- package/lib/module/Tabs.js +55 -33
- package/lib/module/ai.js +49 -20
- package/lib/module/charts/BarChart.js +4 -2
- package/lib/module/charts/FunnelChart.js +4 -2
- package/lib/module/charts/HeatmapChart.js +4 -2
- package/lib/module/charts/LineChart.js +4 -2
- package/lib/module/charts/PlotChart.js +11 -3
- package/lib/module/charts/RadarChart.js +4 -2
- package/lib/module/charts/RingChart.js +4 -2
- package/lib/module/charts/ScatterChart.js +20 -3
- package/lib/module/charts/WaterfallChart.js +12 -3
- package/lib/module/charts/advanced.js +12 -6
- package/lib/module/charts/extra.js +6 -3
- package/lib/module/internal/GlassView.js +17 -19
- package/lib/module/internal/fallback.js +14 -3
- package/lib/module/internal/glass-routing.js +56 -0
- package/lib/module/internal/motion.js +55 -0
- package/lib/module/internal/primitives.js +408 -0
- package/lib/typescript/Button.d.ts +11 -1
- package/lib/typescript/Card.d.ts +20 -8
- package/lib/typescript/Dialog.d.ts +19 -6
- package/lib/typescript/Form.d.ts +27 -11
- package/lib/typescript/Glass.d.ts +9 -0
- package/lib/typescript/Input.d.ts +11 -1
- package/lib/typescript/SegmentedControl.d.ts +11 -1
- package/lib/typescript/Slider.d.ts +13 -1
- package/lib/typescript/Switch.d.ts +12 -1
- package/lib/typescript/TabBar.d.ts +13 -1
- package/lib/typescript/Table.d.ts +14 -5
- package/lib/typescript/Tabs.d.ts +8 -5
- package/lib/typescript/ai.d.ts +12 -9
- package/lib/typescript/charts/BarChart.d.ts +1 -1
- package/lib/typescript/charts/FunnelChart.d.ts +1 -1
- package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
- package/lib/typescript/charts/LineChart.d.ts +1 -1
- package/lib/typescript/charts/PlotChart.d.ts +1 -1
- package/lib/typescript/charts/RadarChart.d.ts +1 -1
- package/lib/typescript/charts/RingChart.d.ts +1 -1
- package/lib/typescript/charts/ScatterChart.d.ts +1 -1
- package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
- package/lib/typescript/charts/advanced.d.ts +5 -5
- package/lib/typescript/charts/extra.d.ts +2 -2
- package/lib/typescript/internal/GlassView.d.ts +11 -3
- package/lib/typescript/internal/fallback.d.ts +10 -1
- package/lib/typescript/internal/glass-routing.d.ts +30 -0
- package/lib/typescript/internal/motion.d.ts +19 -0
- package/lib/typescript/internal/primitives.d.ts +41 -0
- package/package.json +2 -2
- package/src/Button.tsx +47 -22
- package/src/Card.tsx +52 -31
- package/src/Dialog.tsx +99 -64
- package/src/Form.tsx +90 -25
- package/src/Glass.tsx +24 -1
- package/src/Input.tsx +33 -12
- package/src/SegmentedControl.tsx +104 -32
- package/src/Slider.tsx +151 -47
- package/src/Switch.tsx +56 -32
- package/src/TabBar.tsx +100 -30
- package/src/Table.tsx +38 -14
- package/src/Tabs.tsx +85 -32
- package/src/ai.tsx +77 -31
- package/src/charts/BarChart.tsx +4 -2
- package/src/charts/FunnelChart.tsx +4 -2
- package/src/charts/HeatmapChart.tsx +4 -2
- package/src/charts/LineChart.tsx +4 -2
- package/src/charts/PlotChart.tsx +23 -3
- package/src/charts/RadarChart.tsx +4 -2
- package/src/charts/RingChart.tsx +4 -2
- package/src/charts/ScatterChart.tsx +24 -3
- package/src/charts/WaterfallChart.tsx +21 -3
- package/src/charts/advanced.tsx +12 -6
- package/src/charts/extra.tsx +6 -3
- package/src/internal/GlassView.tsx +31 -21
- package/src/internal/fallback.tsx +23 -8
- package/src/internal/glass-routing.ts +68 -0
- package/src/internal/motion.ts +60 -0
- package/src/internal/primitives.ts +477 -0
- package/lib/module/charts/primitives.js +0 -212
- package/lib/typescript/charts/primitives.d.ts +0 -23
- package/src/charts/primitives.ts +0 -262
package/src/charts/PlotChart.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useMemo, useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { colors } from "../internal/tokens";
|
|
4
|
-
import {
|
|
4
|
+
import { useIsDark } from "../internal/motion";
|
|
5
|
+
import { primitives } from "../internal/primitives";
|
|
5
6
|
import { formatValue, linearScale, niceDomain, ticks } from "./scales";
|
|
6
7
|
|
|
7
8
|
export interface NativePlotPoint {
|
|
@@ -32,6 +33,19 @@ export interface NativePlotChartProps {
|
|
|
32
33
|
|
|
33
34
|
const PADDING = { top: 12, right: 12, bottom: 26, left: 44 };
|
|
34
35
|
|
|
36
|
+
/** Reads the chart as one sentence for a screen reader. */
|
|
37
|
+
function plotSummary(
|
|
38
|
+
points: NativePlotPoint[],
|
|
39
|
+
xDomain: [number, number],
|
|
40
|
+
yDomain: [number, number],
|
|
41
|
+
): string {
|
|
42
|
+
return (
|
|
43
|
+
`Plot chart with ${points.length} points. ` +
|
|
44
|
+
`x from ${formatValue(xDomain[0], { compact: true })} to ${formatValue(xDomain[1], { compact: true })}, ` +
|
|
45
|
+
`y from ${formatValue(yDomain[0], { compact: true })} to ${formatValue(yDomain[1], { compact: true })}.`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
35
49
|
/**
|
|
36
50
|
* A numeric plot you supply the marks for.
|
|
37
51
|
*
|
|
@@ -46,9 +60,10 @@ export function NativePlotChart({
|
|
|
46
60
|
height = 200,
|
|
47
61
|
xLabel,
|
|
48
62
|
yLabel,
|
|
49
|
-
isDark
|
|
63
|
+
isDark: isDarkProp,
|
|
50
64
|
style,
|
|
51
65
|
}: NativePlotChartProps) {
|
|
66
|
+
const isDark = useIsDark(isDarkProp);
|
|
52
67
|
const theme = isDark ? colors.dark : colors.light;
|
|
53
68
|
const { View, Text, Svg, G, Line, Circle, SvgText } = primitives();
|
|
54
69
|
|
|
@@ -86,7 +101,12 @@ export function NativePlotChart({
|
|
|
86
101
|
const xTicks = ticks(xDomain, 4);
|
|
87
102
|
|
|
88
103
|
return (
|
|
89
|
-
<View
|
|
104
|
+
<View
|
|
105
|
+
style={style}
|
|
106
|
+
accessible
|
|
107
|
+
accessibilityRole="image"
|
|
108
|
+
accessibilityLabel={plotSummary(points, xDomain, yDomain)}
|
|
109
|
+
>
|
|
90
110
|
<Svg width={width} height={height}>
|
|
91
111
|
{yTicks.map((tick, i) => (
|
|
92
112
|
<Line
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { colors } from "../internal/tokens";
|
|
4
|
-
import {
|
|
4
|
+
import { useIsDark } from "../internal/motion";
|
|
5
|
+
import { primitives } from "../internal/primitives";
|
|
5
6
|
import { formatValue, seriesColor } from "./scales";
|
|
6
7
|
|
|
7
8
|
export interface NativeRadarSeries {
|
|
@@ -46,12 +47,13 @@ export function NativeRadarChart({
|
|
|
46
47
|
size = 260,
|
|
47
48
|
rings = 4,
|
|
48
49
|
max,
|
|
49
|
-
isDark
|
|
50
|
+
isDark: isDarkProp,
|
|
50
51
|
palette,
|
|
51
52
|
style,
|
|
52
53
|
onAxisPress,
|
|
53
54
|
}: NativeRadarChartProps) {
|
|
54
55
|
const [active, setActive] = useState<number | null>(null);
|
|
56
|
+
const isDark = useIsDark(isDarkProp);
|
|
55
57
|
const theme = isDark ? colors.dark : colors.light;
|
|
56
58
|
const { View, Text, Pressable, Svg, G, Line, Polygon, Circle, SvgText } = primitives();
|
|
57
59
|
|
package/src/charts/RingChart.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { colors } from "../internal/tokens";
|
|
4
|
-
import {
|
|
4
|
+
import { useIsDark } from "../internal/motion";
|
|
5
|
+
import { primitives } from "../internal/primitives";
|
|
5
6
|
import { arcPath, formatValue, seriesColor } from "./scales";
|
|
6
7
|
|
|
7
8
|
export interface NativeRingSlice {
|
|
@@ -39,13 +40,14 @@ export function NativeRingChart({
|
|
|
39
40
|
data,
|
|
40
41
|
size = 180,
|
|
41
42
|
thickness = 22,
|
|
42
|
-
isDark
|
|
43
|
+
isDark: isDarkProp,
|
|
43
44
|
palette,
|
|
44
45
|
showLegend = true,
|
|
45
46
|
style,
|
|
46
47
|
onSlicePress,
|
|
47
48
|
}: NativeRingChartProps) {
|
|
48
49
|
const [active, setActive] = useState<number | null>(null);
|
|
50
|
+
const isDark = useIsDark(isDarkProp);
|
|
49
51
|
const theme = isDark ? colors.dark : colors.light;
|
|
50
52
|
const { View, Text, Pressable, Svg, Path } = primitives();
|
|
51
53
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useMemo, useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { colors } from "../internal/tokens";
|
|
4
|
-
import {
|
|
4
|
+
import { useIsDark } from "../internal/motion";
|
|
5
|
+
import { primitives } from "../internal/primitives";
|
|
5
6
|
import { formatValue, linearScale, niceDomain, seriesColor, ticks } from "./scales";
|
|
6
7
|
|
|
7
8
|
export interface NativeScatterPoint {
|
|
@@ -46,12 +47,13 @@ export function NativeScatterChart({
|
|
|
46
47
|
height = 200,
|
|
47
48
|
radius = 4,
|
|
48
49
|
bubble = false,
|
|
49
|
-
isDark
|
|
50
|
+
isDark: isDarkProp,
|
|
50
51
|
palette,
|
|
51
52
|
style,
|
|
52
53
|
onPointPress,
|
|
53
54
|
}: NativeScatterChartProps) {
|
|
54
55
|
const [active, setActive] = useState<{ s: number; p: number } | null>(null);
|
|
56
|
+
const isDark = useIsDark(isDarkProp);
|
|
55
57
|
const theme = isDark ? colors.dark : colors.light;
|
|
56
58
|
const { View, Text, Svg, G, Line, Circle, SvgText } = primitives();
|
|
57
59
|
|
|
@@ -103,7 +105,14 @@ export function NativeScatterChart({
|
|
|
103
105
|
const xTicks = ticks(xDomain, 4);
|
|
104
106
|
|
|
105
107
|
return (
|
|
106
|
-
<View
|
|
108
|
+
<View
|
|
109
|
+
style={style}
|
|
110
|
+
// One summary for the whole chart: the per-point touch targets below are
|
|
111
|
+
// the detailed access, this is what is announced on focus.
|
|
112
|
+
accessible
|
|
113
|
+
accessibilityRole="image"
|
|
114
|
+
accessibilityLabel={scatterSummary(series)}
|
|
115
|
+
>
|
|
107
116
|
<Svg width={width} height={height}>
|
|
108
117
|
{yTicks.map((tick, i) => (
|
|
109
118
|
<Line
|
|
@@ -196,6 +205,18 @@ export function NativeScatterChart({
|
|
|
196
205
|
);
|
|
197
206
|
}
|
|
198
207
|
|
|
208
|
+
/** Reads the chart as one sentence for a screen reader. */
|
|
209
|
+
function scatterSummary(series: NativeScatterSeries[]): string {
|
|
210
|
+
const sentences = series.map((entry) => {
|
|
211
|
+
const ys = entry.points.map((point) => point.y).filter(Number.isFinite);
|
|
212
|
+
if (ys.length === 0) return `${entry.name}: no points`;
|
|
213
|
+
const min = formatValue(Math.min(...ys));
|
|
214
|
+
const max = formatValue(Math.max(...ys));
|
|
215
|
+
return `${entry.name}: ${entry.points.length} points, y from ${min} to ${max}`;
|
|
216
|
+
});
|
|
217
|
+
return `Scatter chart. ${sentences.join(". ")}`;
|
|
218
|
+
}
|
|
219
|
+
|
|
199
220
|
/** Scatter marks sized by a third value. */
|
|
200
221
|
export function NativeBubbleChart(props: Omit<NativeScatterChartProps, "bubble" | "radius">) {
|
|
201
222
|
return <NativeScatterChart {...props} bubble />;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { colors } from "../internal/tokens";
|
|
4
|
-
import {
|
|
4
|
+
import { useIsDark } from "../internal/motion";
|
|
5
|
+
import { primitives } from "../internal/primitives";
|
|
5
6
|
import { formatValue } from "./scales";
|
|
6
7
|
|
|
7
8
|
export interface NativeWaterfallStep {
|
|
@@ -33,11 +34,12 @@ export function NativeWaterfallChart({
|
|
|
33
34
|
steps,
|
|
34
35
|
width = 320,
|
|
35
36
|
height = 200,
|
|
36
|
-
isDark
|
|
37
|
+
isDark: isDarkProp,
|
|
37
38
|
style,
|
|
38
39
|
onStepPress,
|
|
39
40
|
}: NativeWaterfallChartProps) {
|
|
40
41
|
const [active, setActive] = useState<number | null>(null);
|
|
42
|
+
const isDark = useIsDark(isDarkProp);
|
|
41
43
|
const theme = isDark ? colors.dark : colors.light;
|
|
42
44
|
const { View, Text, Pressable, Svg, G, Line, Rect, SvgText } = primitives();
|
|
43
45
|
|
|
@@ -90,7 +92,12 @@ export function NativeWaterfallChart({
|
|
|
90
92
|
const zeroY = y(0);
|
|
91
93
|
|
|
92
94
|
return (
|
|
93
|
-
<View
|
|
95
|
+
<View
|
|
96
|
+
style={style}
|
|
97
|
+
accessible
|
|
98
|
+
accessibilityRole="image"
|
|
99
|
+
accessibilityLabel={waterfallSummary(steps, geometry)}
|
|
100
|
+
>
|
|
94
101
|
<Svg width={width} height={height}>
|
|
95
102
|
<Line
|
|
96
103
|
x1={plot.x}
|
|
@@ -177,6 +184,17 @@ export function NativeWaterfallChart({
|
|
|
177
184
|
);
|
|
178
185
|
}
|
|
179
186
|
|
|
187
|
+
/** Reads the chart as one sentence for a screen reader. */
|
|
188
|
+
function waterfallSummary(
|
|
189
|
+
steps: NativeWaterfallStep[],
|
|
190
|
+
geometry: { end: number }[],
|
|
191
|
+
): string {
|
|
192
|
+
const last = geometry[geometry.length - 1];
|
|
193
|
+
const changes = steps.filter((step) => !step.isTotal).length;
|
|
194
|
+
const closing = last ? ` Closing value ${formatValue(last.end)}.` : "";
|
|
195
|
+
return `Waterfall chart. ${steps.length} steps, ${changes} of them changes.${closing}`;
|
|
196
|
+
}
|
|
197
|
+
|
|
180
198
|
/** Totals are neutral so they do not read as a gain or loss. */
|
|
181
199
|
function seriesTotalColor(isDark: boolean) {
|
|
182
200
|
return isDark ? "#8e8e93" : "#3c3c43";
|
package/src/charts/advanced.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useMemo, useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { colors } from "../internal/tokens";
|
|
4
|
-
import {
|
|
4
|
+
import { useIsDark } from "../internal/motion";
|
|
5
|
+
import { primitives } from "../internal/primitives";
|
|
5
6
|
import { formatValue, linearScale, niceDomain, seriesColor, ticks } from "./scales";
|
|
6
7
|
|
|
7
8
|
export interface NativeCandle {
|
|
@@ -34,11 +35,12 @@ export function NativeCandlestickChart({
|
|
|
34
35
|
candles,
|
|
35
36
|
width = 320,
|
|
36
37
|
height = 200,
|
|
37
|
-
isDark
|
|
38
|
+
isDark: isDarkProp,
|
|
38
39
|
style,
|
|
39
40
|
onCandlePress,
|
|
40
41
|
}: NativeCandlestickChartProps) {
|
|
41
42
|
const [active, setActive] = useState<number | null>(null);
|
|
43
|
+
const isDark = useIsDark(isDarkProp);
|
|
42
44
|
const theme = isDark ? colors.dark : colors.light;
|
|
43
45
|
const { View, Text, Svg, G, Line, Rect, SvgText } = primitives();
|
|
44
46
|
|
|
@@ -233,12 +235,13 @@ export function NativeTreemapChart({
|
|
|
233
235
|
items,
|
|
234
236
|
width = 320,
|
|
235
237
|
height = 200,
|
|
236
|
-
isDark
|
|
238
|
+
isDark: isDarkProp,
|
|
237
239
|
palette,
|
|
238
240
|
style,
|
|
239
241
|
onItemPress,
|
|
240
242
|
}: NativeTreemapChartProps) {
|
|
241
243
|
const [active, setActive] = useState<number | null>(null);
|
|
244
|
+
const isDark = useIsDark(isDarkProp);
|
|
242
245
|
const theme = isDark ? colors.dark : colors.light;
|
|
243
246
|
const { View, Text, Pressable } = primitives();
|
|
244
247
|
|
|
@@ -347,10 +350,11 @@ export function NativeSankeyChart({
|
|
|
347
350
|
links,
|
|
348
351
|
width = 320,
|
|
349
352
|
height = 200,
|
|
350
|
-
isDark
|
|
353
|
+
isDark: isDarkProp,
|
|
351
354
|
palette,
|
|
352
355
|
style,
|
|
353
356
|
}: NativeSankeyChartProps) {
|
|
357
|
+
const isDark = useIsDark(isDarkProp);
|
|
354
358
|
const theme = isDark ? colors.dark : colors.light;
|
|
355
359
|
const { View, Text } = primitives();
|
|
356
360
|
|
|
@@ -460,11 +464,12 @@ export function NativeBumpChart({
|
|
|
460
464
|
series,
|
|
461
465
|
width = 320,
|
|
462
466
|
height = 200,
|
|
463
|
-
isDark
|
|
467
|
+
isDark: isDarkProp,
|
|
464
468
|
palette,
|
|
465
469
|
style,
|
|
466
470
|
onPointPress,
|
|
467
471
|
}: NativeBumpChartProps) {
|
|
472
|
+
const isDark = useIsDark(isDarkProp);
|
|
468
473
|
const theme = isDark ? colors.dark : colors.light;
|
|
469
474
|
const { View, Text, Pressable, Svg, G, Line, Circle, SvgText } = primitives();
|
|
470
475
|
|
|
@@ -577,11 +582,12 @@ export function NativeHexChart({
|
|
|
577
582
|
radius = 9,
|
|
578
583
|
width = 320,
|
|
579
584
|
height = 200,
|
|
580
|
-
isDark
|
|
585
|
+
isDark: isDarkProp,
|
|
581
586
|
style,
|
|
582
587
|
onBinPress,
|
|
583
588
|
}: NativeHexChartProps) {
|
|
584
589
|
const [active, setActive] = useState<number | null>(null);
|
|
590
|
+
const isDark = useIsDark(isDarkProp);
|
|
585
591
|
const theme = isDark ? colors.dark : colors.light;
|
|
586
592
|
const { View, Text, Pressable, Svg, G, Path } = primitives();
|
|
587
593
|
|
package/src/charts/extra.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { colors } from "../internal/tokens";
|
|
4
|
-
import {
|
|
4
|
+
import { useIsDark } from "../internal/motion";
|
|
5
|
+
import { primitives } from "../internal/primitives";
|
|
5
6
|
import { NativeLineChart, type NativeLineSeries } from "./LineChart";
|
|
6
7
|
import { formatValue, seriesColor } from "./scales";
|
|
7
8
|
|
|
@@ -40,12 +41,13 @@ export function NativePolarAreaChart({
|
|
|
40
41
|
segments,
|
|
41
42
|
size = 240,
|
|
42
43
|
max,
|
|
43
|
-
isDark
|
|
44
|
+
isDark: isDarkProp,
|
|
44
45
|
palette,
|
|
45
46
|
style,
|
|
46
47
|
onSegmentPress,
|
|
47
48
|
}: NativePolarAreaChartProps) {
|
|
48
49
|
const [active, setActive] = useState<number | null>(null);
|
|
50
|
+
const isDark = useIsDark(isDarkProp);
|
|
49
51
|
const theme = isDark ? colors.dark : colors.light;
|
|
50
52
|
const { View, Text, Pressable, Svg, G, Path, Circle } = primitives();
|
|
51
53
|
|
|
@@ -156,12 +158,13 @@ export function NativePyramidChart({
|
|
|
156
158
|
levels,
|
|
157
159
|
levelHeight = 34,
|
|
158
160
|
width = 320,
|
|
159
|
-
isDark
|
|
161
|
+
isDark: isDarkProp,
|
|
160
162
|
palette,
|
|
161
163
|
style,
|
|
162
164
|
onLevelPress,
|
|
163
165
|
}: NativePyramidChartProps) {
|
|
164
166
|
const [active, setActive] = useState<number | null>(null);
|
|
167
|
+
const isDark = useIsDark(isDarkProp);
|
|
165
168
|
const theme = isDark ? colors.dark : colors.light;
|
|
166
169
|
const { View, Text, Pressable } = primitives();
|
|
167
170
|
|
|
@@ -1,59 +1,67 @@
|
|
|
1
1
|
import { forwardRef, type ReactNode } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import { FallbackGlassView } from "./fallback";
|
|
5
|
+
import { defaultRouter } from "./glass-routing";
|
|
6
|
+
import { useIsDark } from "./motion";
|
|
5
7
|
|
|
6
8
|
export interface NativeGlassProps {
|
|
7
9
|
effect?: "clear" | "regular" | "none";
|
|
8
10
|
tintColor?: string;
|
|
9
11
|
interactive?: boolean;
|
|
10
|
-
|
|
12
|
+
/** Passed to whichever surface renders, so tests can find the glass itself. */
|
|
13
|
+
testID?: string;
|
|
14
|
+
style?: StyleProp<ViewStyle>;
|
|
11
15
|
children?: ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Explicit dark override for the fallback tint. When omitted the phone's
|
|
18
|
+
* colour scheme decides, so developers never thread this prop themselves.
|
|
19
|
+
*/
|
|
20
|
+
isDark?: boolean;
|
|
12
21
|
}
|
|
13
22
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
LiquidGlassViewComponent = liquidGlass.LiquidGlassView;
|
|
21
|
-
supported = Boolean(liquidGlass.isLiquidGlassSupported);
|
|
22
|
-
}
|
|
23
|
-
} catch {
|
|
24
|
-
supported = false;
|
|
25
|
-
}
|
|
23
|
+
/**
|
|
24
|
+
* The installed `@callstack/liquid-glass` module, resolved once at load.
|
|
25
|
+
* `isLiquidGlassSupported` is true only on iOS 26+; false on older iOS,
|
|
26
|
+
* Android and Expo Go.
|
|
27
|
+
*/
|
|
28
|
+
const router = defaultRouter();
|
|
26
29
|
|
|
27
|
-
export const isGlassSupported = supported;
|
|
30
|
+
export const isGlassSupported = router.supported;
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
|
-
* Platform Glass View:
|
|
33
|
+
* Platform Glass View — the single place a glass surface is chosen:
|
|
31
34
|
* - iOS 26+: Real UIGlassEffect via @callstack/liquid-glass
|
|
32
|
-
* - iOS < 26 / Android / Expo Go
|
|
35
|
+
* - iOS < 26 / Android / Expo Go: translucent tint View with identical layout
|
|
33
36
|
*/
|
|
34
37
|
export const GlassView = forwardRef<any, NativeGlassProps>(function GlassView(
|
|
35
38
|
{
|
|
36
39
|
effect = "regular",
|
|
37
40
|
tintColor,
|
|
38
41
|
interactive = false,
|
|
42
|
+
testID,
|
|
39
43
|
style,
|
|
40
44
|
children,
|
|
45
|
+
isDark: isDarkProp,
|
|
41
46
|
...props
|
|
42
47
|
},
|
|
43
48
|
ref,
|
|
44
49
|
) {
|
|
45
|
-
|
|
50
|
+
const isDark = useIsDark(isDarkProp);
|
|
51
|
+
if (router.supported && router.LiquidGlassView) {
|
|
52
|
+
const LiquidGlassView = router.LiquidGlassView;
|
|
46
53
|
return (
|
|
47
|
-
<
|
|
54
|
+
<LiquidGlassView
|
|
48
55
|
ref={ref}
|
|
49
56
|
effect={effect}
|
|
50
57
|
tintColor={tintColor}
|
|
51
58
|
interactive={interactive}
|
|
59
|
+
testID={testID}
|
|
52
60
|
style={style}
|
|
53
61
|
{...props}
|
|
54
62
|
>
|
|
55
63
|
{children}
|
|
56
|
-
</
|
|
64
|
+
</LiquidGlassView>
|
|
57
65
|
);
|
|
58
66
|
}
|
|
59
67
|
|
|
@@ -62,6 +70,8 @@ export const GlassView = forwardRef<any, NativeGlassProps>(function GlassView(
|
|
|
62
70
|
ref={ref}
|
|
63
71
|
effect={effect}
|
|
64
72
|
tintColor={tintColor}
|
|
73
|
+
testID={testID}
|
|
74
|
+
isDark={isDark}
|
|
65
75
|
style={style}
|
|
66
76
|
{...props}
|
|
67
77
|
>
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
import { forwardRef, type ReactNode } from "react";
|
|
2
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
3
|
+
|
|
2
4
|
import { colors, radii } from "./tokens";
|
|
5
|
+
import { primitives } from "./primitives";
|
|
3
6
|
|
|
4
7
|
export interface FallbackGlassProps {
|
|
5
8
|
effect?: "clear" | "regular" | "none";
|
|
6
9
|
tintColor?: string;
|
|
7
|
-
|
|
10
|
+
testID?: string;
|
|
11
|
+
style?: StyleProp<ViewStyle>;
|
|
8
12
|
children?: ReactNode;
|
|
9
13
|
isDark?: boolean;
|
|
10
14
|
}
|
|
11
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Glacia's own glass surface for every platform where Apple's material is not
|
|
18
|
+
* available: Android, iOS before 26, and Expo Go.
|
|
19
|
+
*
|
|
20
|
+
* It renders the resolver's real React Native `View` with the same shape and
|
|
21
|
+
* layout as the native glass, so switching branches never shifts the layout.
|
|
22
|
+
*/
|
|
12
23
|
export const FallbackGlassView = forwardRef<any, FallbackGlassProps>(function FallbackGlassView(
|
|
13
24
|
{
|
|
14
25
|
effect = "regular",
|
|
15
26
|
tintColor,
|
|
27
|
+
testID,
|
|
16
28
|
style,
|
|
17
29
|
children,
|
|
18
30
|
isDark = false,
|
|
@@ -21,26 +33,29 @@ export const FallbackGlassView = forwardRef<any, FallbackGlassProps>(function Fa
|
|
|
21
33
|
ref,
|
|
22
34
|
) {
|
|
23
35
|
const themeColors = isDark ? colors.dark : colors.light;
|
|
36
|
+
const { View } = primitives();
|
|
24
37
|
|
|
25
38
|
const bg =
|
|
26
39
|
effect === "none"
|
|
27
40
|
? "transparent"
|
|
28
41
|
: effect === "clear"
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
? isDark
|
|
43
|
+
? "rgba(28, 28, 30, 0.35)"
|
|
44
|
+
: "rgba(255, 255, 255, 0.35)"
|
|
45
|
+
: tintColor || themeColors.glass;
|
|
31
46
|
|
|
32
|
-
const containerStyle = {
|
|
47
|
+
const containerStyle: ViewStyle = {
|
|
33
48
|
backgroundColor: bg,
|
|
34
49
|
borderColor: themeColors.edge,
|
|
35
50
|
borderWidth: 0.5,
|
|
36
51
|
borderRadius: radii.md,
|
|
37
|
-
overflow: "hidden"
|
|
38
|
-
...style,
|
|
52
|
+
overflow: "hidden",
|
|
53
|
+
...(style as ViewStyle),
|
|
39
54
|
};
|
|
40
55
|
|
|
41
56
|
return (
|
|
42
|
-
<
|
|
57
|
+
<View ref={ref} testID={testID} style={containerStyle} {...props}>
|
|
43
58
|
{children}
|
|
44
|
-
</
|
|
59
|
+
</View>
|
|
45
60
|
);
|
|
46
61
|
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// The glass switch — the law of this library.
|
|
2
|
+
//
|
|
3
|
+
// Every glass surface in every Glacia Native component goes through
|
|
4
|
+
// `GlassView`, which routes here. On iOS 26+ `@callstack/liquid-glass` reports
|
|
5
|
+
// `isLiquidGlassSupported === true` and the surface is rendered by Apple's
|
|
6
|
+
// real `UIGlassEffect` (`LiquidGlassView`). Everywhere else — older iOS,
|
|
7
|
+
// Android, Expo Go, or a build without the module — it is Glacia's own
|
|
8
|
+
// translucent fallback of identical shape.
|
|
9
|
+
//
|
|
10
|
+
// The decision is split out from the React component so both branches can be
|
|
11
|
+
// exercised in tests: `routerFor` takes the module as an argument, and the
|
|
12
|
+
// default export routes on whatever is installed. On a device the argument is
|
|
13
|
+
// always the installed module, so the routing logic is unchanged.
|
|
14
|
+
|
|
15
|
+
declare const require: any;
|
|
16
|
+
|
|
17
|
+
export interface LiquidGlassModule {
|
|
18
|
+
LiquidGlassView?: any;
|
|
19
|
+
isLiquidGlassSupported?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The routing decision for one glass surface. */
|
|
23
|
+
export interface GlassRouter {
|
|
24
|
+
/** True when Apple's real glass renders this surface. */
|
|
25
|
+
supported: boolean;
|
|
26
|
+
/** Apple's `LiquidGlassView`, or null when the fallback renders instead. */
|
|
27
|
+
LiquidGlassView: any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Reads a liquid-glass module and decides which branch renders.
|
|
32
|
+
*
|
|
33
|
+
* A module only counts as supported when it exports the view *and* reports
|
|
34
|
+
* support; a missing export falls back rather than crashing.
|
|
35
|
+
*/
|
|
36
|
+
export function routerFor(module: LiquidGlassModule | null | undefined): GlassRouter {
|
|
37
|
+
const view = module?.LiquidGlassView ?? null;
|
|
38
|
+
return {
|
|
39
|
+
supported: Boolean(module?.isLiquidGlassSupported) && Boolean(view),
|
|
40
|
+
LiquidGlassView: view,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Loads `@callstack/liquid-glass` at runtime.
|
|
46
|
+
*
|
|
47
|
+
* Resolved through `require` rather than a static import so the package stays
|
|
48
|
+
* importable where the native module is absent (jsdom tests, web preview).
|
|
49
|
+
* `isLiquidGlassSupported` is a constant baked by the package's own platform
|
|
50
|
+
* resolution: its iOS build reads the native module and answers true only on
|
|
51
|
+
* iOS 26+; the default build answers false.
|
|
52
|
+
*/
|
|
53
|
+
export function loadLiquidGlass(): LiquidGlassModule | null {
|
|
54
|
+
try {
|
|
55
|
+
const module = require("@callstack/liquid-glass");
|
|
56
|
+
if (module && (module.LiquidGlassView || module.isLiquidGlassSupported !== undefined)) {
|
|
57
|
+
return module as LiquidGlassModule;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The installed module's routing decision, computed once per process. */
|
|
66
|
+
export function defaultRouter(): GlassRouter {
|
|
67
|
+
return routerFor(loadLiquidGlass());
|
|
68
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Shared component plumbing: dark-mode defaulting and spring motion.
|
|
2
|
+
//
|
|
3
|
+
// Two rules apply to every Glacia component, so they live here instead of
|
|
4
|
+
// being repeated (and forgotten) in each file:
|
|
5
|
+
// - `useIsDark` falls back to the phone's own colour scheme when the caller
|
|
6
|
+
// does not pass `isDark`, so a theme-aware app needs no extra prop threading.
|
|
7
|
+
// - `useSpring` animates a number towards its target with the package's spring
|
|
8
|
+
// tokens through React Native's Animated API. No CSS, no timers of our own.
|
|
9
|
+
|
|
10
|
+
import { useEffect, useRef } from "react";
|
|
11
|
+
|
|
12
|
+
import { primitives } from "./primitives";
|
|
13
|
+
import { springs } from "./tokens";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolves the theme. An explicit `isDark` always wins; otherwise the phone's
|
|
17
|
+
* colour scheme decides, defaulting to light when it is unknown.
|
|
18
|
+
*/
|
|
19
|
+
export function useIsDark(isDark?: boolean): boolean {
|
|
20
|
+
const { useColorScheme } = primitives();
|
|
21
|
+
const scheme = typeof useColorScheme === "function" ? useColorScheme() : null;
|
|
22
|
+
return isDark ?? scheme === "dark";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type SpringName = keyof typeof springs;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A value that springs towards `target` whenever it changes.
|
|
29
|
+
*
|
|
30
|
+
* Returns the `Animated.Value` to put in a style, plus whether motion is real
|
|
31
|
+
* on this platform. A caller that gets `animated === false` renders the target
|
|
32
|
+
* directly, so the DOM preview and tests show the settled state rather than an
|
|
33
|
+
* animation the environment cannot advance.
|
|
34
|
+
*/
|
|
35
|
+
export function useSpring(target: number, spring: SpringName = "snappy") {
|
|
36
|
+
const { Animated, isNative } = primitives();
|
|
37
|
+
const animated = Boolean(isNative && Animated?.Value && Animated?.spring);
|
|
38
|
+
|
|
39
|
+
// Off-device there is no Animated; a plain ref keeps the call sites identical.
|
|
40
|
+
const value = useRef<any>(null);
|
|
41
|
+
if (value.current === null) {
|
|
42
|
+
value.current = animated ? new Animated.Value(target) : { value: target };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!animated) {
|
|
47
|
+
value.current.value = target;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const animation = Animated.spring(value.current, {
|
|
51
|
+
toValue: target,
|
|
52
|
+
...springs[spring],
|
|
53
|
+
useNativeDriver: false,
|
|
54
|
+
});
|
|
55
|
+
animation.start();
|
|
56
|
+
return () => animation.stop?.();
|
|
57
|
+
}, [animated, spring, target]);
|
|
58
|
+
|
|
59
|
+
return { value: value.current, animated };
|
|
60
|
+
}
|