glacia-native 0.4.0 → 0.5.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/lib/module/Bars.js +269 -0
- package/lib/module/Carousel.js +103 -0
- package/lib/module/Display.js +317 -0
- package/lib/module/Feedback.js +386 -0
- package/lib/module/Forms2.js +454 -0
- package/lib/module/Message.js +88 -0
- package/lib/module/Overlays.js +328 -0
- package/lib/module/Pickers.js +243 -0
- package/lib/module/SegmentedControl.js +5 -1
- package/lib/module/Slider.js +6 -1
- package/lib/module/Switch.js +4 -1
- package/lib/module/TabBar.js +5 -1
- package/lib/module/Text.js +37 -0
- package/lib/module/ai.js +8 -3
- package/lib/module/index.js +79 -1
- package/lib/module/internal/GlassContainer.js +54 -0
- package/lib/module/internal/GlassView.js +31 -7
- package/lib/module/internal/a11y.js +94 -0
- package/lib/module/internal/fallback.js +19 -8
- package/lib/module/internal/glass-routing.js +7 -0
- package/lib/module/internal/haptics.js +54 -0
- package/lib/module/internal/motion.js +10 -1
- package/lib/module/internal/primitives.js +73 -3
- package/lib/module/internal/tokens.js +101 -1
- package/lib/typescript/Bars.d.ts +188 -0
- package/lib/typescript/Carousel.d.ts +47 -0
- package/lib/typescript/Display.d.ts +178 -0
- package/lib/typescript/Feedback.d.ts +196 -0
- package/lib/typescript/Forms2.d.ts +209 -0
- package/lib/typescript/Glass.d.ts +1 -1
- package/lib/typescript/Message.d.ts +71 -0
- package/lib/typescript/Overlays.d.ts +146 -0
- package/lib/typescript/Pickers.d.ts +105 -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/Text.d.ts +28 -0
- package/lib/typescript/index.d.ts +11 -1
- package/lib/typescript/internal/GlassContainer.d.ts +37 -0
- package/lib/typescript/internal/GlassView.d.ts +18 -1
- package/lib/typescript/internal/a11y.d.ts +19 -0
- package/lib/typescript/internal/fallback.d.ts +5 -0
- package/lib/typescript/internal/glass-routing.d.ts +10 -0
- package/lib/typescript/internal/haptics.d.ts +7 -0
- package/lib/typescript/internal/motion.d.ts +4 -0
- package/lib/typescript/internal/primitives.d.ts +21 -0
- package/lib/typescript/internal/tokens.d.ts +114 -0
- package/package.json +2 -2
- package/src/Bars.tsx +797 -0
- package/src/Carousel.tsx +233 -0
- package/src/Display.tsx +778 -0
- package/src/Feedback.tsx +969 -0
- package/src/Forms2.tsx +1014 -0
- package/src/Message.tsx +219 -0
- package/src/Overlays.tsx +685 -0
- package/src/Pickers.tsx +590 -0
- package/src/SegmentedControl.tsx +6 -0
- package/src/Slider.tsx +7 -0
- package/src/Switch.tsx +5 -0
- package/src/TabBar.tsx +6 -0
- package/src/Text.tsx +83 -0
- package/src/ai.tsx +9 -3
- package/src/index.ts +142 -1
- package/src/internal/GlassContainer.tsx +82 -0
- package/src/internal/GlassView.tsx +37 -7
- package/src/internal/a11y.ts +105 -0
- package/src/internal/fallback.tsx +19 -2
- package/src/internal/glass-routing.ts +17 -0
- package/src/internal/haptics.ts +59 -0
- package/src/internal/motion.ts +10 -1
- package/src/internal/primitives.ts +84 -3
- package/src/internal/tokens.ts +110 -0
package/src/Carousel.tsx
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { forwardRef, useRef, useState, type ReactNode } from "react";
|
|
2
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { colors } from "./internal/tokens";
|
|
5
|
+
import { primitives } from "./internal/primitives";
|
|
6
|
+
import { useIsDark, useSpring } from "./internal/motion";
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Carousel
|
|
10
|
+
|
|
11
|
+
export interface CarouselProps {
|
|
12
|
+
/** One node per page. */
|
|
13
|
+
slides: ReactNode[];
|
|
14
|
+
/** Controlled page. Omit and the carousel tracks itself. */
|
|
15
|
+
index?: number;
|
|
16
|
+
defaultIndex?: number;
|
|
17
|
+
/** Fires when a swipe settles on a new page. */
|
|
18
|
+
onIndexChange?: (index: number) => void;
|
|
19
|
+
/** Gap between pages, so neighbours peek at the edges. */
|
|
20
|
+
gap?: number;
|
|
21
|
+
style?: StyleProp<ViewStyle>;
|
|
22
|
+
isDark?: boolean;
|
|
23
|
+
testID?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A horizontally paging swiper.
|
|
28
|
+
*
|
|
29
|
+
* It rides the resolver's ScrollView with `pagingEnabled`, so the paging feel is
|
|
30
|
+
* the platform's own and the pages are plain content the caller supplies. The
|
|
31
|
+
* active page is derived from the scroll offset, which is also what reports
|
|
32
|
+
* `onIndexChange`.
|
|
33
|
+
*/
|
|
34
|
+
export const Carousel = forwardRef<any, CarouselProps>(function Carousel(
|
|
35
|
+
{
|
|
36
|
+
slides,
|
|
37
|
+
index: indexProp,
|
|
38
|
+
defaultIndex = 0,
|
|
39
|
+
onIndexChange,
|
|
40
|
+
gap = 0,
|
|
41
|
+
style,
|
|
42
|
+
isDark: isDarkProp,
|
|
43
|
+
testID,
|
|
44
|
+
...props
|
|
45
|
+
},
|
|
46
|
+
ref,
|
|
47
|
+
) {
|
|
48
|
+
const isDark = useIsDark(isDarkProp);
|
|
49
|
+
const { getScrollView } = primitives();
|
|
50
|
+
const ScrollView = getScrollView();
|
|
51
|
+
const { View } = primitives();
|
|
52
|
+
|
|
53
|
+
const [internalIndex, setInternalIndex] = useState(defaultIndex);
|
|
54
|
+
const index = indexProp !== undefined ? indexProp : internalIndex;
|
|
55
|
+
|
|
56
|
+
const viewportWidth = useRef(0);
|
|
57
|
+
const scrollRef = useRef<any>(null);
|
|
58
|
+
|
|
59
|
+
// Derives the page from the offset rather than trusting a counter, so a
|
|
60
|
+
// fast swipe that skips pages still reports the page it landed on.
|
|
61
|
+
const handleScroll = (event: any) => {
|
|
62
|
+
const { contentOffset, layoutMeasurement } = event?.nativeEvent ?? {};
|
|
63
|
+
const width = layoutMeasurement?.width || viewportWidth.current;
|
|
64
|
+
if (!width || !contentOffset) return;
|
|
65
|
+
const next = Math.round(contentOffset.x / width);
|
|
66
|
+
const clamped = Math.min(Math.max(next, 0), Math.max(slides.length - 1, 0));
|
|
67
|
+
if (clamped !== index) {
|
|
68
|
+
if (indexProp === undefined) setInternalIndex(clamped);
|
|
69
|
+
onIndexChange?.(clamped);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const pages = slides.map((slide, i) => (
|
|
74
|
+
<View key={i} style={{ width: viewportWidth.current || "100%", paddingRight: gap }}>
|
|
75
|
+
{slide}
|
|
76
|
+
</View>
|
|
77
|
+
));
|
|
78
|
+
|
|
79
|
+
// Off-device there is no ScrollView; the pages still render in a row so the
|
|
80
|
+
// component mounts, and the tests drive `handleScroll` through onScroll.
|
|
81
|
+
if (!ScrollView) {
|
|
82
|
+
return (
|
|
83
|
+
<View ref={ref} testID={testID} style={[{ flexDirection: "row", overflow: "hidden" }, style as ViewStyle]} {...props}>
|
|
84
|
+
{pages}
|
|
85
|
+
</View>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<View
|
|
91
|
+
ref={ref}
|
|
92
|
+
testID={testID}
|
|
93
|
+
onLayout={(event: any) => {
|
|
94
|
+
viewportWidth.current = event?.nativeEvent?.layout?.width ?? 0;
|
|
95
|
+
}}
|
|
96
|
+
style={style as ViewStyle}
|
|
97
|
+
{...props}
|
|
98
|
+
>
|
|
99
|
+
<ScrollView
|
|
100
|
+
ref={scrollRef}
|
|
101
|
+
horizontal
|
|
102
|
+
pagingEnabled={gap === 0}
|
|
103
|
+
showsHorizontalScrollIndicator={false}
|
|
104
|
+
onScroll={handleScroll}
|
|
105
|
+
scrollEventThrottle={16}
|
|
106
|
+
accessibilityRole="adjustable"
|
|
107
|
+
accessibilityLabel="Carousel"
|
|
108
|
+
accessibilityValue={{ min: 0, max: Math.max(slides.length - 1, 0), now: index }}
|
|
109
|
+
accessibilityActions={[{ name: "increment" }, { name: "decrement" }]}
|
|
110
|
+
onAccessibilityAction={(event: any) => {
|
|
111
|
+
const step = event?.nativeEvent?.actionName === "increment" ? 1 : -1;
|
|
112
|
+
const next = Math.min(Math.max(index + step, 0), Math.max(slides.length - 1, 0));
|
|
113
|
+
if (next === index) return;
|
|
114
|
+
if (indexProp === undefined) setInternalIndex(next);
|
|
115
|
+
onIndexChange?.(next);
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
{pages}
|
|
119
|
+
</ScrollView>
|
|
120
|
+
</View>
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// PageControl
|
|
126
|
+
|
|
127
|
+
export interface PageControlProps {
|
|
128
|
+
count: number;
|
|
129
|
+
/** Controlled active page. Omit and the control keeps its own. */
|
|
130
|
+
activeIndex?: number;
|
|
131
|
+
defaultActiveIndex?: number;
|
|
132
|
+
/** Called when a dot is tapped. */
|
|
133
|
+
onChange?: (index: number) => void;
|
|
134
|
+
/** Tint the active dot; defaults to the theme accent. */
|
|
135
|
+
tint?: string;
|
|
136
|
+
/** Hide the dots when there is only one page. */
|
|
137
|
+
hidesForSinglePage?: boolean;
|
|
138
|
+
style?: StyleProp<ViewStyle>;
|
|
139
|
+
isDark?: boolean;
|
|
140
|
+
testID?: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const DOT = 7;
|
|
144
|
+
const ACTIVE_DOT = 18;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The page dots.
|
|
148
|
+
*
|
|
149
|
+
* The active dot elongates and the others stay narrow, which is how iOS reads
|
|
150
|
+
* "you are here". The width change runs on the springs token through Animated.
|
|
151
|
+
*/
|
|
152
|
+
export const PageControl = forwardRef<any, PageControlProps>(function PageControl(
|
|
153
|
+
{
|
|
154
|
+
count,
|
|
155
|
+
activeIndex: activeProp,
|
|
156
|
+
defaultActiveIndex = 0,
|
|
157
|
+
onChange,
|
|
158
|
+
tint,
|
|
159
|
+
hidesForSinglePage = false,
|
|
160
|
+
style,
|
|
161
|
+
isDark: isDarkProp,
|
|
162
|
+
testID,
|
|
163
|
+
...props
|
|
164
|
+
},
|
|
165
|
+
ref,
|
|
166
|
+
) {
|
|
167
|
+
const isDark = useIsDark(isDarkProp);
|
|
168
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
169
|
+
const { View, Pressable } = primitives();
|
|
170
|
+
|
|
171
|
+
const [internalIndex, setInternalIndex] = useState(defaultActiveIndex);
|
|
172
|
+
const active = activeProp !== undefined ? activeProp : internalIndex;
|
|
173
|
+
|
|
174
|
+
if (hidesForSinglePage && count <= 1) return null;
|
|
175
|
+
|
|
176
|
+
// The accent tints the active dot; the resting dots sit on `glassActive` so
|
|
177
|
+
// selection reads the same way it does in SegmentedControl and TabBar.
|
|
178
|
+
const accent = tint ?? theme.fill;
|
|
179
|
+
const resting = theme.glassActive;
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<View
|
|
183
|
+
ref={ref}
|
|
184
|
+
testID={testID}
|
|
185
|
+
accessibilityRole="tablist"
|
|
186
|
+
style={[{ flexDirection: "row", alignItems: "center", gap: 6, alignSelf: "center" }, style as ViewStyle]}
|
|
187
|
+
{...props}
|
|
188
|
+
>
|
|
189
|
+
{Array.from({ length: Math.max(count, 0) }, (_, index) => {
|
|
190
|
+
const isActive = index === active;
|
|
191
|
+
return (
|
|
192
|
+
<Pressable
|
|
193
|
+
key={index}
|
|
194
|
+
accessibilityRole="tab"
|
|
195
|
+
accessibilityLabel={`Page ${index + 1} of ${count}`}
|
|
196
|
+
accessibilityState={{ selected: isActive }}
|
|
197
|
+
onPress={() => {
|
|
198
|
+
if (activeProp === undefined) setInternalIndex(index);
|
|
199
|
+
onChange?.(index);
|
|
200
|
+
}}
|
|
201
|
+
hitSlop={8}
|
|
202
|
+
>
|
|
203
|
+
<Dot active={isActive} accent={accent} muted={resting} />
|
|
204
|
+
</Pressable>
|
|
205
|
+
);
|
|
206
|
+
})}
|
|
207
|
+
</View>
|
|
208
|
+
);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
/** One dot, whose width springs between the resting and active lengths. */
|
|
212
|
+
function Dot({ active, accent, muted }: { active: boolean; accent: string; muted: string }) {
|
|
213
|
+
const { Animated, View } = primitives();
|
|
214
|
+
const { value: progress, animated } = useSpring(active ? 1 : 0, "snappy");
|
|
215
|
+
|
|
216
|
+
const width = animated
|
|
217
|
+
? progress.interpolate({ inputRange: [0, 1], outputRange: [DOT, ACTIVE_DOT] })
|
|
218
|
+
: active
|
|
219
|
+
? ACTIVE_DOT
|
|
220
|
+
: DOT;
|
|
221
|
+
|
|
222
|
+
const style: ViewStyle = {
|
|
223
|
+
height: DOT,
|
|
224
|
+
borderRadius: DOT / 2,
|
|
225
|
+
backgroundColor: active ? accent : muted,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
return animated ? (
|
|
229
|
+
<Animated.View style={{ ...style, width }} />
|
|
230
|
+
) : (
|
|
231
|
+
<View style={{ ...style, width: width as number }} />
|
|
232
|
+
);
|
|
233
|
+
}
|