glacia-native 0.3.5 → 0.5.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.
Files changed (121) hide show
  1. package/lib/module/Bars.js +176 -0
  2. package/lib/module/Button.js +15 -2
  3. package/lib/module/Card.js +29 -14
  4. package/lib/module/Carousel.js +103 -0
  5. package/lib/module/Dialog.js +43 -32
  6. package/lib/module/Display.js +240 -0
  7. package/lib/module/Feedback.js +172 -0
  8. package/lib/module/Form.js +51 -12
  9. package/lib/module/Forms2.js +227 -0
  10. package/lib/module/Glass.js +11 -2
  11. package/lib/module/Input.js +19 -7
  12. package/lib/module/Overlays.js +166 -0
  13. package/lib/module/Pickers.js +243 -0
  14. package/lib/module/SegmentedControl.js +65 -21
  15. package/lib/module/Slider.js +121 -25
  16. package/lib/module/Switch.js +33 -15
  17. package/lib/module/TabBar.js +63 -25
  18. package/lib/module/Table.js +24 -6
  19. package/lib/module/Tabs.js +55 -33
  20. package/lib/module/Text.js +37 -0
  21. package/lib/module/ai.js +49 -20
  22. package/lib/module/charts/BarChart.js +4 -2
  23. package/lib/module/charts/FunnelChart.js +4 -2
  24. package/lib/module/charts/HeatmapChart.js +4 -2
  25. package/lib/module/charts/LineChart.js +4 -2
  26. package/lib/module/charts/PlotChart.js +11 -3
  27. package/lib/module/charts/RadarChart.js +4 -2
  28. package/lib/module/charts/RingChart.js +4 -2
  29. package/lib/module/charts/ScatterChart.js +20 -3
  30. package/lib/module/charts/WaterfallChart.js +12 -3
  31. package/lib/module/charts/advanced.js +12 -6
  32. package/lib/module/charts/extra.js +6 -3
  33. package/lib/module/index.js +58 -1
  34. package/lib/module/internal/GlassView.js +31 -17
  35. package/lib/module/internal/fallback.js +14 -3
  36. package/lib/module/internal/glass-routing.js +56 -0
  37. package/lib/module/internal/motion.js +55 -0
  38. package/lib/module/internal/primitives.js +413 -0
  39. package/lib/module/internal/tokens.js +55 -1
  40. package/lib/typescript/Bars.d.ts +121 -0
  41. package/lib/typescript/Button.d.ts +11 -1
  42. package/lib/typescript/Card.d.ts +20 -8
  43. package/lib/typescript/Carousel.d.ts +47 -0
  44. package/lib/typescript/Dialog.d.ts +19 -6
  45. package/lib/typescript/Display.d.ts +119 -0
  46. package/lib/typescript/Feedback.d.ts +138 -0
  47. package/lib/typescript/Form.d.ts +27 -11
  48. package/lib/typescript/Forms2.d.ts +128 -0
  49. package/lib/typescript/Glass.d.ts +10 -1
  50. package/lib/typescript/Input.d.ts +11 -1
  51. package/lib/typescript/Overlays.d.ts +105 -0
  52. package/lib/typescript/Pickers.d.ts +105 -0
  53. package/lib/typescript/SegmentedControl.d.ts +11 -1
  54. package/lib/typescript/Slider.d.ts +13 -1
  55. package/lib/typescript/Switch.d.ts +12 -1
  56. package/lib/typescript/TabBar.d.ts +13 -1
  57. package/lib/typescript/Table.d.ts +14 -5
  58. package/lib/typescript/Tabs.d.ts +8 -5
  59. package/lib/typescript/Text.d.ts +28 -0
  60. package/lib/typescript/ai.d.ts +12 -9
  61. package/lib/typescript/charts/BarChart.d.ts +1 -1
  62. package/lib/typescript/charts/FunnelChart.d.ts +1 -1
  63. package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
  64. package/lib/typescript/charts/LineChart.d.ts +1 -1
  65. package/lib/typescript/charts/PlotChart.d.ts +1 -1
  66. package/lib/typescript/charts/RadarChart.d.ts +1 -1
  67. package/lib/typescript/charts/RingChart.d.ts +1 -1
  68. package/lib/typescript/charts/ScatterChart.d.ts +1 -1
  69. package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
  70. package/lib/typescript/charts/advanced.d.ts +5 -5
  71. package/lib/typescript/charts/extra.d.ts +2 -2
  72. package/lib/typescript/index.d.ts +9 -1
  73. package/lib/typescript/internal/GlassView.d.ts +21 -4
  74. package/lib/typescript/internal/fallback.d.ts +10 -1
  75. package/lib/typescript/internal/glass-routing.d.ts +30 -0
  76. package/lib/typescript/internal/motion.d.ts +19 -0
  77. package/lib/typescript/internal/primitives.d.ts +41 -0
  78. package/lib/typescript/internal/tokens.d.ts +61 -0
  79. package/package.json +2 -2
  80. package/src/Bars.tsx +570 -0
  81. package/src/Button.tsx +47 -22
  82. package/src/Card.tsx +52 -31
  83. package/src/Carousel.tsx +233 -0
  84. package/src/Dialog.tsx +99 -64
  85. package/src/Display.tsx +550 -0
  86. package/src/Feedback.tsx +579 -0
  87. package/src/Form.tsx +90 -25
  88. package/src/Forms2.tsx +608 -0
  89. package/src/Glass.tsx +24 -1
  90. package/src/Input.tsx +33 -12
  91. package/src/Overlays.tsx +474 -0
  92. package/src/Pickers.tsx +590 -0
  93. package/src/SegmentedControl.tsx +104 -32
  94. package/src/Slider.tsx +151 -47
  95. package/src/Switch.tsx +56 -32
  96. package/src/TabBar.tsx +100 -30
  97. package/src/Table.tsx +38 -14
  98. package/src/Tabs.tsx +85 -32
  99. package/src/Text.tsx +83 -0
  100. package/src/ai.tsx +77 -31
  101. package/src/charts/BarChart.tsx +4 -2
  102. package/src/charts/FunnelChart.tsx +4 -2
  103. package/src/charts/HeatmapChart.tsx +4 -2
  104. package/src/charts/LineChart.tsx +4 -2
  105. package/src/charts/PlotChart.tsx +23 -3
  106. package/src/charts/RadarChart.tsx +4 -2
  107. package/src/charts/RingChart.tsx +4 -2
  108. package/src/charts/ScatterChart.tsx +24 -3
  109. package/src/charts/WaterfallChart.tsx +21 -3
  110. package/src/charts/advanced.tsx +12 -6
  111. package/src/charts/extra.tsx +6 -3
  112. package/src/index.ts +101 -1
  113. package/src/internal/GlassView.tsx +51 -19
  114. package/src/internal/fallback.tsx +23 -8
  115. package/src/internal/glass-routing.ts +68 -0
  116. package/src/internal/motion.ts +60 -0
  117. package/src/internal/primitives.ts +482 -0
  118. package/src/internal/tokens.ts +62 -0
  119. package/lib/module/charts/primitives.js +0 -212
  120. package/lib/typescript/charts/primitives.d.ts +0 -23
  121. package/src/charts/primitives.ts +0 -262
