panelui-native 1.2.0 → 1.3.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/components/area-chart/index.js +4 -1
- package/lib/module/components/area-chart/index.js.map +1 -1
- package/lib/module/components/bar-chart/index.js +4 -1
- package/lib/module/components/bar-chart/index.js.map +1 -1
- package/lib/module/components/bubble-chart/index.js +4 -1
- package/lib/module/components/bubble-chart/index.js.map +1 -1
- package/lib/module/components/bump-chart/index.js +4 -1
- package/lib/module/components/bump-chart/index.js.map +1 -1
- package/lib/module/components/candlestick-chart/index.js +4 -1
- package/lib/module/components/candlestick-chart/index.js.map +1 -1
- package/lib/module/components/combobox/index.js +23 -5
- package/lib/module/components/combobox/index.js.map +1 -1
- package/lib/module/components/heatmap-chart/index.js +4 -1
- package/lib/module/components/heatmap-chart/index.js.map +1 -1
- package/lib/module/components/line-chart/index.js +4 -1
- package/lib/module/components/line-chart/index.js.map +1 -1
- package/lib/module/components/live-line-chart/index.js +4 -1
- package/lib/module/components/live-line-chart/index.js.map +1 -1
- package/lib/module/components/mirror-area-chart/index.js +4 -1
- package/lib/module/components/mirror-area-chart/index.js.map +1 -1
- package/lib/module/components/plot/index.js +4 -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 +4 -1
- package/lib/module/components/scatter-chart/index.js.map +1 -1
- package/lib/module/components/scroll-blur/index.js +25 -7
- package/lib/module/components/scroll-blur/index.js.map +1 -1
- package/lib/module/components/scroll-header/index.js +44 -24
- package/lib/module/components/scroll-header/index.js.map +1 -1
- package/lib/module/components/select/index.js +23 -5
- package/lib/module/components/select/index.js.map +1 -1
- package/lib/module/components/switch/index.js +51 -15
- package/lib/module/components/switch/index.js.map +1 -1
- package/lib/module/components/toast/index.js +13 -3
- package/lib/module/components/toast/index.js.map +1 -1
- package/lib/module/components/waterfall-chart/index.js +4 -1
- package/lib/module/components/waterfall-chart/index.js.map +1 -1
- package/lib/module/components/week-hours-grid/index.js +187 -0
- package/lib/module/components/week-hours-grid/index.js.map +1 -0
- package/lib/module/components/week-strip/index.js +232 -0
- package/lib/module/components/week-strip/index.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/primitives/scrim.js +50 -2
- package/lib/module/primitives/scrim.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/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/combobox/index.d.ts +2 -1
- package/lib/typescript/src/components/combobox/index.d.ts.map +1 -1
- package/lib/typescript/src/components/heatmap-chart/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/scroll-blur/index.d.ts.map +1 -1
- package/lib/typescript/src/components/scroll-header/index.d.ts +4 -2
- package/lib/typescript/src/components/scroll-header/index.d.ts.map +1 -1
- package/lib/typescript/src/components/select/index.d.ts +2 -1
- package/lib/typescript/src/components/select/index.d.ts.map +1 -1
- package/lib/typescript/src/components/switch/index.d.ts +7 -0
- package/lib/typescript/src/components/switch/index.d.ts.map +1 -1
- package/lib/typescript/src/components/toast/index.d.ts +7 -2
- package/lib/typescript/src/components/toast/index.d.ts.map +1 -1
- package/lib/typescript/src/components/waterfall-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/week-hours-grid/index.d.ts +56 -0
- package/lib/typescript/src/components/week-hours-grid/index.d.ts.map +1 -0
- package/lib/typescript/src/components/week-strip/index.d.ts +173 -0
- package/lib/typescript/src/components/week-strip/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/primitives/scrim.d.ts +56 -2
- package/lib/typescript/src/primitives/scrim.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/area-chart/index.tsx +3 -1
- package/src/components/bar-chart/index.tsx +3 -1
- package/src/components/bubble-chart/index.tsx +3 -1
- package/src/components/bump-chart/index.tsx +3 -1
- package/src/components/candlestick-chart/index.tsx +3 -1
- package/src/components/combobox/index.tsx +23 -6
- package/src/components/heatmap-chart/index.tsx +3 -1
- package/src/components/line-chart/index.tsx +3 -1
- package/src/components/live-line-chart/index.tsx +3 -1
- package/src/components/mirror-area-chart/index.tsx +3 -1
- package/src/components/plot/index.tsx +3 -1
- package/src/components/pyramid-chart/index.tsx +3 -1
- package/src/components/scatter-chart/index.tsx +3 -1
- package/src/components/scroll-blur/index.tsx +32 -4
- package/src/components/scroll-header/index.tsx +63 -25
- package/src/components/select/index.tsx +23 -6
- package/src/components/switch/index.tsx +54 -5
- package/src/components/toast/index.tsx +24 -4
- package/src/components/waterfall-chart/index.tsx +3 -1
- package/src/components/week-hours-grid/index.tsx +238 -0
- package/src/components/week-strip/index.tsx +272 -0
- package/src/index.ts +15 -0
- package/src/primitives/scrim.tsx +56 -4
|
@@ -62,9 +62,11 @@ import {
|
|
|
62
62
|
Children,
|
|
63
63
|
isValidElement,
|
|
64
64
|
useMemo,
|
|
65
|
+
useRef,
|
|
65
66
|
type ComponentType,
|
|
66
67
|
type ReactElement,
|
|
67
68
|
type ReactNode,
|
|
69
|
+
type RefObject,
|
|
68
70
|
} from 'react';
|
|
69
71
|
import {
|
|
70
72
|
StyleSheet,
|
|
@@ -83,7 +85,12 @@ import Animated, {
|
|
|
83
85
|
type DerivedValue,
|
|
84
86
|
} from 'react-native-reanimated';
|
|
85
87
|
import { useCSSVariable } from 'uniwind';
|
|
86
|
-
import {
|
|
88
|
+
import {
|
|
89
|
+
androidBlurProps,
|
|
90
|
+
BlurTargetView,
|
|
91
|
+
canBlurHere,
|
|
92
|
+
useReduceTransparency,
|
|
93
|
+
} from '../../primitives/scrim';
|
|
87
94
|
import { useThemeMode } from '../../theme/use-theme';
|
|
88
95
|
|
|
89
96
|
/**
|
|
@@ -95,6 +102,8 @@ const BlurView: ComponentType<{
|
|
|
95
102
|
intensity?: number;
|
|
96
103
|
tint?: ScrollBlurTint;
|
|
97
104
|
style?: unknown;
|
|
105
|
+
blurMethod?: string;
|
|
106
|
+
blurTarget?: RefObject<View | null>;
|
|
98
107
|
}> | null = (() => {
|
|
99
108
|
try {
|
|
100
109
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
@@ -190,7 +199,11 @@ export function ScrollBlur({
|
|
|
190
199
|
* arriving a frame late costs nothing, while a blur flashed at somebody who
|
|
191
200
|
* switched Reduce Transparency on is the whole thing that setting is for.
|
|
192
201
|
*/
|
|
193
|
-
const blurring =
|
|
202
|
+
const blurring = canBlurHere && BlurView !== null && reduceTransparency === false;
|
|
203
|
+
// Android blurs only a view it is pointed at, so the scroller is wrapped in a
|
|
204
|
+
// target when there is a blur to draw over it.
|
|
205
|
+
const targetRef = useRef<View>(null);
|
|
206
|
+
const wantsTarget = blurring && BlurTargetView !== null;
|
|
194
207
|
const materialTint: ScrollBlurTint = material === 'default' ? mode : material;
|
|
195
208
|
|
|
196
209
|
const themeBackground = useCSSVariable('--color-background');
|
|
@@ -278,6 +291,7 @@ export function ScrollBlur({
|
|
|
278
291
|
}
|
|
279
292
|
|
|
280
293
|
const edgeProps = {
|
|
294
|
+
blurTarget: wantsTarget ? targetRef : null,
|
|
281
295
|
size,
|
|
282
296
|
horizontal,
|
|
283
297
|
layers: Math.max(1, Math.round(layers)),
|
|
@@ -290,7 +304,13 @@ export function ScrollBlur({
|
|
|
290
304
|
|
|
291
305
|
return (
|
|
292
306
|
<View {...props} className={className}>
|
|
293
|
-
{
|
|
307
|
+
{wantsTarget && BlurTargetView ? (
|
|
308
|
+
<BlurTargetView ref={targetRef} collapsable={false} style={{ flex: 1 }}>
|
|
309
|
+
{scrollable}
|
|
310
|
+
</BlurTargetView>
|
|
311
|
+
) : (
|
|
312
|
+
scrollable
|
|
313
|
+
)}
|
|
294
314
|
|
|
295
315
|
{edges !== 'end' ? (
|
|
296
316
|
<Edge {...edgeProps} opacity={startOpacity} edge="start" />
|
|
@@ -306,6 +326,7 @@ ScrollBlur.displayName = 'ScrollBlur';
|
|
|
306
326
|
|
|
307
327
|
/** One edge's band: the stack of blur views, and the wash that joins them up. */
|
|
308
328
|
function Edge({
|
|
329
|
+
blurTarget,
|
|
309
330
|
size,
|
|
310
331
|
horizontal,
|
|
311
332
|
layers,
|
|
@@ -317,6 +338,7 @@ function Edge({
|
|
|
317
338
|
opacity,
|
|
318
339
|
edge,
|
|
319
340
|
}: {
|
|
341
|
+
blurTarget: RefObject<View | null> | null;
|
|
320
342
|
size: number;
|
|
321
343
|
horizontal: boolean;
|
|
322
344
|
layers: number;
|
|
@@ -385,9 +407,15 @@ function Edge({
|
|
|
385
407
|
style={[{ position: 'absolute', opacity: step.opacity }, along(step.span)]}
|
|
386
408
|
>
|
|
387
409
|
<BlurView
|
|
388
|
-
|
|
410
|
+
// Elsewhere each layer blurs the layers under it, so the
|
|
411
|
+
// strength adds up towards the edge. Android's layers each
|
|
412
|
+
// blur the scroller itself, so each carries its own share.
|
|
413
|
+
intensity={
|
|
414
|
+
blurTarget ? (intensity * (step.key + 1)) / layers : intensity / layers
|
|
415
|
+
}
|
|
389
416
|
tint={material}
|
|
390
417
|
style={StyleSheet.absoluteFill}
|
|
418
|
+
{...androidBlurProps(blurTarget)}
|
|
391
419
|
/>
|
|
392
420
|
</View>
|
|
393
421
|
))
|
|
@@ -81,10 +81,12 @@ import {
|
|
|
81
81
|
useCallback,
|
|
82
82
|
useContext,
|
|
83
83
|
useMemo,
|
|
84
|
+
useRef,
|
|
84
85
|
useState,
|
|
85
86
|
type ComponentType,
|
|
86
87
|
type ReactNode,
|
|
87
88
|
type Ref,
|
|
89
|
+
type RefObject,
|
|
88
90
|
} from 'react';
|
|
89
91
|
import {
|
|
90
92
|
Image,
|
|
@@ -120,7 +122,12 @@ import Animated, {
|
|
|
120
122
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
121
123
|
import { tv, type VariantProps } from 'tailwind-variants';
|
|
122
124
|
import { useCSSVariable } from 'uniwind';
|
|
123
|
-
import {
|
|
125
|
+
import {
|
|
126
|
+
androidBlurProps,
|
|
127
|
+
BlurTargetView,
|
|
128
|
+
canBlurHere,
|
|
129
|
+
useReduceTransparency,
|
|
130
|
+
} from '../../primitives/scrim';
|
|
124
131
|
import { Text, textChildren, type TextProps } from '../../primitives/text';
|
|
125
132
|
import { useThemeMode } from '../../theme/use-theme';
|
|
126
133
|
import { cn } from '../../utils/cn';
|
|
@@ -164,6 +171,8 @@ const BlurView: ComponentType<{
|
|
|
164
171
|
intensity?: number;
|
|
165
172
|
tint?: ScrollHeaderMaterial;
|
|
166
173
|
style?: unknown;
|
|
174
|
+
blurMethod?: string;
|
|
175
|
+
blurTarget?: RefObject<View | null>;
|
|
167
176
|
}> | null = (() => {
|
|
168
177
|
try {
|
|
169
178
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
@@ -234,6 +243,11 @@ interface ScrollHeaderContextValue {
|
|
|
234
243
|
/** Whether there is a large block at all. A bar-only header has no crossing. */
|
|
235
244
|
hasLarge: boolean;
|
|
236
245
|
measureLarge: (event: LayoutChangeEvent) => void;
|
|
246
|
+
/**
|
|
247
|
+
* The view wrapping the scroller on Android, which a blurred bar samples.
|
|
248
|
+
* Null on other platforms, and when the bar is not blurred.
|
|
249
|
+
*/
|
|
250
|
+
blurTarget: RefObject<View | null> | null;
|
|
237
251
|
}
|
|
238
252
|
|
|
239
253
|
const ScrollHeaderContext = createContext<ScrollHeaderContextValue | undefined>(undefined);
|
|
@@ -500,35 +514,54 @@ const ScrollHeaderRoot = forwardRef<ViewRef, ScrollHeaderProps>(
|
|
|
500
514
|
|
|
501
515
|
const hasLarge = largeSize >= 1;
|
|
502
516
|
|
|
517
|
+
// Android blurs only a view it is pointed at, so a blurred bar needs the
|
|
518
|
+
// scroller wrapped in a target. Only then: the wrapper records every frame
|
|
519
|
+
// the scroller draws.
|
|
520
|
+
const targetRef = useRef<View>(null);
|
|
521
|
+
const wantsTarget =
|
|
522
|
+
BlurTargetView !== null &&
|
|
523
|
+
isValidElement(parts.bar) &&
|
|
524
|
+
(parts.bar.props as { surface?: ScrollHeaderSurface }).surface === 'blur';
|
|
525
|
+
const blurTarget = wantsTarget ? targetRef : null;
|
|
526
|
+
|
|
503
527
|
const context = useMemo<ScrollHeaderContextValue>(
|
|
504
|
-
() => ({ progress, offset, largeHeight, collapsed, hasLarge, measureLarge }),
|
|
505
|
-
[progress, offset, largeHeight, collapsed, hasLarge, measureLarge]
|
|
528
|
+
() => ({ progress, offset, largeHeight, collapsed, hasLarge, measureLarge, blurTarget }),
|
|
529
|
+
[progress, offset, largeHeight, collapsed, hasLarge, measureLarge, blurTarget]
|
|
506
530
|
);
|
|
507
531
|
|
|
508
532
|
const { root, band } = scrollHeaderVariants();
|
|
509
533
|
|
|
534
|
+
const scroller =
|
|
535
|
+
AnimatedScrollable && isValidElement(scrollable) ? (
|
|
536
|
+
<AnimatedScrollable
|
|
537
|
+
{...childProps}
|
|
538
|
+
ref={composeRefs(scrollRef, childProps.ref)}
|
|
539
|
+
onScroll={onScroll}
|
|
540
|
+
scrollEventThrottle={childProps.scrollEventThrottle ?? 16}
|
|
541
|
+
// The band is the inset. iOS would otherwise add one of its own
|
|
542
|
+
// on top of it, for a header it cannot see.
|
|
543
|
+
contentInsetAdjustmentBehavior={
|
|
544
|
+
childProps.contentInsetAdjustmentBehavior ?? 'never'
|
|
545
|
+
}
|
|
546
|
+
contentContainerStyle={[
|
|
547
|
+
childProps.contentContainerStyle,
|
|
548
|
+
{ paddingTop: headerHeight },
|
|
549
|
+
]}
|
|
550
|
+
scrollIndicatorInsets={{ top: barBand, ...childProps.scrollIndicatorInsets }}
|
|
551
|
+
/>
|
|
552
|
+
) : (
|
|
553
|
+
scrollable
|
|
554
|
+
);
|
|
555
|
+
|
|
510
556
|
return (
|
|
511
557
|
<ScrollHeaderContext.Provider value={context}>
|
|
512
558
|
<View {...props} ref={ref} className={root({ className })}>
|
|
513
|
-
{
|
|
514
|
-
<
|
|
515
|
-
{
|
|
516
|
-
|
|
517
|
-
onScroll={onScroll}
|
|
518
|
-
scrollEventThrottle={childProps.scrollEventThrottle ?? 16}
|
|
519
|
-
// The band is the inset. iOS would otherwise add one of its own
|
|
520
|
-
// on top of it, for a header it cannot see.
|
|
521
|
-
contentInsetAdjustmentBehavior={
|
|
522
|
-
childProps.contentInsetAdjustmentBehavior ?? 'never'
|
|
523
|
-
}
|
|
524
|
-
contentContainerStyle={[
|
|
525
|
-
childProps.contentContainerStyle,
|
|
526
|
-
{ paddingTop: headerHeight },
|
|
527
|
-
]}
|
|
528
|
-
scrollIndicatorInsets={{ top: barBand, ...childProps.scrollIndicatorInsets }}
|
|
529
|
-
/>
|
|
559
|
+
{wantsTarget && BlurTargetView ? (
|
|
560
|
+
<BlurTargetView ref={targetRef} collapsable={false} style={styles.target}>
|
|
561
|
+
{scroller}
|
|
562
|
+
</BlurTargetView>
|
|
530
563
|
) : (
|
|
531
|
-
|
|
564
|
+
scroller
|
|
532
565
|
)}
|
|
533
566
|
|
|
534
567
|
<Animated.View
|
|
@@ -569,8 +602,10 @@ export interface ScrollHeaderBarProps extends ViewProps {
|
|
|
569
602
|
* content passing under the bar stays legible as shape and colour.
|
|
570
603
|
*
|
|
571
604
|
* `blur` needs `expo-blur`, which is optional, and it is replaced by an
|
|
572
|
-
* opaque bar under Reduce Transparency.
|
|
573
|
-
*
|
|
605
|
+
* opaque bar under Reduce Transparency. On Android it needs Android 12 (API
|
|
606
|
+
* 31) or later, and the header wraps its scroller in the view the blur
|
|
607
|
+
* samples. Each of these falls back to `plain` — a bar whose title cannot be
|
|
608
|
+
* read is a worse answer than one that is not frosted.
|
|
574
609
|
*/
|
|
575
610
|
surface?: ScrollHeaderSurface;
|
|
576
611
|
/** A hairline under the bar, drawn with its surface. */
|
|
@@ -609,7 +644,7 @@ const ScrollHeaderBar = forwardRef<ViewRef, ScrollHeaderBarProps>(
|
|
|
609
644
|
},
|
|
610
645
|
ref
|
|
611
646
|
) => {
|
|
612
|
-
const { progress } = useScrollHeader('ScrollHeader.Bar');
|
|
647
|
+
const { progress, blurTarget } = useScrollHeader('ScrollHeader.Bar');
|
|
613
648
|
const { barBand, insetTop } = useContext(BandMetricsContext);
|
|
614
649
|
const { mode } = useThemeMode();
|
|
615
650
|
const reduceTransparency = useReduceTransparency();
|
|
@@ -617,7 +652,7 @@ const ScrollHeaderBar = forwardRef<ViewRef, ScrollHeaderBarProps>(
|
|
|
617
652
|
// Three gates, and a preference that has not been answered yet counts as
|
|
618
653
|
// switched on: the case worth being careful about is the one where it is.
|
|
619
654
|
const blurring =
|
|
620
|
-
surface === 'blur' &&
|
|
655
|
+
surface === 'blur' && canBlurHere && BlurView !== null && reduceTransparency === false;
|
|
621
656
|
const fill = surface === 'blur' && !blurring ? 'plain' : surface;
|
|
622
657
|
const { bar, barSurface } = scrollHeaderVariants({ surface: fill, divider });
|
|
623
658
|
|
|
@@ -652,6 +687,7 @@ const ScrollHeaderBar = forwardRef<ViewRef, ScrollHeaderBarProps>(
|
|
|
652
687
|
intensity={intensity}
|
|
653
688
|
tint={material === 'default' ? mode : material}
|
|
654
689
|
style={StyleSheet.absoluteFill}
|
|
690
|
+
{...androidBlurProps(blurTarget)}
|
|
655
691
|
/>
|
|
656
692
|
) : null}
|
|
657
693
|
</Animated.View>
|
|
@@ -893,6 +929,8 @@ const styles = StyleSheet.create({
|
|
|
893
929
|
// Android draws by elevation before z-order, so a band with none of its own
|
|
894
930
|
// ends up under the scroller's own background.
|
|
895
931
|
lift: { elevation: 4 },
|
|
932
|
+
// Takes the scroller's place in the root, which it fills.
|
|
933
|
+
target: { flex: 1 },
|
|
896
934
|
});
|
|
897
935
|
|
|
898
936
|
export const ScrollHeader = Object.assign(ScrollHeaderRoot, {
|
|
@@ -89,7 +89,9 @@ const selectVariants = tv({
|
|
|
89
89
|
search: 'pb-2',
|
|
90
90
|
empty: 'px-3 py-6 text-center text-sm text-muted-foreground',
|
|
91
91
|
item: 'flex-row items-center gap-2 rounded-lg px-3 py-3',
|
|
92
|
-
|
|
92
|
+
// Grows to fill the row but keeps its natural width as its basis, so an
|
|
93
|
+
// overlay sized to `content` can measure the longest label.
|
|
94
|
+
itemLabel: 'grow shrink text-base font-medium text-foreground',
|
|
93
95
|
itemIndicator: 'h-5 w-5 items-center justify-center',
|
|
94
96
|
group: 'gap-1',
|
|
95
97
|
groupLabel: 'px-3 pb-1 pt-2',
|
|
@@ -483,7 +485,8 @@ export interface SelectProps {
|
|
|
483
485
|
sheetProps?: SelectSheetProps;
|
|
484
486
|
/**
|
|
485
487
|
* Width of the floating list. `trigger` matches the trigger, `content` sizes
|
|
486
|
-
* to the longest option, or pass a pixel value.
|
|
488
|
+
* to the longest option, or pass a pixel value. A list wider than the
|
|
489
|
+
* trigger moves left to stay on screen. `overlay` only.
|
|
487
490
|
*/
|
|
488
491
|
contentWidth?: 'trigger' | 'content' | number;
|
|
489
492
|
/** Gap between the trigger and the floating list. `overlay` only. */
|
|
@@ -521,6 +524,18 @@ export interface SelectProps {
|
|
|
521
524
|
children: ReactNode;
|
|
522
525
|
}
|
|
523
526
|
|
|
527
|
+
/** Space kept between a floating list and the side of the screen. */
|
|
528
|
+
const OVERLAY_EDGE = 8;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Where a floating list starts. It lines up with the trigger, and moves left
|
|
532
|
+
* when a list wider than the trigger would run off the right of the screen.
|
|
533
|
+
*/
|
|
534
|
+
function overlayLeft(anchor: { x: number }, width: number, screenWidth: number) {
|
|
535
|
+
const furthest = screenWidth - OVERLAY_EDGE - width;
|
|
536
|
+
return Math.max(Math.min(anchor.x, furthest), Math.min(anchor.x, OVERLAY_EDGE));
|
|
537
|
+
}
|
|
538
|
+
|
|
524
539
|
function SelectRoot({
|
|
525
540
|
className,
|
|
526
541
|
value,
|
|
@@ -554,9 +569,10 @@ function SelectRoot({
|
|
|
554
569
|
const [query, setQuery] = useState('');
|
|
555
570
|
const [anchor, setAnchor] = useState<Anchor | null>(null);
|
|
556
571
|
const [listHeight, setListHeight] = useState(0);
|
|
572
|
+
const [listWidth, setListWidth] = useState(0);
|
|
557
573
|
const triggerRef = useRef<ViewRef>(null);
|
|
558
574
|
const chevron = useSharedValue(0);
|
|
559
|
-
const { height: screenHeight } = useWindowDimensions();
|
|
575
|
+
const { height: screenHeight, width: screenWidth } = useWindowDimensions();
|
|
560
576
|
const insets = useSafeAreaInsets();
|
|
561
577
|
|
|
562
578
|
const options = useMemo(() => {
|
|
@@ -866,15 +882,15 @@ function SelectRoot({
|
|
|
866
882
|
const overlayPosition = anchor
|
|
867
883
|
? {
|
|
868
884
|
position: 'absolute' as const,
|
|
869
|
-
left: anchor.
|
|
885
|
+
left: overlayLeft(anchor, contentWidth === 'trigger' ? anchor.width : listWidth, screenWidth),
|
|
870
886
|
...(flip
|
|
871
887
|
? { bottom: screenHeight - anchor.y + offset }
|
|
872
888
|
: { top: anchor.y + anchor.height + offset }),
|
|
873
889
|
...(contentWidth === 'trigger'
|
|
874
890
|
? { width: anchor.width }
|
|
875
891
|
: typeof contentWidth === 'number'
|
|
876
|
-
? { width: contentWidth }
|
|
877
|
-
: { minWidth: anchor.width }),
|
|
892
|
+
? { width: contentWidth, maxWidth: screenWidth - OVERLAY_EDGE * 2 }
|
|
893
|
+
: { minWidth: anchor.width, maxWidth: screenWidth - OVERLAY_EDGE * 2 }),
|
|
878
894
|
// Never collapse to nothing in a cramped viewport — the list scrolls.
|
|
879
895
|
maxHeight: Math.max((flip ? anchor.y : spaceBelow) - offset, 160),
|
|
880
896
|
}
|
|
@@ -882,6 +898,7 @@ function SelectRoot({
|
|
|
882
898
|
|
|
883
899
|
const onListLayout = (event: LayoutChangeEvent) => {
|
|
884
900
|
setListHeight(event.nativeEvent.layout.height);
|
|
901
|
+
setListWidth(event.nativeEvent.layout.width);
|
|
885
902
|
};
|
|
886
903
|
|
|
887
904
|
return (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { forwardRef, useEffect } from 'react';
|
|
2
|
-
import { Pressable, View, type PressableProps } from 'react-native';
|
|
2
|
+
import { Platform, Pressable, View, type PressableProps } from 'react-native';
|
|
3
3
|
import Animated, {
|
|
4
4
|
interpolate,
|
|
5
5
|
useAnimatedStyle,
|
|
@@ -62,6 +62,25 @@ const SWITCH_HIT_SLOP: Record<SwitchSize, { top: number; bottom: number; left: n
|
|
|
62
62
|
xl: { top: 6, bottom: 6, left: 0, right: 0 },
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* The same room as padding, with a negative margin that gives it back to the
|
|
67
|
+
* layout. The web ignores `hitSlop`, so without this its target would be the
|
|
68
|
+
* bare track.
|
|
69
|
+
*/
|
|
70
|
+
const webTarget = (size: SwitchSize) => {
|
|
71
|
+
const slop = SWITCH_HIT_SLOP[size];
|
|
72
|
+
return {
|
|
73
|
+
paddingTop: slop.top,
|
|
74
|
+
paddingBottom: slop.bottom,
|
|
75
|
+
paddingLeft: slop.left,
|
|
76
|
+
paddingRight: slop.right,
|
|
77
|
+
marginTop: -slop.top,
|
|
78
|
+
marginBottom: -slop.bottom,
|
|
79
|
+
marginLeft: -slop.left,
|
|
80
|
+
marginRight: -slop.right,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
65
84
|
export interface SwitchProps
|
|
66
85
|
extends VariantProps<typeof switchVariants>,
|
|
67
86
|
Pick<PressableProps, 'accessibilityLabel' | 'accessibilityHint' | 'accessibilityLabelledBy'> {
|
|
@@ -86,6 +105,13 @@ export interface SwitchProps
|
|
|
86
105
|
* the platform control owns its own feedback.
|
|
87
106
|
*/
|
|
88
107
|
haptics?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Set to `false` to draw only the track, with no press and no role of its
|
|
110
|
+
* own. Use it when a whole row is the switch: the row is the one
|
|
111
|
+
* `Pressable` with `accessibilityRole="switch"`, and a second switch inside
|
|
112
|
+
* it would be announced twice and take two Tab stops.
|
|
113
|
+
*/
|
|
114
|
+
interactive?: boolean;
|
|
89
115
|
}
|
|
90
116
|
|
|
91
117
|
/**
|
|
@@ -115,6 +141,7 @@ export const Switch = forwardRef<ViewRef, SwitchProps>(
|
|
|
115
141
|
accessibilityLabel,
|
|
116
142
|
accessibilityHint,
|
|
117
143
|
accessibilityLabelledBy,
|
|
144
|
+
interactive = true,
|
|
118
145
|
},
|
|
119
146
|
ref
|
|
120
147
|
) => {
|
|
@@ -173,11 +200,35 @@ export const Switch = forwardRef<ViewRef, SwitchProps>(
|
|
|
173
200
|
);
|
|
174
201
|
}
|
|
175
202
|
|
|
203
|
+
const track = (
|
|
204
|
+
<View className={slots.track({ className })}>
|
|
205
|
+
<Animated.View style={activeTrackStyle} className={slots.activeTrack()} />
|
|
206
|
+
<Animated.View style={thumbStyle} className={slots.thumb()} />
|
|
207
|
+
</View>
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
if (!interactive) {
|
|
211
|
+
return (
|
|
212
|
+
<View
|
|
213
|
+
ref={ref}
|
|
214
|
+
accessible={false}
|
|
215
|
+
aria-hidden
|
|
216
|
+
importantForAccessibility="no-hide-descendants"
|
|
217
|
+
pointerEvents="none"
|
|
218
|
+
>
|
|
219
|
+
{track}
|
|
220
|
+
</View>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
176
224
|
return (
|
|
177
225
|
<Pressable
|
|
178
226
|
ref={ref}
|
|
179
227
|
accessibilityRole="switch"
|
|
180
228
|
accessibilityState={{ checked: value, disabled: !!disabled }}
|
|
229
|
+
// Stated as well, because the web drops `checked: false` from the
|
|
230
|
+
// state and a switch with no `aria-checked` is an incomplete one.
|
|
231
|
+
aria-checked={value}
|
|
181
232
|
accessibilityLabel={accessibilityLabel ?? label}
|
|
182
233
|
accessibilityHint={accessibilityHint}
|
|
183
234
|
accessibilityLabelledBy={
|
|
@@ -189,11 +240,9 @@ export const Switch = forwardRef<ViewRef, SwitchProps>(
|
|
|
189
240
|
onValueChange?.(!value);
|
|
190
241
|
}}
|
|
191
242
|
hitSlop={SWITCH_HIT_SLOP[size]}
|
|
243
|
+
style={Platform.OS === 'web' ? webTarget(size) : undefined}
|
|
192
244
|
>
|
|
193
|
-
|
|
194
|
-
<Animated.View style={activeTrackStyle} className={slots.activeTrack()} />
|
|
195
|
-
<Animated.View style={thumbStyle} className={slots.thumb()} />
|
|
196
|
-
</View>
|
|
245
|
+
{track}
|
|
197
246
|
</Pressable>
|
|
198
247
|
);
|
|
199
248
|
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from 'react';
|
|
21
21
|
import {
|
|
22
22
|
AppState,
|
|
23
|
+
Platform,
|
|
23
24
|
View,
|
|
24
25
|
type ViewProps,
|
|
25
26
|
} from 'react-native';
|
|
@@ -266,11 +267,29 @@ const ToastAction = ({ variant = 'secondary', size = 'sm', onPress, ...props }:
|
|
|
266
267
|
};
|
|
267
268
|
ToastAction.displayName = 'Toast.Action';
|
|
268
269
|
|
|
269
|
-
export interface ToastCloseProps extends ViewProps {
|
|
270
|
+
export interface ToastCloseProps extends Omit<ViewProps, 'accessibilityLabel'> {
|
|
270
271
|
className?: string;
|
|
272
|
+
/**
|
|
273
|
+
* What a screen reader calls the button. Defaults to "Dismiss notification";
|
|
274
|
+
* pass your own in an app that is not in English.
|
|
275
|
+
*/
|
|
276
|
+
accessibilityLabel?: string;
|
|
271
277
|
}
|
|
272
278
|
|
|
273
|
-
|
|
279
|
+
/*
|
|
280
|
+
* The cross is drawn at 24 points so it stays quiet beside the text, and its
|
|
281
|
+
* target reaches 44 on both axes. Natively that is hit slop. The web ignores
|
|
282
|
+
* hit slop, so there the button itself is 44 and a negative margin gives the
|
|
283
|
+
* room back to the layout.
|
|
284
|
+
*/
|
|
285
|
+
const CLOSE_SIZE = Platform.OS === 'web' ? '-m-2.5 h-11 w-11' : 'h-6 w-6';
|
|
286
|
+
const CLOSE_SLOP = Platform.OS === 'web' ? undefined : 10;
|
|
287
|
+
|
|
288
|
+
const ToastClose = ({
|
|
289
|
+
className,
|
|
290
|
+
accessibilityLabel = 'Dismiss notification',
|
|
291
|
+
...props
|
|
292
|
+
}: ToastCloseProps) => {
|
|
274
293
|
const { hide } = useContext(ToastContext);
|
|
275
294
|
const color = useCSSVariable('--color-muted-foreground');
|
|
276
295
|
|
|
@@ -279,8 +298,9 @@ const ToastClose = ({ className, ...props }: ToastCloseProps) => {
|
|
|
279
298
|
<Button
|
|
280
299
|
variant="ghost"
|
|
281
300
|
size="icon"
|
|
282
|
-
accessibilityLabel=
|
|
283
|
-
className=
|
|
301
|
+
accessibilityLabel={accessibilityLabel}
|
|
302
|
+
className={cn(CLOSE_SIZE, 'rounded-full')}
|
|
303
|
+
hitSlop={CLOSE_SLOP}
|
|
284
304
|
onPress={hide}
|
|
285
305
|
>
|
|
286
306
|
<XIcon size={14} color={typeof color === 'string' ? color : undefined} />
|
|
@@ -1386,7 +1386,9 @@ function WaterfallChartTooltip({
|
|
|
1386
1386
|
};
|
|
1387
1387
|
|
|
1388
1388
|
return Gesture.Pan()
|
|
1389
|
-
|
|
1389
|
+
// With a hold, only the timer may start the readout: a distance of 0 would
|
|
1390
|
+
// activate on the first move event and take the touch from a Pressable above.
|
|
1391
|
+
.minDistance(activateAfterLongPress > 0 ? 10_000 : 0)
|
|
1390
1392
|
.activateAfterLongPress(activateAfterLongPress)
|
|
1391
1393
|
.onStart((event) => {
|
|
1392
1394
|
'worklet';
|