@xaui/native 0.0.16 → 0.0.18

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 (62) hide show
  1. package/dist/accordion/index.cjs +1 -1
  2. package/dist/accordion/index.js +5 -4
  3. package/dist/alert/index.js +352 -3
  4. package/dist/autocomplete/index.cjs +5 -11
  5. package/dist/autocomplete/index.js +1122 -5
  6. package/dist/avatar/index.js +276 -4
  7. package/dist/badge/index.js +193 -3
  8. package/dist/bottom-sheet/index.cjs +9 -20
  9. package/dist/bottom-sheet/index.js +364 -3
  10. package/dist/button/index.js +3 -2
  11. package/dist/card/index.cjs +429 -0
  12. package/dist/card/index.d.cts +186 -0
  13. package/dist/card/index.d.ts +186 -0
  14. package/dist/card/index.js +336 -0
  15. package/dist/carousel/index.cjs +458 -0
  16. package/dist/carousel/index.d.cts +147 -0
  17. package/dist/carousel/index.d.ts +147 -0
  18. package/dist/carousel/index.js +381 -0
  19. package/dist/checkbox/index.js +2 -1
  20. package/dist/chip/index.cjs +2 -8
  21. package/dist/chip/index.js +497 -5
  22. package/dist/chunk-DXXNBF5P.js +7 -0
  23. package/dist/{chunk-MKHBEJLO.js → chunk-F7WH4DMG.js} +1 -1
  24. package/dist/{chunk-II4QINLG.js → chunk-JEGEPGVU.js} +2 -2
  25. package/dist/{chunk-NBRASCX4.js → chunk-LTKYHG5V.js} +6 -13
  26. package/dist/{chunk-GNJIET26.js → chunk-LUBWRVI2.js} +1 -1
  27. package/dist/core/index.cjs +1 -1
  28. package/dist/core/index.js +5 -3
  29. package/dist/datepicker/index.js +1623 -3
  30. package/dist/divider/index.js +3 -2
  31. package/dist/fab/index.js +4 -3
  32. package/dist/fab-menu/index.cjs +4 -13
  33. package/dist/fab-menu/index.js +325 -6
  34. package/dist/index.cjs +0 -5709
  35. package/dist/index.d.cts +2 -17
  36. package/dist/index.d.ts +2 -17
  37. package/dist/index.js +0 -62
  38. package/dist/indicator/index.js +3 -2
  39. package/dist/menu/index.cjs +8 -7
  40. package/dist/menu/index.js +15 -9
  41. package/dist/progress/index.js +2 -1
  42. package/dist/segment-button/index.cjs +492 -0
  43. package/dist/segment-button/index.d.cts +141 -0
  44. package/dist/segment-button/index.d.ts +141 -0
  45. package/dist/segment-button/index.js +405 -0
  46. package/dist/select/index.js +2 -1
  47. package/dist/switch/index.js +2 -1
  48. package/dist/typography/index.js +146 -3
  49. package/dist/view/index.cjs +153 -78
  50. package/dist/view/index.d.cts +77 -1
  51. package/dist/view/index.d.ts +77 -1
  52. package/dist/view/index.js +125 -52
  53. package/package.json +16 -1
  54. package/dist/chunk-2T6FKPJW.js +0 -356
  55. package/dist/chunk-4LFRYVSR.js +0 -281
  56. package/dist/chunk-7OFTYKK4.js +0 -1627
  57. package/dist/chunk-EI5OMBFE.js +0 -338
  58. package/dist/chunk-GAOI4KIV.js +0 -379
  59. package/dist/chunk-NMZUPH3R.js +0 -1133
  60. package/dist/chunk-QLEQYKG5.js +0 -509
  61. package/dist/chunk-XJKA22BK.js +0 -197
  62. package/dist/chunk-ZYTBRHLJ.js +0 -150
