panelui-native 0.112.1 → 0.113.1
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/README.md +2 -2
- package/lib/module/components/area-chart/index.js +3 -1
- package/lib/module/components/area-chart/index.js.map +1 -1
- package/lib/module/components/bar-chart/index.js +3 -1
- package/lib/module/components/bar-chart/index.js.map +1 -1
- package/lib/module/components/bottom-sheet/index.js +11 -0
- package/lib/module/components/bottom-sheet/index.js.map +1 -1
- package/lib/module/components/bubble-chart/index.js +5 -1
- package/lib/module/components/bubble-chart/index.js.map +1 -1
- package/lib/module/components/bump-chart/index.js +3 -1
- package/lib/module/components/bump-chart/index.js.map +1 -1
- package/lib/module/components/candlestick-chart/index.js +3 -1
- package/lib/module/components/candlestick-chart/index.js.map +1 -1
- package/lib/module/components/heatmap-chart/index.js +32 -7
- package/lib/module/components/heatmap-chart/index.js.map +1 -1
- package/lib/module/components/image-viewer/index.js +6 -1
- package/lib/module/components/image-viewer/index.js.map +1 -1
- package/lib/module/components/line-chart/index.js +3 -1
- package/lib/module/components/line-chart/index.js.map +1 -1
- package/lib/module/components/live-line-chart/index.js +3 -0
- package/lib/module/components/live-line-chart/index.js.map +1 -1
- package/lib/module/components/mirror-area-chart/index.js +3 -1
- package/lib/module/components/mirror-area-chart/index.js.map +1 -1
- package/lib/module/components/plot/index.js +3 -1
- package/lib/module/components/plot/index.js.map +1 -1
- package/lib/module/components/pyramid-chart/index.js +4 -1
- package/lib/module/components/pyramid-chart/index.js.map +1 -1
- package/lib/module/components/scatter-chart/index.js +3 -1
- package/lib/module/components/scatter-chart/index.js.map +1 -1
- package/lib/module/components/waterfall-chart/index.js +3 -1
- package/lib/module/components/waterfall-chart/index.js.map +1 -1
- package/lib/module/primitives/chart-accessibility.js +8 -0
- package/lib/module/primitives/chart-accessibility.js.map +1 -1
- package/lib/module/primitives/portal-store.js +79 -0
- package/lib/module/primitives/portal-store.js.map +1 -0
- package/lib/module/primitives/portal.js +21 -30
- package/lib/module/primitives/portal.js.map +1 -1
- package/lib/typescript/src/components/area-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bar-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bubble-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bump-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/candlestick-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/heatmap-chart/index.d.ts +5 -2
- package/lib/typescript/src/components/heatmap-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/image-viewer/index.d.ts.map +1 -1
- package/lib/typescript/src/components/line-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/live-line-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/mirror-area-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/plot/index.d.ts.map +1 -1
- package/lib/typescript/src/components/pyramid-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/scatter-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/waterfall-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/primitives/chart-accessibility.d.ts +7 -0
- package/lib/typescript/src/primitives/chart-accessibility.d.ts.map +1 -1
- package/lib/typescript/src/primitives/portal-store.d.ts +40 -0
- package/lib/typescript/src/primitives/portal-store.d.ts.map +1 -0
- package/lib/typescript/src/primitives/portal.d.ts.map +1 -1
- package/package.json +11 -1
- package/src/components/area-chart/index.tsx +13 -2
- package/src/components/bar-chart/index.tsx +7 -2
- package/src/components/bottom-sheet/index.tsx +22 -1
- package/src/components/bubble-chart/index.tsx +17 -2
- package/src/components/bump-chart/index.tsx +13 -2
- package/src/components/candlestick-chart/index.tsx +14 -2
- package/src/components/heatmap-chart/index.tsx +46 -7
- package/src/components/image-viewer/index.tsx +4 -0
- package/src/components/line-chart/index.tsx +13 -2
- package/src/components/live-line-chart/index.tsx +13 -2
- package/src/components/mirror-area-chart/index.tsx +7 -1
- package/src/components/plot/index.tsx +13 -2
- package/src/components/pyramid-chart/index.tsx +10 -2
- package/src/components/scatter-chart/index.tsx +13 -2
- package/src/components/waterfall-chart/index.tsx +7 -2
- package/src/primitives/chart-accessibility.ts +8 -0
- package/src/primitives/portal-store.ts +94 -0
- package/src/primitives/portal.tsx +21 -36
|
@@ -48,7 +48,13 @@ import {
|
|
|
48
48
|
useState,
|
|
49
49
|
type ReactNode,
|
|
50
50
|
} from 'react';
|
|
51
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
StyleSheet,
|
|
53
|
+
useWindowDimensions,
|
|
54
|
+
View,
|
|
55
|
+
type LayoutChangeEvent,
|
|
56
|
+
type ViewProps,
|
|
57
|
+
} from 'react-native';
|
|
52
58
|
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
53
59
|
import Animated, {
|
|
54
60
|
Easing,
|
|
@@ -62,7 +68,11 @@ import Animated, {
|
|
|
62
68
|
import Svg, { G, Line as SvgLine, Rect } from 'react-native-svg';
|
|
63
69
|
import { useCSSVariable } from 'uniwind';
|
|
64
70
|
import { Text } from '../../primitives/text';
|
|
65
|
-
import {
|
|
71
|
+
import {
|
|
72
|
+
CHART_AXIS_MAX_FONT_SCALE,
|
|
73
|
+
ChartAccessibilityData,
|
|
74
|
+
type ChartAccessibilityProps,
|
|
75
|
+
} from '../../primitives/chart-accessibility';
|
|
66
76
|
import { cn } from '../../utils/cn';
|
|
67
77
|
import { normalizeWeekStart, startOfDay } from '../../utils/date';
|
|
68
78
|
|
|
@@ -89,6 +99,20 @@ function isToken(value: string | undefined): value is string {
|
|
|
89
99
|
/** Room left for the weekday labels when the y-axis does not ask for its own. */
|
|
90
100
|
const DEFAULT_AXIS_WIDTH = 26;
|
|
91
101
|
|
|
102
|
+
/** Height of the month row at the default text size: one line of `xs` text. */
|
|
103
|
+
const X_AXIS_HEIGHT = 16;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* How much larger than default the axis labels are drawn, from 1 up to the
|
|
107
|
+
* axis cap. The heatmap's gutters are only just wide enough for a weekday at
|
|
108
|
+
* the default size, so they grow by the same factor or a larger label wraps
|
|
109
|
+
* and runs into the cells. Below the default size they stay put.
|
|
110
|
+
*/
|
|
111
|
+
function useAxisLabelScale() {
|
|
112
|
+
const { fontScale } = useWindowDimensions();
|
|
113
|
+
return Math.min(Math.max(fontScale, 1), CHART_AXIS_MAX_FONT_SCALE);
|
|
114
|
+
}
|
|
115
|
+
|
|
92
116
|
/**
|
|
93
117
|
* Height assumed for the readout when placing it above a cell. It is a single
|
|
94
118
|
* line of `xs` text in a padded box, so it does not vary — and measuring it
|
|
@@ -432,9 +456,12 @@ const HeatmapChartRoot = forwardRef<View, HeatmapChartProps>(function HeatmapCha
|
|
|
432
456
|
(typeof emptyToken === 'string' ? emptyToken : 'rgba(128,128,128,0.16)');
|
|
433
457
|
|
|
434
458
|
const parts = useMemo(() => splitParts(children), [children]);
|
|
459
|
+
const labelScale = useAxisLabelScale();
|
|
435
460
|
// The y-axis is laid out beside the grid rather than over it, so its width
|
|
436
461
|
// has to come out of the grid's before the cells are sized.
|
|
437
|
-
const axisWidth = parts.y
|
|
462
|
+
const axisWidth = parts.y
|
|
463
|
+
? (parts.y.props.width ?? Math.ceil(DEFAULT_AXIS_WIDTH * labelScale))
|
|
464
|
+
: 0;
|
|
438
465
|
|
|
439
466
|
const grid = useMemo<Grid>(() => {
|
|
440
467
|
const count = data.length;
|
|
@@ -836,6 +863,7 @@ export interface HeatmapXAxisProps {
|
|
|
836
863
|
function HeatmapXAxis({ className, formatLabel, labels: given }: HeatmapXAxisProps) {
|
|
837
864
|
const { data, grid } = useHeatmap('HeatmapChart.XAxis');
|
|
838
865
|
const step = grid.size + grid.gap;
|
|
866
|
+
const scale = useAxisLabelScale();
|
|
839
867
|
|
|
840
868
|
const labels = useMemo(() => {
|
|
841
869
|
if (given) {
|
|
@@ -865,7 +893,10 @@ function HeatmapXAxis({ className, formatLabel, labels: given }: HeatmapXAxisPro
|
|
|
865
893
|
}, [data, formatLabel, given]);
|
|
866
894
|
|
|
867
895
|
return (
|
|
868
|
-
<View
|
|
896
|
+
<View
|
|
897
|
+
className={cn('h-4', className)}
|
|
898
|
+
style={[{ width: grid.width }, scale > 1 && { height: Math.ceil(X_AXIS_HEIGHT * scale) }]}
|
|
899
|
+
>
|
|
869
900
|
{labels.map(({ column, label }) => (
|
|
870
901
|
<Text
|
|
871
902
|
key={`${column}-${label}`}
|
|
@@ -873,6 +904,7 @@ function HeatmapXAxis({ className, formatLabel, labels: given }: HeatmapXAxisPro
|
|
|
873
904
|
muted
|
|
874
905
|
className="absolute"
|
|
875
906
|
style={{ left: column * step }}
|
|
907
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
876
908
|
>
|
|
877
909
|
{label}
|
|
878
910
|
</Text>
|
|
@@ -884,7 +916,10 @@ HeatmapXAxis.slot = 'x-axis' as Slot;
|
|
|
884
916
|
|
|
885
917
|
export interface HeatmapYAxisProps {
|
|
886
918
|
className?: string;
|
|
887
|
-
/**
|
|
919
|
+
/**
|
|
920
|
+
* Width reserved for the labels. The grid is sized around it. Defaults to 26,
|
|
921
|
+
* and widens with the system text size so a larger weekday does not wrap.
|
|
922
|
+
*/
|
|
888
923
|
width?: number;
|
|
889
924
|
/** Which rows get a label. Every other row is the usual choice. */
|
|
890
925
|
tickFilter?: 'all' | 'odd' | 'even';
|
|
@@ -900,13 +935,15 @@ export interface HeatmapYAxisProps {
|
|
|
900
935
|
/** Weekday labels down the left of the grid. */
|
|
901
936
|
function HeatmapYAxis({
|
|
902
937
|
className,
|
|
903
|
-
width
|
|
938
|
+
width: widthProp,
|
|
904
939
|
tickFilter = 'odd',
|
|
905
940
|
labelFormat = 'full',
|
|
906
941
|
labels,
|
|
907
942
|
}: HeatmapYAxisProps) {
|
|
908
943
|
const { grid, weekStartDay } = useHeatmap('HeatmapChart.YAxis');
|
|
909
944
|
const step = grid.size + grid.gap;
|
|
945
|
+
const scale = useAxisLabelScale();
|
|
946
|
+
const width = widthProp ?? Math.ceil(DEFAULT_AXIS_WIDTH * scale);
|
|
910
947
|
|
|
911
948
|
return (
|
|
912
949
|
<View className={className} style={{ width, height: grid.height }}>
|
|
@@ -922,10 +959,12 @@ function HeatmapYAxis({
|
|
|
922
959
|
key={row}
|
|
923
960
|
size="xs"
|
|
924
961
|
muted
|
|
962
|
+
numberOfLines={1}
|
|
925
963
|
className="absolute"
|
|
926
964
|
// Centred on the cell rather than aligned to its top edge, so a
|
|
927
965
|
// label reads as belonging to the row it sits beside.
|
|
928
|
-
style={{ top: row * step + grid.size / 2 - 7 }}
|
|
966
|
+
style={{ top: row * step + grid.size / 2 - 7 * scale }}
|
|
967
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
929
968
|
>
|
|
930
969
|
{labels
|
|
931
970
|
? name
|
|
@@ -1084,6 +1084,10 @@ function ViewerOverlay({
|
|
|
1084
1084
|
return (
|
|
1085
1085
|
<View
|
|
1086
1086
|
style={StyleSheet.absoluteFill}
|
|
1087
|
+
// Mounted until the picture is back in the page, which is after `open`
|
|
1088
|
+
// has gone false. Taking touches for that flight swallowed the first tap
|
|
1089
|
+
// on the screen behind it.
|
|
1090
|
+
pointerEvents={open ? 'auto' : 'none'}
|
|
1087
1091
|
accessibilityViewIsModal
|
|
1088
1092
|
onAccessibilityEscape={onRequestClose}
|
|
1089
1093
|
>
|
|
@@ -80,7 +80,11 @@ import Svg, {
|
|
|
80
80
|
} from 'react-native-svg';
|
|
81
81
|
import { useCSSVariable } from 'uniwind';
|
|
82
82
|
import { Text } from '../../primitives/text';
|
|
83
|
-
import {
|
|
83
|
+
import {
|
|
84
|
+
CHART_AXIS_MAX_FONT_SCALE,
|
|
85
|
+
ChartAccessibilityData,
|
|
86
|
+
type ChartAccessibilityProps,
|
|
87
|
+
} from '../../primitives/chart-accessibility';
|
|
84
88
|
import {
|
|
85
89
|
areaPath,
|
|
86
90
|
columnValues,
|
|
@@ -870,6 +874,7 @@ function LineChartXAxis({ ticks = 4, format, className }: LineChartXAxisProps) {
|
|
|
870
874
|
width: POINT_LABEL_WIDTH,
|
|
871
875
|
textAlign: 'center',
|
|
872
876
|
}}
|
|
877
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
873
878
|
>
|
|
874
879
|
{label.text}
|
|
875
880
|
</Text>
|
|
@@ -930,7 +935,13 @@ function LineChartYAxis({ ticks = 4, format, className }: LineChartYAxisProps) {
|
|
|
930
935
|
className={cn('items-end justify-between', className)}
|
|
931
936
|
>
|
|
932
937
|
{labels.map((label) => (
|
|
933
|
-
<Text
|
|
938
|
+
<Text
|
|
939
|
+
key={label.key}
|
|
940
|
+
size="xs"
|
|
941
|
+
muted
|
|
942
|
+
numberOfLines={1}
|
|
943
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
944
|
+
>
|
|
934
945
|
{label.text}
|
|
935
946
|
</Text>
|
|
936
947
|
))}
|
|
@@ -93,6 +93,7 @@ import Svg, {
|
|
|
93
93
|
Line as SvgLine,
|
|
94
94
|
} from 'react-native-svg';
|
|
95
95
|
import { useCSSVariable } from 'uniwind';
|
|
96
|
+
import { CHART_AXIS_MAX_FONT_SCALE } from '../../primitives/chart-accessibility';
|
|
96
97
|
import { Text } from '../../primitives/text';
|
|
97
98
|
import {
|
|
98
99
|
compactNumber,
|
|
@@ -1027,7 +1028,12 @@ function LiveLineChartXAxis({ ticks = 4, formatTick, className }: LiveLineChartX
|
|
|
1027
1028
|
}}
|
|
1028
1029
|
className={cn('items-center', className)}
|
|
1029
1030
|
>
|
|
1030
|
-
<Text
|
|
1031
|
+
<Text
|
|
1032
|
+
size="xs"
|
|
1033
|
+
muted
|
|
1034
|
+
numberOfLines={1}
|
|
1035
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
1036
|
+
>
|
|
1031
1037
|
{format(seconds * (1 - fraction))}
|
|
1032
1038
|
</Text>
|
|
1033
1039
|
</View>
|
|
@@ -1082,7 +1088,12 @@ function LiveLineChartYAxis({ ticks = 4, formatValue, className }: LiveLineChart
|
|
|
1082
1088
|
}}
|
|
1083
1089
|
className={cn('items-end', className)}
|
|
1084
1090
|
>
|
|
1085
|
-
<Text
|
|
1091
|
+
<Text
|
|
1092
|
+
size="xs"
|
|
1093
|
+
muted
|
|
1094
|
+
numberOfLines={1}
|
|
1095
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
1096
|
+
>
|
|
1086
1097
|
{format(max - (max - min) * fraction)}
|
|
1087
1098
|
</Text>
|
|
1088
1099
|
</View>
|
|
@@ -64,7 +64,11 @@ import Svg, {
|
|
|
64
64
|
} from 'react-native-svg';
|
|
65
65
|
import { useCSSVariable } from 'uniwind';
|
|
66
66
|
import { Text } from '../../primitives/text';
|
|
67
|
-
import {
|
|
67
|
+
import {
|
|
68
|
+
CHART_AXIS_MAX_FONT_SCALE,
|
|
69
|
+
ChartAccessibilityData,
|
|
70
|
+
type ChartAccessibilityProps,
|
|
71
|
+
} from '../../primitives/chart-accessibility';
|
|
68
72
|
import { finiteChartDomain } from '../../primitives/finite-chart';
|
|
69
73
|
import {
|
|
70
74
|
colorStop,
|
|
@@ -934,6 +938,7 @@ function MirrorAreaChartXAxis({ ticks = 4, format, className }: MirrorAreaChartX
|
|
|
934
938
|
width: POINT_LABEL_WIDTH,
|
|
935
939
|
textAlign: 'center',
|
|
936
940
|
}}
|
|
941
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
937
942
|
>
|
|
938
943
|
{label.text}
|
|
939
944
|
</Text>
|
|
@@ -984,6 +989,7 @@ function MirrorAreaChartYAxis({ formatTop, formatBottom, className }: MirrorArea
|
|
|
984
989
|
width,
|
|
985
990
|
textAlign: 'right',
|
|
986
991
|
}}
|
|
992
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
987
993
|
>
|
|
988
994
|
{label.text}
|
|
989
995
|
</Text>
|
|
@@ -96,7 +96,11 @@ import Svg, {
|
|
|
96
96
|
Rect,
|
|
97
97
|
} from 'react-native-svg';
|
|
98
98
|
import { useCSSVariable } from 'uniwind';
|
|
99
|
-
import {
|
|
99
|
+
import {
|
|
100
|
+
CHART_AXIS_MAX_FONT_SCALE,
|
|
101
|
+
ChartAccessibilityData,
|
|
102
|
+
type ChartAccessibilityProps,
|
|
103
|
+
} from '../../primitives/chart-accessibility';
|
|
100
104
|
import { Text } from '../../primitives/text';
|
|
101
105
|
import { finiteChartNumber } from '../../primitives/finite-chart';
|
|
102
106
|
import {
|
|
@@ -1371,6 +1375,7 @@ function PlotXAxis({ ticks = 4, format, className }: PlotXAxisProps) {
|
|
|
1371
1375
|
width: POINT_LABEL_WIDTH,
|
|
1372
1376
|
textAlign: 'center',
|
|
1373
1377
|
}}
|
|
1378
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
1374
1379
|
>
|
|
1375
1380
|
{label.text}
|
|
1376
1381
|
</Text>
|
|
@@ -1429,7 +1434,13 @@ function PlotYAxis({ ticks = 4, format, className }: PlotYAxisProps) {
|
|
|
1429
1434
|
className={cn('items-end justify-between', className)}
|
|
1430
1435
|
>
|
|
1431
1436
|
{labels.map((label) => (
|
|
1432
|
-
<Text
|
|
1437
|
+
<Text
|
|
1438
|
+
key={label.key}
|
|
1439
|
+
size="xs"
|
|
1440
|
+
muted
|
|
1441
|
+
numberOfLines={1}
|
|
1442
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
1443
|
+
>
|
|
1433
1444
|
{label.text}
|
|
1434
1445
|
</Text>
|
|
1435
1446
|
))}
|
|
@@ -80,6 +80,7 @@ import Animated, {
|
|
|
80
80
|
import Svg, { Defs, G, Line as SvgLine, LinearGradient, Path, Stop } from 'react-native-svg';
|
|
81
81
|
import { useCSSVariable } from 'uniwind';
|
|
82
82
|
import {
|
|
83
|
+
CHART_AXIS_MAX_FONT_SCALE,
|
|
83
84
|
ChartAccessibilityData,
|
|
84
85
|
type ChartAccessibilityProps,
|
|
85
86
|
} from '../../primitives/chart-accessibility';
|
|
@@ -956,6 +957,7 @@ function PyramidChartXAxis({ ticks = 2, format, className }: PyramidChartXAxisPr
|
|
|
956
957
|
width: AXIS_LABEL_WIDTH,
|
|
957
958
|
textAlign: 'center',
|
|
958
959
|
}}
|
|
960
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
959
961
|
>
|
|
960
962
|
{label.text}
|
|
961
963
|
</Text>
|
|
@@ -1013,7 +1015,13 @@ function PyramidChartYAxis({ format, className }: PyramidChartYAxisProps) {
|
|
|
1013
1015
|
}}
|
|
1014
1016
|
className="justify-center"
|
|
1015
1017
|
>
|
|
1016
|
-
<Text
|
|
1018
|
+
<Text
|
|
1019
|
+
size="xs"
|
|
1020
|
+
muted
|
|
1021
|
+
numberOfLines={1}
|
|
1022
|
+
style={{ textAlign: 'center' }}
|
|
1023
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
1024
|
+
>
|
|
1017
1025
|
{label(datum, index)}
|
|
1018
1026
|
</Text>
|
|
1019
1027
|
</View>
|
|
@@ -1037,7 +1045,7 @@ function PyramidChartYAxis({ format, className }: PyramidChartYAxisProps) {
|
|
|
1037
1045
|
>
|
|
1038
1046
|
{data.map((datum, index) => (
|
|
1039
1047
|
<View key={index} className="flex-1 justify-center">
|
|
1040
|
-
<Text size="xs" muted numberOfLines={1}>
|
|
1048
|
+
<Text size="xs" muted numberOfLines={1} maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}>
|
|
1041
1049
|
{label(datum, index)}
|
|
1042
1050
|
</Text>
|
|
1043
1051
|
</View>
|
|
@@ -67,7 +67,11 @@ import Animated, {
|
|
|
67
67
|
import Svg, { Circle, G, Line as SvgLine } from 'react-native-svg';
|
|
68
68
|
import { useCSSVariable } from 'uniwind';
|
|
69
69
|
import { Text } from '../../primitives/text';
|
|
70
|
-
import {
|
|
70
|
+
import {
|
|
71
|
+
CHART_AXIS_MAX_FONT_SCALE,
|
|
72
|
+
ChartAccessibilityData,
|
|
73
|
+
type ChartAccessibilityProps,
|
|
74
|
+
} from '../../primitives/chart-accessibility';
|
|
71
75
|
import { compactNumber, useSeriesColor, xAt, yOf, type Plot } from '../../utils/chart';
|
|
72
76
|
import { cn } from '../../utils/cn';
|
|
73
77
|
import { useSkeletonHandoff } from '../../hooks/use-skeleton-handoff';
|
|
@@ -957,6 +961,7 @@ function ScatterChartXAxis({ ticks = 4, format, className }: ScatterChartXAxisPr
|
|
|
957
961
|
width: POINT_LABEL_WIDTH,
|
|
958
962
|
textAlign: 'center',
|
|
959
963
|
}}
|
|
964
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
960
965
|
>
|
|
961
966
|
{label.text}
|
|
962
967
|
</Text>
|
|
@@ -1004,7 +1009,13 @@ function ScatterChartYAxis({ ticks = 4, format, className }: ScatterChartYAxisPr
|
|
|
1004
1009
|
className={cn('items-end justify-between', className)}
|
|
1005
1010
|
>
|
|
1006
1011
|
{labels.map((label) => (
|
|
1007
|
-
<Text
|
|
1012
|
+
<Text
|
|
1013
|
+
key={label.key}
|
|
1014
|
+
size="xs"
|
|
1015
|
+
muted
|
|
1016
|
+
numberOfLines={1}
|
|
1017
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
1018
|
+
>
|
|
1008
1019
|
{label.text}
|
|
1009
1020
|
</Text>
|
|
1010
1021
|
))}
|
|
@@ -66,7 +66,11 @@ import Animated, {
|
|
|
66
66
|
} from 'react-native-reanimated';
|
|
67
67
|
import Svg, { Defs, G, Line as SvgLine, LinearGradient, Path, Stop } from 'react-native-svg';
|
|
68
68
|
import { useCSSVariable } from 'uniwind';
|
|
69
|
-
import {
|
|
69
|
+
import {
|
|
70
|
+
CHART_AXIS_MAX_FONT_SCALE,
|
|
71
|
+
ChartAccessibilityData,
|
|
72
|
+
type ChartAccessibilityProps,
|
|
73
|
+
} from '../../primitives/chart-accessibility';
|
|
70
74
|
import { Text } from '../../primitives/text';
|
|
71
75
|
import {
|
|
72
76
|
finiteChartDomain,
|
|
@@ -1142,6 +1146,7 @@ function WaterfallChartXAxis({ ticks, format, className }: WaterfallChartXAxisPr
|
|
|
1142
1146
|
width: bandWidth,
|
|
1143
1147
|
textAlign: 'center',
|
|
1144
1148
|
}}
|
|
1149
|
+
maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
|
|
1145
1150
|
>
|
|
1146
1151
|
{label.text}
|
|
1147
1152
|
</Text>
|
|
@@ -1209,7 +1214,7 @@ function WaterfallChartYAxis({ ticks = 4, format, className }: WaterfallChartYAx
|
|
|
1209
1214
|
>
|
|
1210
1215
|
{labels.map((label) => (
|
|
1211
1216
|
<View key={label.key} className={horizontal ? 'flex-1 justify-center' : undefined}>
|
|
1212
|
-
<Text size="xs" muted numberOfLines={1}>
|
|
1217
|
+
<Text size="xs" muted numberOfLines={1} maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}>
|
|
1213
1218
|
{label.text}
|
|
1214
1219
|
</Text>
|
|
1215
1220
|
</View>
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* The largest text scale a chart's axis labels follow: iOS's biggest size before
|
|
5
|
+
* the accessibility range. Axis labels sit in fixed-width gutters at fixed
|
|
6
|
+
* steps, so past this they overlap each other or clip. Screen readers still get
|
|
7
|
+
* every value through the chart's accessibility data.
|
|
8
|
+
*/
|
|
9
|
+
export const CHART_AXIS_MAX_FONT_SCALE = 1.353;
|
|
10
|
+
|
|
3
11
|
export interface ChartAccessibilityProps<Datum> {
|
|
4
12
|
/** Spoken summary. Defaults to the chart family and number of data entries. */
|
|
5
13
|
accessibilityLabel?: string;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/** One portal's content, and whether it is on its way out. */
|
|
4
|
+
export interface PortalEntry {
|
|
5
|
+
node: ReactNode;
|
|
6
|
+
/**
|
|
7
|
+
* Set for the one frame between the owner going away and the content being
|
|
8
|
+
* removed. The host stops the entry taking touches while it is set.
|
|
9
|
+
*/
|
|
10
|
+
leaving: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type PortalMap = ReadonlyMap<string, PortalEntry>;
|
|
14
|
+
|
|
15
|
+
/** Runs `callback` on a later frame and returns a function that cancels it. */
|
|
16
|
+
export type PortalScheduler = (callback: () => void) => () => void;
|
|
17
|
+
|
|
18
|
+
const nextFrame: PortalScheduler = (callback) => {
|
|
19
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
20
|
+
const id = requestAnimationFrame(callback);
|
|
21
|
+
return () => cancelAnimationFrame(id);
|
|
22
|
+
}
|
|
23
|
+
const id = setTimeout(callback, 16);
|
|
24
|
+
return () => clearTimeout(id);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What every portal has put on screen, keyed by portal.
|
|
29
|
+
*
|
|
30
|
+
* Removal takes two commits rather than one. An overlay's views usually carry
|
|
31
|
+
* an `exiting` animation, and Reanimated keeps a removed view on screen until
|
|
32
|
+
* that animation ends. The view keeps the props it had when it was removed but
|
|
33
|
+
* not its handlers, so a full-screen backdrop left fading out takes every touch
|
|
34
|
+
* and does nothing with it: a tap on the button that opened the overlay is
|
|
35
|
+
* simply lost. So `unmount` first marks the entry `leaving`, which the host
|
|
36
|
+
* turns into `pointerEvents="none"`, and removes it a frame later. Whatever
|
|
37
|
+
* stays behind to animate has already stopped taking touches.
|
|
38
|
+
*/
|
|
39
|
+
export class PortalStore {
|
|
40
|
+
private portals = new Map<string, PortalEntry>();
|
|
41
|
+
private snapshot: PortalMap = this.portals;
|
|
42
|
+
private listeners = new Set<() => void>();
|
|
43
|
+
private pending = new Map<string, () => void>();
|
|
44
|
+
private schedule: PortalScheduler;
|
|
45
|
+
|
|
46
|
+
constructor(schedule: PortalScheduler = nextFrame) {
|
|
47
|
+
this.schedule = schedule;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
mount = (key: string, node: ReactNode) => {
|
|
51
|
+
// A remount inside the leaving frame (StrictMode, or a quick reopen) keeps
|
|
52
|
+
// the entry instead of losing it to the removal already scheduled.
|
|
53
|
+
this.cancel(key);
|
|
54
|
+
this.portals.set(key, { node, leaving: false });
|
|
55
|
+
this.emit();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
unmount = (key: string) => {
|
|
59
|
+
const entry = this.portals.get(key);
|
|
60
|
+
if (!entry || entry.leaving) return;
|
|
61
|
+
this.portals.set(key, { node: entry.node, leaving: true });
|
|
62
|
+
this.emit();
|
|
63
|
+
this.pending.set(
|
|
64
|
+
key,
|
|
65
|
+
this.schedule(() => {
|
|
66
|
+
this.pending.delete(key);
|
|
67
|
+
if (!this.portals.get(key)?.leaving) return;
|
|
68
|
+
this.portals.delete(key);
|
|
69
|
+
this.emit();
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
subscribe = (listener: () => void) => {
|
|
75
|
+
this.listeners.add(listener);
|
|
76
|
+
return () => {
|
|
77
|
+
this.listeners.delete(listener);
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
getSnapshot = (): PortalMap => this.snapshot;
|
|
82
|
+
|
|
83
|
+
private cancel(key: string) {
|
|
84
|
+
const cancel = this.pending.get(key);
|
|
85
|
+
if (!cancel) return;
|
|
86
|
+
cancel();
|
|
87
|
+
this.pending.delete(key);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private emit() {
|
|
91
|
+
this.snapshot = new Map(this.portals);
|
|
92
|
+
this.listeners.forEach((listener) => listener());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -7,39 +7,11 @@ import {
|
|
|
7
7
|
useSyncExternalStore,
|
|
8
8
|
type ReactNode,
|
|
9
9
|
} from 'react';
|
|
10
|
+
import { StyleSheet, View } from 'react-native';
|
|
10
11
|
import { ModalIsolationStore } from './modal-isolation-store';
|
|
12
|
+
import { PortalStore } from './portal-store';
|
|
11
13
|
import { captureFocusRestore, FocusRestorationStore } from './focus-restoration-store';
|
|
12
14
|
|
|
13
|
-
type PortalMap = ReadonlyMap<string, ReactNode>;
|
|
14
|
-
|
|
15
|
-
class PortalStore {
|
|
16
|
-
private portals = new Map<string, ReactNode>();
|
|
17
|
-
private snapshot: PortalMap = this.portals;
|
|
18
|
-
private listeners = new Set<() => void>();
|
|
19
|
-
|
|
20
|
-
mount = (key: string, node: ReactNode) => {
|
|
21
|
-
this.portals.set(key, node);
|
|
22
|
-
this.emit();
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
unmount = (key: string) => {
|
|
26
|
-
this.portals.delete(key);
|
|
27
|
-
this.emit();
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
subscribe = (listener: () => void) => {
|
|
31
|
-
this.listeners.add(listener);
|
|
32
|
-
return () => this.listeners.delete(listener);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
getSnapshot = (): PortalMap => this.snapshot;
|
|
36
|
-
|
|
37
|
-
private emit() {
|
|
38
|
-
this.snapshot = new Map(this.portals);
|
|
39
|
-
this.listeners.forEach((listener) => listener());
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
15
|
const PortalContext = createContext<PortalStore | null>(null);
|
|
44
16
|
const ModalIsolationContext = createContext<ModalIsolationStore | null>(null);
|
|
45
17
|
const FocusRestorationContext = createContext<FocusRestorationStore | null>(null);
|
|
@@ -154,13 +126,26 @@ export function PortalHost() {
|
|
|
154
126
|
|
|
155
127
|
return (
|
|
156
128
|
<>
|
|
157
|
-
{Array.from(portals.entries(), ([key, node]) => (
|
|
158
|
-
|
|
129
|
+
{Array.from(portals.entries(), ([key, { node, leaving }]) => (
|
|
130
|
+
/*
|
|
131
|
+
* Every entry sits in a full-screen layer from its first render, so the
|
|
132
|
+
* frame it is marked `leaving` changes one prop rather than remounting
|
|
133
|
+
* the content. `box-none` passes through wherever the content has
|
|
134
|
+
* nothing, which is how an open overlay already behaved. `none` is the
|
|
135
|
+
* frame before removal: views Reanimated keeps on screen to finish an
|
|
136
|
+
* exit animation then sit under a layer that takes no touches, so a tap
|
|
137
|
+
* on the screen behind reaches it. `collapsable` keeps the layer from
|
|
138
|
+
* being flattened away, since the prop has to live on a real view.
|
|
139
|
+
*/
|
|
140
|
+
<View
|
|
141
|
+
key={key}
|
|
142
|
+
collapsable={false}
|
|
143
|
+
pointerEvents={leaving ? 'none' : 'box-none'}
|
|
144
|
+
style={StyleSheet.absoluteFill}
|
|
145
|
+
>
|
|
146
|
+
{node}
|
|
147
|
+
</View>
|
|
159
148
|
))}
|
|
160
149
|
</>
|
|
161
150
|
);
|
|
162
151
|
}
|
|
163
|
-
|
|
164
|
-
function PortalFragment({ children }: { children: ReactNode }) {
|
|
165
|
-
return <>{children}</>;
|
|
166
|
-
}
|