glacia-native 0.5.0 → 0.5.2
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/LICENSE +29 -4
- package/README.md +27 -0
- package/lib/module/Bars.js +103 -9
- package/lib/module/Button.js +11 -8
- package/lib/module/Card.js +2 -2
- package/lib/module/Dialog.js +16 -17
- package/lib/module/Display.js +86 -8
- package/lib/module/Feedback.js +244 -21
- package/lib/module/Form.js +29 -33
- package/lib/module/Forms2.js +257 -13
- package/lib/module/Glass.js +2 -2
- package/lib/module/Input.js +12 -10
- package/lib/module/Message.js +84 -0
- package/lib/module/Overlays.js +195 -17
- package/lib/module/Pickers.js +16 -16
- package/lib/module/SegmentedControl.js +24 -11
- package/lib/module/Slider.js +24 -10
- package/lib/module/Switch.js +25 -10
- package/lib/module/TabBar.js +23 -13
- package/lib/module/Table.js +4 -3
- package/lib/module/Tabs.js +3 -2
- package/lib/module/ai.js +26 -18
- package/lib/module/charts/BarChart.js +11 -3
- package/lib/module/index.js +23 -2
- package/lib/module/internal/GlassContainer.js +54 -0
- package/lib/module/internal/GlassView.js +10 -2
- package/lib/module/internal/a11y.js +94 -0
- package/lib/module/internal/blur.js +78 -0
- package/lib/module/internal/fallback.js +120 -19
- package/lib/module/internal/glass-routing.js +7 -0
- package/lib/module/internal/glow.js +36 -0
- package/lib/module/internal/haptics.js +54 -0
- package/lib/module/internal/lens.js +70 -0
- package/lib/module/internal/material.js +64 -0
- package/lib/module/internal/motion.js +10 -1
- package/lib/module/internal/primitives.js +70 -4
- package/lib/module/internal/rim.js +35 -0
- package/lib/module/internal/tokens.js +80 -2
- package/lib/typescript/Bars.d.ts +67 -0
- package/lib/typescript/Display.d.ts +59 -0
- package/lib/typescript/Feedback.d.ts +58 -0
- package/lib/typescript/Forms2.d.ts +81 -0
- package/lib/typescript/Message.d.ts +67 -0
- package/lib/typescript/Overlays.d.ts +41 -0
- package/lib/typescript/SegmentedControl.d.ts +2 -0
- package/lib/typescript/Slider.d.ts +2 -0
- package/lib/typescript/Switch.d.ts +2 -0
- package/lib/typescript/TabBar.d.ts +2 -0
- package/lib/typescript/index.d.ts +9 -6
- package/lib/typescript/internal/GlassContainer.d.ts +37 -0
- package/lib/typescript/internal/GlassView.d.ts +21 -0
- package/lib/typescript/internal/a11y.d.ts +19 -0
- package/lib/typescript/internal/blur.d.ts +24 -0
- package/lib/typescript/internal/fallback.d.ts +32 -2
- package/lib/typescript/internal/glass-routing.d.ts +10 -0
- package/lib/typescript/internal/glow.d.ts +11 -0
- package/lib/typescript/internal/haptics.d.ts +7 -0
- package/lib/typescript/internal/lens.d.ts +47 -0
- package/lib/typescript/internal/material.d.ts +27 -0
- package/lib/typescript/internal/motion.d.ts +4 -0
- package/lib/typescript/internal/primitives.d.ts +23 -0
- package/lib/typescript/internal/rim.d.ts +16 -0
- package/lib/typescript/internal/tokens.d.ts +89 -0
- package/package.json +12 -3
- package/src/Bars.tsx +239 -2
- package/src/Button.tsx +16 -9
- package/src/Card.tsx +2 -2
- package/src/Dialog.tsx +37 -26
- package/src/Display.tsx +237 -6
- package/src/Feedback.tsx +448 -35
- package/src/Form.tsx +60 -40
- package/src/Forms2.tsx +455 -8
- package/src/Glass.tsx +4 -0
- package/src/Input.tsx +15 -11
- package/src/Message.tsx +218 -0
- package/src/Overlays.tsx +269 -39
- package/src/Pickers.tsx +11 -6
- package/src/SegmentedControl.tsx +39 -9
- package/src/Slider.tsx +26 -10
- package/src/Switch.tsx +29 -10
- package/src/TabBar.tsx +39 -12
- package/src/Table.tsx +4 -3
- package/src/Tabs.tsx +5 -0
- package/src/ai.tsx +37 -23
- package/src/charts/BarChart.tsx +41 -3
- package/src/index.ts +43 -1
- package/src/internal/GlassContainer.tsx +82 -0
- package/src/internal/GlassView.tsx +25 -0
- package/src/internal/a11y.ts +105 -0
- package/src/internal/blur.ts +90 -0
- package/src/internal/fallback.tsx +170 -15
- package/src/internal/glass-routing.ts +17 -0
- package/src/internal/glow.tsx +62 -0
- package/src/internal/haptics.ts +59 -0
- package/src/internal/lens.tsx +105 -0
- package/src/internal/material.ts +92 -0
- package/src/internal/motion.ts +10 -1
- package/src/internal/primitives.ts +83 -4
- package/src/internal/rim.tsx +79 -0
- package/src/internal/tokens.ts +82 -1
package/src/Display.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { forwardRef, useEffect, useRef, useState, type ReactNode } from "react";
|
|
|
2
2
|
import type { StyleProp, ViewStyle } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { Glass } from "./Glass";
|
|
5
|
-
import { colors, radii } from "./internal/tokens";
|
|
5
|
+
import { colors, controlSizes, radii } from "./internal/tokens";
|
|
6
6
|
import { primitives } from "./internal/primitives";
|
|
7
7
|
import { useIsDark, useSpring } from "./internal/motion";
|
|
8
8
|
|
|
@@ -69,6 +69,7 @@ export const Avatar = forwardRef<any, AvatarProps>(function Avatar(
|
|
|
69
69
|
>
|
|
70
70
|
<Glass
|
|
71
71
|
effect="regular"
|
|
72
|
+
surface="panel"
|
|
72
73
|
isDark={isDark}
|
|
73
74
|
style={{
|
|
74
75
|
width: dimension,
|
|
@@ -158,7 +159,8 @@ export const Badge = forwardRef<any, BadgeProps>(function Badge(
|
|
|
158
159
|
: theme.fill;
|
|
159
160
|
|
|
160
161
|
const isDot = children == null;
|
|
161
|
-
|
|
162
|
+
// The web badge is 24 tall with 10 of horizontal padding and 12/500 type.
|
|
163
|
+
const height = isDot ? 10 : 24;
|
|
162
164
|
|
|
163
165
|
const badge = (
|
|
164
166
|
<View
|
|
@@ -170,7 +172,7 @@ export const Badge = forwardRef<any, BadgeProps>(function Badge(
|
|
|
170
172
|
minWidth: height,
|
|
171
173
|
height,
|
|
172
174
|
borderRadius: height / 2,
|
|
173
|
-
paddingHorizontal: isDot ? 0 :
|
|
175
|
+
paddingHorizontal: isDot ? 0 : 10,
|
|
174
176
|
alignItems: "center",
|
|
175
177
|
justifyContent: "center",
|
|
176
178
|
backgroundColor: background,
|
|
@@ -179,7 +181,7 @@ export const Badge = forwardRef<any, BadgeProps>(function Badge(
|
|
|
179
181
|
{...props}
|
|
180
182
|
>
|
|
181
183
|
{!isDot && (
|
|
182
|
-
<Text style={{ fontSize:
|
|
184
|
+
<Text style={{ fontSize: 12, fontWeight: "500", color: theme.onTint }} numberOfLines={1}>
|
|
183
185
|
{children}
|
|
184
186
|
</Text>
|
|
185
187
|
)}
|
|
@@ -226,8 +228,8 @@ export const Separator = forwardRef<any, SeparatorProps>(function Separator(
|
|
|
226
228
|
|
|
227
229
|
const separatorStyle: ViewStyle =
|
|
228
230
|
orientation === "horizontal"
|
|
229
|
-
? { height:
|
|
230
|
-
: { width:
|
|
231
|
+
? { height: 1, alignSelf: "stretch", marginLeft: inset, backgroundColor: theme.separator }
|
|
232
|
+
: { width: 1, alignSelf: "stretch", backgroundColor: theme.separator };
|
|
231
233
|
|
|
232
234
|
return (
|
|
233
235
|
<View
|
|
@@ -526,6 +528,7 @@ export const Progress = forwardRef<any, ProgressProps>(function Progress(
|
|
|
526
528
|
<Glass
|
|
527
529
|
ref={ref}
|
|
528
530
|
effect="regular"
|
|
531
|
+
surface="rail"
|
|
529
532
|
isDark={isDark}
|
|
530
533
|
style={{
|
|
531
534
|
height: 8,
|
|
@@ -548,3 +551,231 @@ export const Progress = forwardRef<any, ProgressProps>(function Progress(
|
|
|
548
551
|
</Glass>
|
|
549
552
|
);
|
|
550
553
|
});
|
|
554
|
+
|
|
555
|
+
// ---------------------------------------------------------------------------
|
|
556
|
+
// Rating
|
|
557
|
+
|
|
558
|
+
/** The five-pointed star, as a path in a unit box. */
|
|
559
|
+
const STAR_PATH =
|
|
560
|
+
"M12 2.4l2.95 5.98 6.6.96-4.78 4.66 1.13 6.57L12 17.46l-5.9 3.11 1.13-6.57L2.45 9.34l6.6-.96z";
|
|
561
|
+
|
|
562
|
+
export interface RatingProps {
|
|
563
|
+
/** How many stars are filled. Fractions render a partially filled star. */
|
|
564
|
+
value: number;
|
|
565
|
+
/** The number of stars. Defaults to five. */
|
|
566
|
+
max?: number;
|
|
567
|
+
size?: "sm" | "md" | "lg";
|
|
568
|
+
/** Makes the stars tappable. Omit for a read-only rating. */
|
|
569
|
+
onChange?: (value: number) => void;
|
|
570
|
+
disabled?: boolean;
|
|
571
|
+
/** The accessible name, e.g. "Rating". */
|
|
572
|
+
accessibilityLabel?: string;
|
|
573
|
+
style?: StyleProp<ViewStyle>;
|
|
574
|
+
isDark?: boolean;
|
|
575
|
+
testID?: string;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* A star rating.
|
|
580
|
+
*
|
|
581
|
+
* The stars are drawn as SVG paths from the resolver, so nothing is a
|
|
582
|
+
* platform control. A fractional value fills part of a star: 3.5 draws three
|
|
583
|
+
* full stars and one half, the half produced by clipping the filled star at the
|
|
584
|
+
* fraction's width rather than by rounding — a 4.5-star average must look like
|
|
585
|
+
* a 4.5-star average.
|
|
586
|
+
*
|
|
587
|
+
* Read-only unless `onChange` is given. With it, each star is tappable, the
|
|
588
|
+
* value is exposed as an adjustable control (increment/decrement through
|
|
589
|
+
* accessibility actions), and each star has its own label so a screen reader
|
|
590
|
+
* can name the exact rating it sets.
|
|
591
|
+
*/
|
|
592
|
+
export const Rating = forwardRef<any, RatingProps>(function Rating(
|
|
593
|
+
{
|
|
594
|
+
value,
|
|
595
|
+
max = 5,
|
|
596
|
+
size = "md",
|
|
597
|
+
onChange,
|
|
598
|
+
disabled = false,
|
|
599
|
+
accessibilityLabel = "Rating",
|
|
600
|
+
style,
|
|
601
|
+
isDark: isDarkProp,
|
|
602
|
+
testID,
|
|
603
|
+
...props
|
|
604
|
+
},
|
|
605
|
+
ref,
|
|
606
|
+
) {
|
|
607
|
+
const isDark = useIsDark(isDarkProp);
|
|
608
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
609
|
+
const { View, Pressable, Svg, Path, Defs, ClipPath, Rect } = primitives();
|
|
610
|
+
const starSize = controlSizes.star[size];
|
|
611
|
+
const interactive = Boolean(onChange) && !disabled;
|
|
612
|
+
const clamped = Math.max(0, Math.min(value, max));
|
|
613
|
+
|
|
614
|
+
const setValue = (next: number) => {
|
|
615
|
+
const bounded = Math.max(0, Math.min(next, max));
|
|
616
|
+
onChange?.(bounded);
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
const star = (index: number) => {
|
|
620
|
+
// How much of this star is filled: 1 for a full star, 0 for empty, and the
|
|
621
|
+
// remainder for the one the value lands inside.
|
|
622
|
+
const filled = Math.max(0, Math.min(1, clamped - index));
|
|
623
|
+
const half = filled > 0 && filled < 1;
|
|
624
|
+
|
|
625
|
+
const glyph = (
|
|
626
|
+
<Svg width={starSize} height={starSize} viewBox="0 0 24 24">
|
|
627
|
+
{half ? (
|
|
628
|
+
<Defs>
|
|
629
|
+
{/* The clip is what makes a fractional star possible: the filled
|
|
630
|
+
star is cut at the fraction's width. */}
|
|
631
|
+
<ClipPath id={`rating-clip-${index}`}>
|
|
632
|
+
<Rect x="0" y="0" width={24 * filled} height={24} />
|
|
633
|
+
</ClipPath>
|
|
634
|
+
</Defs>
|
|
635
|
+
) : null}
|
|
636
|
+
{/* The empty star is always drawn, so the shape is complete. */}
|
|
637
|
+
<Path d={STAR_PATH} fill={theme.separator} />
|
|
638
|
+
{filled > 0 ? (
|
|
639
|
+
<Path
|
|
640
|
+
d={STAR_PATH}
|
|
641
|
+
fill={theme.fill}
|
|
642
|
+
{...(half ? { clipPath: `url(#rating-clip-${index})` } : {})}
|
|
643
|
+
/>
|
|
644
|
+
) : null}
|
|
645
|
+
</Svg>
|
|
646
|
+
);
|
|
647
|
+
|
|
648
|
+
if (!interactive) return <View key={index}>{glyph}</View>;
|
|
649
|
+
|
|
650
|
+
return (
|
|
651
|
+
<Pressable
|
|
652
|
+
key={index}
|
|
653
|
+
accessibilityRole="button"
|
|
654
|
+
accessibilityLabel={`${index + 1} of ${max} stars`}
|
|
655
|
+
accessibilityState={{ selected: clamped === index + 1 }}
|
|
656
|
+
onPress={() => setValue(index + 1)}
|
|
657
|
+
hitSlop={4}
|
|
658
|
+
>
|
|
659
|
+
{glyph}
|
|
660
|
+
</Pressable>
|
|
661
|
+
);
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
const stars = Array.from({ length: Math.max(1, max) }, (_unused, index) => star(index));
|
|
665
|
+
|
|
666
|
+
if (!interactive && !onChange) {
|
|
667
|
+
return (
|
|
668
|
+
<View
|
|
669
|
+
ref={ref}
|
|
670
|
+
testID={testID}
|
|
671
|
+
accessibilityRole="text"
|
|
672
|
+
accessibilityLabel={`${accessibilityLabel}, ${clamped} of ${max}`}
|
|
673
|
+
style={{ flexDirection: "row", alignItems: "center", gap: 2, ...(style as ViewStyle) }}
|
|
674
|
+
{...props}
|
|
675
|
+
>
|
|
676
|
+
{stars}
|
|
677
|
+
</View>
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
return (
|
|
682
|
+
<View
|
|
683
|
+
ref={ref}
|
|
684
|
+
testID={testID}
|
|
685
|
+
accessibilityRole="adjustable"
|
|
686
|
+
accessibilityLabel={accessibilityLabel}
|
|
687
|
+
accessibilityState={{ disabled }}
|
|
688
|
+
accessibilityValue={{ min: 0, max, now: clamped }}
|
|
689
|
+
accessibilityActions={[{ name: "increment" }, { name: "decrement" }]}
|
|
690
|
+
onAccessibilityAction={(event: any) => {
|
|
691
|
+
if (disabled) return;
|
|
692
|
+
if (event?.nativeEvent?.actionName === "increment") setValue(clamped + 1);
|
|
693
|
+
if (event?.nativeEvent?.actionName === "decrement") setValue(clamped - 1);
|
|
694
|
+
}}
|
|
695
|
+
style={{ flexDirection: "row", alignItems: "center", gap: 2, opacity: disabled ? 0.38 : 1, ...(style as ViewStyle) }}
|
|
696
|
+
{...props}
|
|
697
|
+
>
|
|
698
|
+
{stars}
|
|
699
|
+
</View>
|
|
700
|
+
);
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
// ---------------------------------------------------------------------------
|
|
704
|
+
// Image
|
|
705
|
+
|
|
706
|
+
export interface NativeImageProps {
|
|
707
|
+
/** The image to show. */
|
|
708
|
+
source: { uri: string } | number;
|
|
709
|
+
/** A description for screen readers. Required: an image with no name is a hole. */
|
|
710
|
+
accessibilityLabel: string;
|
|
711
|
+
/** Shown behind the image while it loads; a Skeleton when omitted. */
|
|
712
|
+
placeholder?: ReactNode;
|
|
713
|
+
/** Shown when the image fails to load. */
|
|
714
|
+
fallback?: ReactNode;
|
|
715
|
+
/** Fades the image in when it loads. Honours Reduce Motion. */
|
|
716
|
+
fadeIn?: boolean;
|
|
717
|
+
style?: StyleProp<ViewStyle>;
|
|
718
|
+
isDark?: boolean;
|
|
719
|
+
testID?: string;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* A plain image, with the loading and error states every app ends up writing.
|
|
724
|
+
*
|
|
725
|
+
* Three states, because an image on a phone is three states: loading (a
|
|
726
|
+
* Skeleton behind it), loaded (a fade in), and failed (the caller's fallback).
|
|
727
|
+
* Aspect ratio comes from `style`, so a caller sets `aspectRatio` and the height
|
|
728
|
+
* follows.
|
|
729
|
+
*
|
|
730
|
+
* This is the plain one; `NativeImageGeneration` is the AI-specific cousin and
|
|
731
|
+
* keeps its own state machine.
|
|
732
|
+
*/
|
|
733
|
+
export const NativeImage = forwardRef<any, NativeImageProps>(function NativeImage(
|
|
734
|
+
{
|
|
735
|
+
source,
|
|
736
|
+
accessibilityLabel,
|
|
737
|
+
placeholder,
|
|
738
|
+
fallback,
|
|
739
|
+
fadeIn = true,
|
|
740
|
+
style,
|
|
741
|
+
isDark: isDarkProp,
|
|
742
|
+
testID,
|
|
743
|
+
...props
|
|
744
|
+
},
|
|
745
|
+
ref,
|
|
746
|
+
) {
|
|
747
|
+
const isDark = useIsDark(isDarkProp);
|
|
748
|
+
const { View, Image: RNImage, Animated } = primitives();
|
|
749
|
+
const [failed, setFailed] = useState(false);
|
|
750
|
+
const [loaded, setLoaded] = useState(false);
|
|
751
|
+
const { value: fade, animated } = useSpring(loaded ? 1 : 0, "gentle");
|
|
752
|
+
|
|
753
|
+
const boxStyle: ViewStyle = { overflow: "hidden", ...(style as ViewStyle) };
|
|
754
|
+
|
|
755
|
+
if (failed && fallback) {
|
|
756
|
+
return (
|
|
757
|
+
<View ref={ref} testID={testID} style={boxStyle} {...props}>
|
|
758
|
+
{fallback}
|
|
759
|
+
</View>
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
const imageStyle: ViewStyle = { width: "100%", height: "100%" };
|
|
764
|
+
const opacity = fadeIn && animated ? fade : 1;
|
|
765
|
+
|
|
766
|
+
return (
|
|
767
|
+
<View ref={ref} testID={testID} style={boxStyle} {...props}>
|
|
768
|
+
{/* The placeholder sits under the image, so the box never collapses and
|
|
769
|
+
the fade reveals rather than jumps. */}
|
|
770
|
+
{!loaded ? <View style={{ position: "absolute", top: 0, left: 0, right: 0, bottom: 0 }}>{placeholder ?? <Skeleton shape="rect" isDark={isDark} />}</View> : null}
|
|
771
|
+
<RNImage
|
|
772
|
+
accessibilityRole="image"
|
|
773
|
+
accessibilityLabel={accessibilityLabel}
|
|
774
|
+
source={source}
|
|
775
|
+
onLoad={() => setLoaded(true)}
|
|
776
|
+
onError={() => setFailed(true)}
|
|
777
|
+
style={[imageStyle, animated ? { opacity } : null]}
|
|
778
|
+
/>
|
|
779
|
+
</View>
|
|
780
|
+
);
|
|
781
|
+
});
|