@@ -1,7 +1,368 @@
1
+ import "../chunk-DXXNBF5P.js";
1
2
  import {
2
- BottomSheet
3
- } from "../chunk-GAOI4KIV.js";
4
- import "../chunk-NBRASCX4.js";
3
+ Portal,
4
+ useXUITheme
5
+ } from "../chunk-LTKYHG5V.js";
6
+
7
+ // src/components/bottom-sheet/bottom-sheet.tsx
8
+ import React from "react";
9
+ import { Animated as Animated3, Pressable, View } from "react-native";
10
+
11
+ // src/components/bottom-sheet/bottom-sheet.hook.ts
12
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
13
+ import { Animated as Animated2, Dimensions, PanResponder } from "react-native";
14
+ import { getSafeThemeColor } from "@xaui/core";
15
+
16
+ // src/components/bottom-sheet/bottom-sheet.animation.ts
17
+ import { Animated, Easing } from "react-native";
18
+ var SPRING_CONFIG = {
19
+ useNativeDriver: true,
20
+ speed: 14,
21
+ bounciness: 4
22
+ };
23
+ var TIMING_CONFIG = {
24
+ duration: 280,
25
+ easing: Easing.bezier(0.2, 0, 0, 1),
26
+ useNativeDriver: true
27
+ };
28
+ var runOpenAnimation = (translateY, backdropOpacity, targetTranslateY) => {
29
+ const animation = Animated.parallel([
30
+ Animated.spring(translateY, {
31
+ ...SPRING_CONFIG,
32
+ toValue: targetTranslateY
33
+ }),
34
+ Animated.timing(backdropOpacity, {
35
+ ...TIMING_CONFIG,
36
+ toValue: 1
37
+ })
38
+ ]);
39
+ animation.start();
40
+ return animation;
41
+ };
42
+ var runCloseAnimation = (translateY, backdropOpacity, screenHeight, onComplete) => {
43
+ const animation = Animated.parallel([
44
+ Animated.timing(translateY, {
45
+ ...TIMING_CONFIG,
46
+ toValue: screenHeight
47
+ }),
48
+ Animated.timing(backdropOpacity, {
49
+ ...TIMING_CONFIG,
50
+ toValue: 0
51
+ })
52
+ ]);
53
+ animation.start(({ finished }) => {
54
+ if (finished && onComplete) {
55
+ onComplete();
56
+ }
57
+ });
58
+ return animation;
59
+ };
60
+ var runSnapAnimation = (translateY, targetTranslateY) => {
61
+ const animation = Animated.spring(translateY, {
62
+ ...SPRING_CONFIG,
63
+ toValue: targetTranslateY
64
+ });
65
+ animation.start();
66
+ return animation;
67
+ };
68
+
69
+ // src/components/bottom-sheet/bottom-sheet.hook.ts
70
+ var DISMISS_VELOCITY_THRESHOLD = 0.5;
71
+ var DISMISS_DISTANCE_FRACTION = 0.3;
72
+ var SCREEN_HEIGHT = Dimensions.get("window").height;
73
+ var getTranslateYForSnap = (snapFraction) => SCREEN_HEIGHT * (1 - snapFraction);
74
+ var useBottomSheetAnimation = ({
75
+ isOpen,
76
+ snapPoints,
77
+ initialSnapIndex,
78
+ enableSwipeToDismiss,
79
+ disableAnimation,
80
+ onClose,
81
+ onSnapChange
82
+ }) => {
83
+ const [shouldRender, setShouldRender] = useState(false);
84
+ const currentSnapIndex = useRef(initialSnapIndex);
85
+ const animationRef = useRef(null);
86
+ const translateY = useRef(new Animated2.Value(SCREEN_HEIGHT)).current;
87
+ const backdropOpacity = useRef(new Animated2.Value(0)).current;
88
+ const sortedSnapPoints = useMemo(
89
+ () => [...snapPoints].sort((a, b) => a - b),
90
+ [snapPoints]
91
+ );
92
+ const snapTranslateValues = useMemo(
93
+ () => sortedSnapPoints.map(getTranslateYForSnap),
94
+ [sortedSnapPoints]
95
+ );
96
+ const open = useCallback(() => {
97
+ setShouldRender(true);
98
+ const targetIndex = Math.min(initialSnapIndex, sortedSnapPoints.length - 1);
99
+ currentSnapIndex.current = targetIndex;
100
+ if (disableAnimation) {
101
+ translateY.setValue(snapTranslateValues[targetIndex]);
102
+ backdropOpacity.setValue(1);
103
+ return;
104
+ }
105
+ translateY.setValue(SCREEN_HEIGHT);
106
+ backdropOpacity.setValue(0);
107
+ animationRef.current?.stop();
108
+ animationRef.current = runOpenAnimation(
109
+ translateY,
110
+ backdropOpacity,
111
+ snapTranslateValues[targetIndex]
112
+ );
113
+ }, [
114
+ initialSnapIndex,
115
+ sortedSnapPoints,
116
+ snapTranslateValues,
117
+ disableAnimation,
118
+ translateY,
119
+ backdropOpacity
120
+ ]);
121
+ const close = useCallback(() => {
122
+ if (disableAnimation) {
123
+ translateY.setValue(SCREEN_HEIGHT);
124
+ backdropOpacity.setValue(0);
125
+ setShouldRender(false);
126
+ onClose?.();
127
+ return;
128
+ }
129
+ animationRef.current?.stop();
130
+ animationRef.current = runCloseAnimation(
131
+ translateY,
132
+ backdropOpacity,
133
+ SCREEN_HEIGHT,
134
+ () => {
135
+ setShouldRender(false);
136
+ onClose?.();
137
+ }
138
+ );
139
+ }, [disableAnimation, translateY, backdropOpacity, onClose]);
140
+ const snapTo = useCallback(
141
+ (index) => {
142
+ const clampedIndex = Math.max(0, Math.min(index, sortedSnapPoints.length - 1));
143
+ currentSnapIndex.current = clampedIndex;
144
+ onSnapChange?.(clampedIndex);
145
+ if (disableAnimation) {
146
+ translateY.setValue(snapTranslateValues[clampedIndex]);
147
+ return;
148
+ }
149
+ animationRef.current?.stop();
150
+ animationRef.current = runSnapAnimation(
151
+ translateY,
152
+ snapTranslateValues[clampedIndex]
153
+ );
154
+ },
155
+ [
156
+ sortedSnapPoints,
157
+ snapTranslateValues,
158
+ disableAnimation,
159
+ translateY,
160
+ onSnapChange
161
+ ]
162
+ );
163
+ useEffect(() => {
164
+ if (isOpen) {
165
+ open();
166
+ } else if (shouldRender) {
167
+ close();
168
+ }
169
+ }, [isOpen]);
170
+ const panResponder = useMemo(
171
+ () => PanResponder.create({
172
+ onStartShouldSetPanResponder: () => true,
173
+ onMoveShouldSetPanResponder: (_, gestureState) => Math.abs(gestureState.dy) > 5,
174
+ onPanResponderMove: (_, gestureState) => {
175
+ const currentTranslate = snapTranslateValues[currentSnapIndex.current];
176
+ const newTranslateY = currentTranslate + gestureState.dy;
177
+ const maxExpanded = snapTranslateValues[snapTranslateValues.length - 1];
178
+ const clamped = Math.max(maxExpanded, newTranslateY);
179
+ translateY.setValue(clamped);
180
+ },
181
+ onPanResponderRelease: (_, gestureState) => {
182
+ const currentTranslate = snapTranslateValues[currentSnapIndex.current];
183
+ const finalPosition = currentTranslate + gestureState.dy;
184
+ if (enableSwipeToDismiss && (gestureState.vy > DISMISS_VELOCITY_THRESHOLD || finalPosition > SCREEN_HEIGHT * (1 - sortedSnapPoints[0] * DISMISS_DISTANCE_FRACTION))) {
185
+ close();
186
+ return;
187
+ }
188
+ if (gestureState.vy < -DISMISS_VELOCITY_THRESHOLD) {
189
+ const nextIndex = Math.min(
190
+ currentSnapIndex.current + 1,
191
+ sortedSnapPoints.length - 1
192
+ );
193
+ snapTo(nextIndex);
194
+ return;
195
+ }
196
+ if (gestureState.vy > DISMISS_VELOCITY_THRESHOLD) {
197
+ const prevIndex = Math.max(currentSnapIndex.current - 1, 0);
198
+ if (prevIndex === currentSnapIndex.current && enableSwipeToDismiss) {
199
+ close();
200
+ return;
201
+ }
202
+ snapTo(prevIndex);
203
+ return;
204
+ }
205
+ let closestIndex = 0;
206
+ let minDistance = Infinity;
207
+ snapTranslateValues.forEach((snapVal, index) => {
208
+ const distance = Math.abs(finalPosition - snapVal);
209
+ if (distance < minDistance) {
210
+ minDistance = distance;
211
+ closestIndex = index;
212
+ }
213
+ });
214
+ snapTo(closestIndex);
215
+ }
216
+ }),
217
+ [
218
+ snapTranslateValues,
219
+ sortedSnapPoints,
220
+ enableSwipeToDismiss,
221
+ translateY,
222
+ close,
223
+ snapTo
224
+ ]
225
+ );
226
+ return {
227
+ shouldRender,
228
+ translateY,
229
+ backdropOpacity,
230
+ panResponder,
231
+ close,
232
+ snapTo,
233
+ screenHeight: SCREEN_HEIGHT
234
+ };
235
+ };
236
+ var useBottomSheetStyles = (themeColor, radius) => {
237
+ const theme = useXUITheme();
238
+ const safeThemeColor = getSafeThemeColor(themeColor);
239
+ const colorScheme = theme.colors[safeThemeColor];
240
+ const sheetStyles = useMemo(
241
+ () => ({
242
+ backgroundColor: colorScheme.background ?? theme.colors.background ?? "#ffffff",
243
+ borderTopLeftRadius: theme.borderRadius[radius],
244
+ borderTopRightRadius: theme.borderRadius[radius]
245
+ }),
246
+ [theme, colorScheme, radius]
247
+ );
248
+ const handleIndicatorColor = useMemo(
249
+ () => theme.mode === "dark" ? `${colorScheme.main}60` : `${colorScheme.main}40`,
250
+ [theme, colorScheme]
251
+ );
252
+ return { sheetStyles, handleIndicatorColor };
253
+ };
254
+
255
+ // src/components/bottom-sheet/bottom-sheet.style.ts
256
+ import { StyleSheet } from "react-native";
257
+ var styles = StyleSheet.create({
258
+ backdrop: {
259
+ position: "absolute",
260
+ top: 0,
261
+ left: 0,
262
+ right: 0,
263
+ bottom: 0,
264
+ backgroundColor: "rgba(0, 0, 0, 0.5)"
265
+ },
266
+ container: {
267
+ position: "absolute",
268
+ left: 0,
269
+ right: 0,
270
+ bottom: 0
271
+ },
272
+ sheet: {
273
+ overflow: "hidden"
274
+ },
275
+ handle: {
276
+ alignItems: "center",
277
+ justifyContent: "center",
278
+ paddingVertical: 10
279
+ },
280
+ handleIndicator: {
281
+ width: 36,
282
+ height: 4,
283
+ borderRadius: 2
284
+ },
285
+ content: {
286
+ flex: 1
287
+ }
288
+ });
289
+
290
+ // src/components/bottom-sheet/bottom-sheet.tsx
291
+ var BottomSheet = ({
292
+ children,
293
+ isOpen,
294
+ snapPoints = [0.4, 0.9],
295
+ initialSnapIndex = 0,
296
+ themeColor = "default",
297
+ radius = "lg",
298
+ showBackdrop = true,
299
+ closeOnBackdropPress = true,
300
+ enableSwipeToDismiss = true,
301
+ showHandle = true,
302
+ disableAnimation = false,
303
+ style,
304
+ handleContent,
305
+ onClose,
306
+ onSnapChange
307
+ }) => {
308
+ const {
309
+ shouldRender,
310
+ translateY,
311
+ backdropOpacity,
312
+ panResponder,
313
+ close,
314
+ screenHeight
315
+ } = useBottomSheetAnimation({
316
+ isOpen,
317
+ snapPoints,
318
+ initialSnapIndex,
319
+ enableSwipeToDismiss,
320
+ disableAnimation,
321
+ onClose,
322
+ onSnapChange
323
+ });
324
+ const { sheetStyles, handleIndicatorColor } = useBottomSheetStyles(
325
+ themeColor,
326
+ radius
327
+ );
328
+ if (!shouldRender) {
329
+ return null;
330
+ }
331
+ const handleBackdropPress = () => {
332
+ if (closeOnBackdropPress) {
333
+ close();
334
+ }
335
+ };
336
+ return /* @__PURE__ */ React.createElement(Portal, null, showBackdrop && /* @__PURE__ */ React.createElement(Animated3.View, { style: [styles.backdrop, { opacity: backdropOpacity }] }, /* @__PURE__ */ React.createElement(Pressable, { style: styles.backdrop, onPress: handleBackdropPress })), /* @__PURE__ */ React.createElement(
337
+ Animated3.View,
338
+ {
339
+ style: [
340
+ styles.container,
341
+ {
342
+ height: screenHeight,
343
+ transform: [{ translateY }]
344
+ }
345
+ ]
346
+ },
347
+ /* @__PURE__ */ React.createElement(
348
+ View,
349
+ {
350
+ style: [styles.sheet, { height: screenHeight }, sheetStyles, style],
351
+ ...panResponder.panHandlers
352
+ },
353
+ showHandle && /* @__PURE__ */ React.createElement(View, { style: styles.handle }, handleContent ?? /* @__PURE__ */ React.createElement(
354
+ View,
355
+ {
356
+ style: [
357
+ styles.handleIndicator,
358
+ { backgroundColor: handleIndicatorColor }
359
+ ]
360
+ }
361
+ )),
362
+ /* @__PURE__ */ React.createElement(View, { style: styles.content }, children)
363
+ )
364
+ ));
365
+ };
5
366
  export {
6
367
  BottomSheet
7
368
  };
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  ActivityIndicator
3
- } from "../chunk-MKHBEJLO.js";
3
+ } from "../chunk-F7WH4DMG.js";
4
+ import "../chunk-DXXNBF5P.js";
4
5
  import {
5
6
  useBorderRadiusStyles,
6
7
  useXUITheme
7
- } from "../chunk-NBRASCX4.js";
8
+ } from "../chunk-LTKYHG5V.js";
8
9
 
9
10
  // src/components/button/button.tsx
10
11
  import React from "react";