package/src/ai.tsx CHANGED
@@ -1,7 +1,9 @@
1
1
  import { useEffect, useState, type ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
2
3
 
3
4
  import { colors, radii } from "./internal/tokens";
4
- import { primitives } from "./charts/primitives";
5
+ import { primitives } from "./internal/primitives";
6
+ import { useIsDark } from "./internal/motion";
5
7
 
6
8
  export interface NativePlanStep {
7
9
  id: string;
@@ -23,7 +25,8 @@ export interface NativePlanProps {
23
25
  * Each step carries its own status, so a half-finished plan is legible instead
24
26
  * of appearing blank until the whole thing completes.
25
27
  */
26
- export function NativePlan({ title = "Plan", steps, isDark = false, style }: NativePlanProps) {
28
+ export function NativePlan({ title = "Plan", steps, isDark: isDarkProp, style }: NativePlanProps) {
29
+ const isDark = useIsDark(isDarkProp);
27
30
  const theme = isDark ? colors.dark : colors.light;
28
31
  const { View, Text } = primitives();
29
32
  const done = steps.filter((step) => step.status === "done").length;
@@ -124,10 +127,11 @@ export interface NativeSourcesProps {
124
127
  export function NativeSources({
125
128
  sources,
126
129
  title = "Sources",
127
- isDark = false,
130
+ isDark: isDarkProp,
128
131
  style,
129
132
  onSourcePress,
130
133
  }: NativeSourcesProps) {
134
+ const isDark = useIsDark(isDarkProp);
131
135
  const theme = isDark ? colors.dark : colors.light;
132
136
  const { View, Text, Pressable } = primitives();
133
137
 
@@ -197,9 +201,10 @@ export function NativeResponse({
197
201
  text,
198
202
  revealed,
199
203
  streaming,
200
- isDark = false,
204
+ isDark: isDarkProp,
201
205
  style,
202
206
  }: NativeResponseProps) {
207
+ const isDark = useIsDark(isDarkProp);
203
208
  const theme = isDark ? colors.dark : colors.light;
204
209
  const { View, Text } = primitives();
205
210
 
@@ -237,7 +242,8 @@ export interface NativeTaskProps {
237
242
  }
238
243
 
239
244
  /** Progress of a long-running background task. */
240
- export function NativeTask({ task, isDark = false, style }: NativeTaskProps) {
245
+ export function NativeTask({ task, isDark: isDarkProp, style }: NativeTaskProps) {
246
+ const isDark = useIsDark(isDarkProp);
241
247
  const theme = isDark ? colors.dark : colors.light;
242
248
  const { View, Text } = primitives();
243
249
 
@@ -251,10 +257,13 @@ export function NativeTask({ task, isDark = false, style }: NativeTaskProps) {
251
257
  <View
252
258
  accessibilityRole="progressbar"
253
259
  accessibilityLabel={task.label ?? "Task progress"}
260
+ // Without the value, a screen reader only reads the label and never says
261
+ // how far along the task is.
262
+ accessibilityValue={percent == null ? undefined : { min: 0, max: 100, now: percent }}
254
263
  accessibilityState={{
255
264
  disabled: false,
256
265
  }}
257
- style={style}
266
+ style={style as StyleProp<ViewStyle>}
258
267
  >
259
268
  <View
260
269
  style={{ flexDirection: "row", justifyContent: "space-between", marginBottom: 6 }}
@@ -318,10 +327,11 @@ export function NativeSoundwave({
318
327
  active = true,
319
328
  height = 40,
320
329
  color,
321
- isDark = false,
330
+ isDark: isDarkProp,
322
331
  style,
323
332
  label = "Audio level",
324
333
  }: NativeSoundwaveProps) {
334
+ const isDark = useIsDark(isDarkProp);
325
335
  const theme = isDark ? colors.dark : colors.light;
326
336
  const { View } = primitives();
327
337
 
@@ -374,9 +384,10 @@ export function NativeThinkingOrb({
374
384
  label = "Thinking",
375
385
  size = 22,
376
386
  paused = false,
377
- isDark = false,
387
+ isDark: isDarkProp,
378
388
  style,
379
389
  }: NativeThinkingOrbProps) {
390
+ const isDark = useIsDark(isDarkProp);
380
391
  const theme = isDark ? colors.dark : colors.light;
381
392
  const { View, Text } = primitives();
382
393
  const [tick, setTick] = useState(0);
@@ -435,10 +446,11 @@ export function NativePanelside({
435
446
  items,
436
447
  value,
437
448
  onValueChange,
438
- isDark = false,
449
+ isDark: isDarkProp,
439
450
  style,
440
451
  title,
441
452
  }: NativePanelsideProps) {
453
+ const isDark = useIsDark(isDarkProp);
442
454
  const theme = isDark ? colors.dark : colors.light;
443
455
  const { View, Text, Pressable } = primitives();
444
456
 
@@ -490,7 +502,10 @@ export function NativePanelside({
490
502
  }
491
503
 
492
504
  export interface NativeAIInputProps {
505
+ /** Controlled text. Omit it and the composer keeps its own. */
493
506
  value?: string;
507
+ /** Starting text for uncontrolled use. */
508
+ defaultValue?: string;
494
509
  onChangeText?: (text: string) => void;
495
510
  onSubmit?: () => void;
496
511
  placeholder?: string;
@@ -510,24 +525,38 @@ export interface NativeAIInputProps {
510
525
  * that prevents empty submissions rather than a validation message afterwards.
511
526
  */
512
527
  export function NativeAIInput({
513
- value = "",
528
+ value: valueProp,
529
+ defaultValue,
514
530
  onChangeText,
515
531
  onSubmit,
516
532
  placeholder = "Ask anything",
517
533
  disabled = false,
518
534
  busy = false,
519
535
  sendLabel = "Send",
520
- isDark = false,
536
+ isDark: isDarkProp,
521
537
  style,
522
538
  footer,
523
539
  }: NativeAIInputProps) {
540
+ const isDark = useIsDark(isDarkProp);
524
541
  const theme = isDark ? colors.dark : colors.light;
525
542
  const { View, Text, TextInput, Pressable } = primitives();
526
543
 
544
+ // Uncontrolled support: the composer owns its text when no `value` is given,
545
+ // which is what makes typed text appear in plain uncontrolled use.
546
+ const [internalText, setInternalText] = useState(defaultValue ?? "");
547
+ const value = valueProp !== undefined ? valueProp : internalText;
548
+ const handleChangeText = (next: string) => {
549
+ if (valueProp === undefined) setInternalText(next);
550
+ onChangeText?.(next);
551
+ };
552
+
527
553
  const canSend = !disabled && !busy && value.trim().length > 0;
554
+ // The themed placeholder is drawn as a Text, matching Input: the OS default
555
+ // placeholder colour ignores the theme.
556
+ const showPlaceholder = !value && Boolean(placeholder);
528
557
 
529
558
  return (
530
- <View style={style}>
559
+ <View style={style as StyleProp<ViewStyle>}>
531
560
  <View
532
561
  style={{
533
562
  flexDirection: "row",
@@ -541,24 +570,40 @@ export function NativeAIInput({
541
570
  opacity: disabled ? 0.5 : 1,
542
571
  }}
543
572
  >
544
- <TextInput
545
- value={value}
546
- onChangeText={onChangeText}
547
- placeholder={placeholder}
548
- editable={!disabled}
549
- multiline
550
- numberOfLines={3}
551
- accessibilityLabel={placeholder}
552
- style={{
553
- flex: 1,
554
- minHeight: 34,
555
- maxHeight: 120,
556
- paddingHorizontal: 6,
557
- paddingVertical: 7,
558
- fontSize: 14,
559
- color: theme.foreground,
560
- }}
561
- />
573
+ <View style={{ flex: 1, justifyContent: "center" }}>
574
+ {showPlaceholder && (
575
+ <Text
576
+ pointerEvents="none"
577
+ numberOfLines={1}
578
+ style={{
579
+ position: "absolute",
580
+ left: 6,
581
+ fontSize: 14,
582
+ color: theme.muted,
583
+ }}
584
+ >
585
+ {placeholder}
586
+ </Text>
587
+ )}
588
+
589
+ <TextInput
590
+ value={value}
591
+ onChangeText={handleChangeText}
592
+ editable={!disabled}
593
+ multiline
594
+ numberOfLines={3}
595
+ accessibilityLabel={placeholder}
596
+ accessibilityState={{ disabled }}
597
+ style={{
598
+ minHeight: 34,
599
+ maxHeight: 120,
600
+ paddingHorizontal: 6,
601
+ paddingVertical: 7,
602
+ fontSize: 14,
603
+ color: theme.foreground,
604
+ }}
605
+ />
606
+ </View>
562
607
 
563
608
  <Pressable
564
609
  accessibilityRole="button"
@@ -611,9 +656,10 @@ export function NativeImageGeneration({
611
656
  image,
612
657
  prompt,
613
658
  status = "queued",
614
- isDark = false,
659
+ isDark: isDarkProp,
615
660
  style,
616
661
  }: NativeImageGenerationProps) {
662
+ const isDark = useIsDark(isDarkProp);
617
663
  const theme = isDark ? colors.dark : colors.light;
618
664
  const { View, Text, Image } = primitives();
619
665
 
@@ -1,7 +1,8 @@
1
1
  import { useMemo, useState } from "react";
2
2
 
3
3
  import { colors } from "../internal/tokens";
4
- import { primitives } from "./primitives";
4
+ import { useIsDark } from "../internal/motion";
5
+ import { primitives } from "../internal/primitives";
5
6
  import { bandScale, formatValue, linearScale, niceDomain, seriesColor, ticks } from "./scales";
6
7
 
7
8
  export interface NativeBarSeries {
@@ -33,12 +34,13 @@ export function NativeBarChart({
33
34
  height = 200,
34
35
  stacked = false,
35
36
  radius = 4,
36
- isDark = false,
37
+ isDark: isDarkProp,
37
38
  palette,
38
39
  style,
39
40
  onBarPress,
40
41
  }: NativeBarChartProps) {
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, Pressable, Svg, G, Line, Rect, SvgText } = primitives();
44
46
 
@@ -1,7 +1,8 @@
1
1
  import { useState } from "react";
2
2
 
3
3
  import { colors } from "../internal/tokens";
4
- import { primitives } from "./primitives";
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 NativeFunnelStage {
@@ -35,12 +36,13 @@ export function NativeFunnelChart({
35
36
  width = 320,
36
37
  stageHeight = 38,
37
38
  baseline,
38
- isDark = false,
39
+ isDark: isDarkProp,
39
40
  palette,
40
41
  style,
41
42
  onStagePress,
42
43
  }: NativeFunnelChartProps) {
43
44
  const [active, setActive] = useState<number | null>(null);
45
+ const isDark = useIsDark(isDarkProp);
44
46
  const theme = isDark ? colors.dark : colors.light;
45
47
  const { View, Text, Pressable } = primitives();
46
48
 
@@ -1,7 +1,8 @@
1
1
  import { useState } from "react";
2
2
 
3
3
  import { colors } from "../internal/tokens";
4
- import { primitives } from "./primitives";
4
+ import { useIsDark } from "../internal/motion";
5
+ import { primitives } from "../internal/primitives";
5
6
  import { formatValue } from "./scales";
6
7
 
7
8
  export interface NativeHeatmapChartProps {
@@ -46,13 +47,14 @@ export function NativeHeatmapChart({
46
47
  columns,
47
48
  cellSize = 28,
48
49
  cellGap = 3,
49
- isDark = false,
50
+ isDark: isDarkProp,
50
51
  minColor = "#e8eef7",
51
52
  maxColor = "#0088ff",
52
53
  style,
53
54
  onCellPress,
54
55
  }: NativeHeatmapChartProps) {
55
56
  const [active, setActive] = useState<{ r: number; c: number } | null>(null);
57
+ const isDark = useIsDark(isDarkProp);
56
58
  const theme = isDark ? colors.dark : colors.light;
57
59
  const { View, Text, Pressable } = primitives();
58
60
 
@@ -1,7 +1,8 @@
1
1
  import { useMemo, useState } from "react";
2
2
 
3
3
  import { colors, radii } from "../internal/tokens";
4
- import { primitives } from "./primitives";
4
+ import { useIsDark } from "../internal/motion";
5
+ import { primitives } from "../internal/primitives";
5
6
  import {
6
7
  bandScale,
7
8
  formatValue,
@@ -53,12 +54,13 @@ export function NativeLineChart({
53
54
  area = false,
54
55
  smooth = true,
55
56
  showDots = false,
56
- isDark = false,
57
+ isDark: isDarkProp,
57
58
  palette,
58
59
  style,
59
60
  onPointPress,
60
61
  }: NativeLineChartProps) {
61
62
  const [active, setActive] = useState<number | null>(null);
63
+ const isDark = useIsDark(isDarkProp);
62
64
  const theme = isDark ? colors.dark : colors.light;
63
65
  const { View, Text, Pressable, Svg, G, Line, Path, Circle, SvgText } = primitives();
64
66
 
@@ -1,7 +1,8 @@
1
1
  import { useMemo, useState } from "react";
2
2
 
3
3
  import { colors } from "../internal/tokens";
4
- import { primitives } from "./primitives";
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 = false,
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 style={style}>
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 { primitives } from "./primitives";
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 = false,
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
 
@@ -1,7 +1,8 @@
1
1
  import { useState } from "react";
2
2
 
3
3
  import { colors } from "../internal/tokens";
4
- import { primitives } from "./primitives";
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 = false,
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 { primitives } from "./primitives";
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 = false,
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 style={style}>
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 { primitives } from "./primitives";
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 = false,
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 style={style}>
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";
@@ -1,7 +1,8 @@
1
1
  import { useMemo, useState } from "react";
2
2
 
3
3
  import { colors } from "../internal/tokens";
4
- import { primitives } from "./primitives";
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 = false,
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 = false,
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 = false,
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 = false,
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 = false,
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
 
@@ -1,7 +1,8 @@
1
1
  import { useState } from "react";
2
2
 
3
3
  import { colors } from "../internal/tokens";
4
- import { primitives } from "./primitives";
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 = false,
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 = false,
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