@ledgerhq/lumen-ui-rnative 0.1.63 → 0.1.65

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 (165) hide show
  1. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.js +19 -11
  2. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.js.map +1 -1
  3. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.test.js +113 -4
  4. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.test.js.map +1 -1
  5. package/dist/module/lib/Components/core/BottomSheet/BottomSheet.stories.js +51 -0
  6. package/dist/module/lib/Components/core/BottomSheet/BottomSheet.stories.js.map +1 -1
  7. package/dist/module/lib/Components/core/CardButton/CardButton.js +2 -0
  8. package/dist/module/lib/Components/core/CardButton/CardButton.js.map +1 -1
  9. package/dist/module/lib/Components/core/CardButton/CardButton.mdx +4 -0
  10. package/dist/module/lib/Components/core/CardButton/CardButton.stories.js +1 -0
  11. package/dist/module/lib/Components/core/CardButton/CardButton.stories.js.map +1 -1
  12. package/dist/module/lib/Components/core/Link/Link.figma.js +2 -1
  13. package/dist/module/lib/Components/core/Link/Link.figma.js.map +1 -1
  14. package/dist/module/lib/Components/core/Link/Link.js +5 -3
  15. package/dist/module/lib/Components/core/Link/Link.js.map +1 -1
  16. package/dist/module/lib/Components/core/Link/Link.mdx +3 -2
  17. package/dist/module/lib/Components/core/Link/Link.stories.js +4 -1
  18. package/dist/module/lib/Components/core/Link/Link.stories.js.map +1 -1
  19. package/dist/module/lib/Components/core/Link/Link.test.js +2 -2
  20. package/dist/module/lib/Components/core/Link/Link.test.js.map +1 -1
  21. package/dist/module/lib/Components/core/MenuList/MenuList.js +93 -7
  22. package/dist/module/lib/Components/core/MenuList/MenuList.js.map +1 -1
  23. package/dist/module/lib/Components/core/MenuList/MenuList.mdx +14 -1
  24. package/dist/module/lib/Components/core/MenuList/MenuList.stories.js +39 -2
  25. package/dist/module/lib/Components/core/MenuList/MenuList.stories.js.map +1 -1
  26. package/dist/module/lib/Components/core/MenuList/MenuList.test.js +60 -2
  27. package/dist/module/lib/Components/core/MenuList/MenuList.test.js.map +1 -1
  28. package/dist/module/lib/Components/core/SegmentedControl/SegmentedControl.js +1 -1
  29. package/dist/module/lib/Components/core/SegmentedControl/SegmentedControl.js.map +1 -1
  30. package/dist/module/lib/Components/core/Stepper/Stepper.js +76 -30
  31. package/dist/module/lib/Components/core/Stepper/Stepper.js.map +1 -1
  32. package/dist/module/lib/Components/core/Stepper/Stepper.mdx +37 -16
  33. package/dist/module/lib/Components/core/Stepper/Stepper.stories.js +102 -2
  34. package/dist/module/lib/Components/core/Stepper/Stepper.stories.js.map +1 -1
  35. package/dist/module/lib/Components/core/Stepper/Stepper.test.js +32 -1
  36. package/dist/module/lib/Components/core/Stepper/Stepper.test.js.map +1 -1
  37. package/dist/module/lib/Components/core/Timeline/Timeline.figma.js +83 -0
  38. package/dist/module/lib/Components/core/Timeline/Timeline.figma.js.map +1 -0
  39. package/dist/module/lib/Components/core/Timeline/Timeline.js +464 -0
  40. package/dist/module/lib/Components/core/Timeline/Timeline.js.map +1 -0
  41. package/dist/module/lib/Components/core/Timeline/Timeline.mdx +49 -0
  42. package/dist/module/lib/Components/core/Timeline/Timeline.stories.js +289 -0
  43. package/dist/module/lib/Components/core/Timeline/Timeline.stories.js.map +1 -0
  44. package/dist/module/lib/Components/core/Timeline/Timeline.test.js +234 -0
  45. package/dist/module/lib/Components/core/Timeline/Timeline.test.js.map +1 -0
  46. package/dist/module/lib/Components/core/Timeline/index.js +5 -0
  47. package/dist/module/lib/Components/core/Timeline/index.js.map +1 -0
  48. package/dist/module/lib/Components/core/Timeline/types.js +4 -0
  49. package/dist/module/lib/Components/core/Timeline/types.js.map +1 -0
  50. package/dist/module/lib/Components/core/Toast/Toast.figma.js +39 -0
  51. package/dist/module/lib/Components/core/Toast/Toast.figma.js.map +1 -0
  52. package/dist/module/lib/Components/core/Toast/Toast.js +138 -0
  53. package/dist/module/lib/Components/core/Toast/Toast.js.map +1 -0
  54. package/dist/module/lib/Components/core/Toast/Toast.mdx +203 -0
  55. package/dist/module/lib/Components/core/Toast/Toast.stories.js +238 -0
  56. package/dist/module/lib/Components/core/Toast/Toast.stories.js.map +1 -0
  57. package/dist/module/lib/Components/core/Toast/Toast.test.js +203 -0
  58. package/dist/module/lib/Components/core/Toast/Toast.test.js.map +1 -0
  59. package/dist/module/lib/Components/core/Toast/Toaster.js +147 -0
  60. package/dist/module/lib/Components/core/Toast/Toaster.js.map +1 -0
  61. package/dist/module/lib/Components/core/Toast/Toaster.test.js +732 -0
  62. package/dist/module/lib/Components/core/Toast/Toaster.test.js.map +1 -0
  63. package/dist/module/lib/Components/core/Toast/hooks/useToastAccessibility.js +70 -0
  64. package/dist/module/lib/Components/core/Toast/hooks/useToastAccessibility.js.map +1 -0
  65. package/dist/module/lib/Components/core/Toast/hooks/useToastCollapse.js +33 -0
  66. package/dist/module/lib/Components/core/Toast/hooks/useToastCollapse.js.map +1 -0
  67. package/dist/module/lib/Components/core/Toast/hooks/useToastGesture.js +224 -0
  68. package/dist/module/lib/Components/core/Toast/hooks/useToastGesture.js.map +1 -0
  69. package/dist/module/lib/Components/core/Toast/hooks/useToastMotion.js +82 -0
  70. package/dist/module/lib/Components/core/Toast/hooks/useToastMotion.js.map +1 -0
  71. package/dist/module/lib/Components/core/Toast/hooks/useToastViewportStyles.js +21 -0
  72. package/dist/module/lib/Components/core/Toast/hooks/useToastViewportStyles.js.map +1 -0
  73. package/dist/module/lib/Components/core/Toast/index.js +7 -0
  74. package/dist/module/lib/Components/core/Toast/index.js.map +1 -0
  75. package/dist/module/lib/Components/core/Toast/types.js +4 -0
  76. package/dist/module/lib/Components/core/Toast/types.js.map +1 -0
  77. package/dist/module/lib/Components/core/index.js +2 -0
  78. package/dist/module/lib/Components/core/index.js.map +1 -1
  79. package/dist/typescript/src/lib/Components/core/AmountDisplay/AmountDisplay.d.ts.map +1 -1
  80. package/dist/typescript/src/lib/Components/core/CardButton/CardButton.d.ts +2 -0
  81. package/dist/typescript/src/lib/Components/core/CardButton/CardButton.d.ts.map +1 -1
  82. package/dist/typescript/src/lib/Components/core/Link/Link.d.ts +1 -1
  83. package/dist/typescript/src/lib/Components/core/Link/Link.d.ts.map +1 -1
  84. package/dist/typescript/src/lib/Components/core/Link/types.d.ts +1 -1
  85. package/dist/typescript/src/lib/Components/core/Link/types.d.ts.map +1 -1
  86. package/dist/typescript/src/lib/Components/core/MenuList/MenuList.d.ts +12 -2
  87. package/dist/typescript/src/lib/Components/core/MenuList/MenuList.d.ts.map +1 -1
  88. package/dist/typescript/src/lib/Components/core/MenuList/types.d.ts +26 -7
  89. package/dist/typescript/src/lib/Components/core/MenuList/types.d.ts.map +1 -1
  90. package/dist/typescript/src/lib/Components/core/Stepper/Stepper.d.ts +4 -3
  91. package/dist/typescript/src/lib/Components/core/Stepper/Stepper.d.ts.map +1 -1
  92. package/dist/typescript/src/lib/Components/core/Stepper/types.d.ts +12 -2
  93. package/dist/typescript/src/lib/Components/core/Stepper/types.d.ts.map +1 -1
  94. package/dist/typescript/src/lib/Components/core/Timeline/Timeline.d.ts +56 -0
  95. package/dist/typescript/src/lib/Components/core/Timeline/Timeline.d.ts.map +1 -0
  96. package/dist/typescript/src/lib/Components/core/Timeline/index.d.ts +3 -0
  97. package/dist/typescript/src/lib/Components/core/Timeline/index.d.ts.map +1 -0
  98. package/dist/typescript/src/lib/Components/core/Timeline/types.d.ts +109 -0
  99. package/dist/typescript/src/lib/Components/core/Timeline/types.d.ts.map +1 -0
  100. package/dist/typescript/src/lib/Components/core/Toast/Toast.d.ts +24 -0
  101. package/dist/typescript/src/lib/Components/core/Toast/Toast.d.ts.map +1 -0
  102. package/dist/typescript/src/lib/Components/core/Toast/Toaster.d.ts +35 -0
  103. package/dist/typescript/src/lib/Components/core/Toast/Toaster.d.ts.map +1 -0
  104. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastAccessibility.d.ts +17 -0
  105. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastAccessibility.d.ts.map +1 -0
  106. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastCollapse.d.ts +19 -0
  107. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastCollapse.d.ts.map +1 -0
  108. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastGesture.d.ts +14 -0
  109. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastGesture.d.ts.map +1 -0
  110. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastMotion.d.ts +15 -0
  111. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastMotion.d.ts.map +1 -0
  112. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastViewportStyles.d.ts +21 -0
  113. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastViewportStyles.d.ts.map +1 -0
  114. package/dist/typescript/src/lib/Components/core/Toast/index.d.ts +5 -0
  115. package/dist/typescript/src/lib/Components/core/Toast/index.d.ts.map +1 -0
  116. package/dist/typescript/src/lib/Components/core/Toast/types.d.ts +75 -0
  117. package/dist/typescript/src/lib/Components/core/Toast/types.d.ts.map +1 -0
  118. package/dist/typescript/src/lib/Components/core/index.d.ts +2 -0
  119. package/dist/typescript/src/lib/Components/core/index.d.ts.map +1 -1
  120. package/package.json +3 -3
  121. package/src/lib/Components/core/AmountDisplay/AmountDisplay.test.tsx +138 -4
  122. package/src/lib/Components/core/AmountDisplay/AmountDisplay.tsx +13 -6
  123. package/src/lib/Components/core/BottomSheet/BottomSheet.stories.tsx +51 -0
  124. package/src/lib/Components/core/CardButton/CardButton.mdx +4 -0
  125. package/src/lib/Components/core/CardButton/CardButton.stories.tsx +1 -0
  126. package/src/lib/Components/core/CardButton/CardButton.tsx +2 -0
  127. package/src/lib/Components/core/Link/Link.figma.tsx +1 -0
  128. package/src/lib/Components/core/Link/Link.mdx +3 -2
  129. package/src/lib/Components/core/Link/Link.stories.tsx +3 -2
  130. package/src/lib/Components/core/Link/Link.test.tsx +2 -0
  131. package/src/lib/Components/core/Link/Link.tsx +3 -1
  132. package/src/lib/Components/core/Link/types.ts +1 -1
  133. package/src/lib/Components/core/MenuList/MenuList.mdx +14 -1
  134. package/src/lib/Components/core/MenuList/MenuList.stories.tsx +30 -2
  135. package/src/lib/Components/core/MenuList/MenuList.test.tsx +72 -2
  136. package/src/lib/Components/core/MenuList/MenuList.tsx +94 -11
  137. package/src/lib/Components/core/MenuList/types.ts +29 -7
  138. package/src/lib/Components/core/SegmentedControl/SegmentedControl.tsx +1 -1
  139. package/src/lib/Components/core/Stepper/Stepper.mdx +37 -16
  140. package/src/lib/Components/core/Stepper/Stepper.stories.tsx +50 -2
  141. package/src/lib/Components/core/Stepper/Stepper.test.tsx +29 -1
  142. package/src/lib/Components/core/Stepper/Stepper.tsx +73 -32
  143. package/src/lib/Components/core/Stepper/types.ts +12 -2
  144. package/src/lib/Components/core/Timeline/Timeline.figma.tsx +79 -0
  145. package/src/lib/Components/core/Timeline/Timeline.mdx +49 -0
  146. package/src/lib/Components/core/Timeline/Timeline.stories.tsx +250 -0
  147. package/src/lib/Components/core/Timeline/Timeline.test.tsx +275 -0
  148. package/src/lib/Components/core/Timeline/Timeline.tsx +576 -0
  149. package/src/lib/Components/core/Timeline/index.ts +2 -0
  150. package/src/lib/Components/core/Timeline/types.ts +124 -0
  151. package/src/lib/Components/core/Toast/Toast.figma.tsx +36 -0
  152. package/src/lib/Components/core/Toast/Toast.mdx +203 -0
  153. package/src/lib/Components/core/Toast/Toast.stories.tsx +260 -0
  154. package/src/lib/Components/core/Toast/Toast.test.tsx +181 -0
  155. package/src/lib/Components/core/Toast/Toast.tsx +163 -0
  156. package/src/lib/Components/core/Toast/Toaster.test.tsx +687 -0
  157. package/src/lib/Components/core/Toast/Toaster.tsx +157 -0
  158. package/src/lib/Components/core/Toast/hooks/useToastAccessibility.ts +82 -0
  159. package/src/lib/Components/core/Toast/hooks/useToastCollapse.ts +38 -0
  160. package/src/lib/Components/core/Toast/hooks/useToastGesture.ts +83 -0
  161. package/src/lib/Components/core/Toast/hooks/useToastMotion.ts +71 -0
  162. package/src/lib/Components/core/Toast/hooks/useToastViewportStyles.ts +45 -0
  163. package/src/lib/Components/core/Toast/index.ts +4 -0
  164. package/src/lib/Components/core/Toast/types.ts +94 -0
  165. package/src/lib/Components/core/index.ts +2 -0
@@ -0,0 +1,157 @@
1
+ import {
2
+ resolveDurationMs,
3
+ resolveMaxItems,
4
+ toastStore,
5
+ useToastBacklog,
6
+ useToastLifecycle,
7
+ } from '@ledgerhq/lumen-utils-shared';
8
+ import { useEffect, useState, useSyncExternalStore } from 'react';
9
+ import { View } from 'react-native';
10
+ import { GestureDetector } from 'react-native-gesture-handler';
11
+ import Animated from 'react-native-reanimated';
12
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
13
+ import { useToastAccessibility } from './hooks/useToastAccessibility';
14
+ import { useToastCollapse } from './hooks/useToastCollapse';
15
+ import { useToastGesture } from './hooks/useToastGesture';
16
+ import { useToastMotion } from './hooks/useToastMotion';
17
+ import { useToastViewportStyles } from './hooks/useToastViewportStyles';
18
+ import { Toast } from './Toast';
19
+ import type { ToasterProps, ToastItem, ToastPosition } from './types';
20
+
21
+ const ToastQueueItem = ({
22
+ item,
23
+ durationMs,
24
+ queued,
25
+ position,
26
+ onDismiss,
27
+ }: {
28
+ item: ToastItem;
29
+ durationMs: number;
30
+ queued: boolean;
31
+ position: ToastPosition;
32
+ onDismiss: () => void;
33
+ }) => {
34
+ const exiting = item.exiting ?? false;
35
+ const [held, setHeld] = useState(false);
36
+
37
+ useToastLifecycle({ durationMs, paused: held, exiting, onDismiss });
38
+ const { animatedStyle, translateX, markDismissedViaSwipe } = useToastMotion({
39
+ position,
40
+ queued,
41
+ exiting,
42
+ });
43
+ const { gesture } = useToastGesture({
44
+ dismissible: item.dismissible,
45
+ translateX,
46
+ onHoldChange: setHeld,
47
+ onSwipeDismiss: () => {
48
+ markDismissedViaSwipe();
49
+ onDismiss();
50
+ },
51
+ });
52
+ const { collapseStyle, handleLayout } = useToastCollapse({
53
+ position,
54
+ exiting,
55
+ });
56
+ const accessibilityProps = useToastAccessibility({
57
+ item,
58
+ exiting,
59
+ onDismiss,
60
+ });
61
+
62
+ return (
63
+ <Animated.View testID='toast-collapse' style={collapseStyle}>
64
+ <GestureDetector gesture={gesture}>
65
+ <Animated.View
66
+ testID='toast-entry'
67
+ style={animatedStyle}
68
+ onLayout={handleLayout}
69
+ {...accessibilityProps}
70
+ >
71
+ <Toast
72
+ appearance={item.appearance}
73
+ loading={item.loading}
74
+ title={item.title}
75
+ action={item.action}
76
+ />
77
+ </Animated.View>
78
+ </GestureDetector>
79
+ </Animated.View>
80
+ );
81
+ };
82
+
83
+ /**
84
+ * Subscribes to the module-level toast store and renders the queue viewport
85
+ * as an absolutely-positioned overlay. Mount it once, near the app root — it
86
+ * takes no children. `toast.*` from `@ledgerhq/lumen-utils-shared` works even
87
+ * before this mounts, or from outside the React tree entirely.
88
+ *
89
+ * Mount exactly one `<Toaster />` for the whole app. Every instance renders
90
+ * the full queue, so a second one duplicates every toast on screen — mounting
91
+ * more than one logs a console warning in development.
92
+ *
93
+ * Toasts are dismissed by swiping left or right; there is no close icon.
94
+ * Screen-reader users get the dismissal and the inline action as accessibility
95
+ * actions instead, and each toast is announced when it appears or changes.
96
+ * Touching a toast — a hold or an in-progress swipe — pauses its auto-dismiss
97
+ * timer until the finger is released.
98
+ * Requires `react-native-gesture-handler`'s `GestureHandlerRootView` at the
99
+ * app root.
100
+ *
101
+ * @see {@link https://ldls-react-native.vercel.app/?path=/docs/rnative-toast--docs Guidelines}
102
+ *
103
+ * @example
104
+ * import { Toaster } from '@ledgerhq/lumen-ui-rnative';
105
+ *
106
+ * function App() {
107
+ * return (
108
+ * <>
109
+ * <Toaster position="bottom" maxItems={1} />
110
+ * <Screens />
111
+ * </>
112
+ * );
113
+ * }
114
+ */
115
+ export const Toaster = ({
116
+ maxItems = 1,
117
+ position = 'bottom',
118
+ insets = {},
119
+ durations,
120
+ }: ToasterProps) => {
121
+ const items = useSyncExternalStore(
122
+ toastStore.subscribe,
123
+ toastStore.getSnapshot,
124
+ );
125
+ const safeAreaInsets = useSafeAreaInsets();
126
+ const viewportStyles = useToastViewportStyles({
127
+ position,
128
+ safeAreaTop: safeAreaInsets.top,
129
+ safeAreaBottom: safeAreaInsets.bottom,
130
+ insets,
131
+ });
132
+
133
+ useEffect(() => toastStore.registerRenderer(), []);
134
+
135
+ const visibleSlots = resolveMaxItems(maxItems);
136
+ const visibleItems = items.slice(0, visibleSlots);
137
+ const isQueued = useToastBacklog(items, visibleSlots);
138
+
139
+ return (
140
+ <View
141
+ testID='toast-viewport'
142
+ pointerEvents='box-none'
143
+ style={viewportStyles.root}
144
+ >
145
+ {visibleItems.map((item) => (
146
+ <ToastQueueItem
147
+ key={item.id}
148
+ item={item}
149
+ durationMs={resolveDurationMs(item, durations)}
150
+ queued={isQueued(item.id)}
151
+ position={position}
152
+ onDismiss={() => toastStore.dismiss(item.id)}
153
+ />
154
+ ))}
155
+ </View>
156
+ );
157
+ };
@@ -0,0 +1,82 @@
1
+ import { useEffect } from 'react';
2
+ import {
3
+ AccessibilityInfo,
4
+ Platform,
5
+ type AccessibilityActionEvent,
6
+ type AccessibilityActionInfo,
7
+ type ViewProps,
8
+ } from 'react-native';
9
+ import { useCommonTranslation } from '../../../../../i18n';
10
+ import type { ToastItem } from '../types';
11
+
12
+ type UseToastAccessibilityArgs = {
13
+ item: ToastItem;
14
+ exiting: boolean;
15
+ onDismiss: () => void;
16
+ };
17
+
18
+ type ToastAccessibilityProps = Pick<
19
+ ViewProps,
20
+ | 'accessible'
21
+ | 'accessibilityLabel'
22
+ | 'accessibilityState'
23
+ | 'accessibilityActions'
24
+ | 'onAccessibilityAction'
25
+ | 'onAccessibilityEscape'
26
+ >;
27
+
28
+ const DISMISS_ACTION = 'dismiss';
29
+ const TOAST_ACTION = 'toastAction';
30
+
31
+ /**
32
+ * Screen readers capture swipes for their own navigation, so the swipe-to-dismiss
33
+ * gesture is unreachable for them. The toast is exposed as a single element
34
+ * whose dismissal and inline action are custom accessibility actions instead
35
+ * (VoiceOver rotor, TalkBack actions menu, iOS two-finger scrub to escape).
36
+ */
37
+ export const useToastAccessibility = ({
38
+ item,
39
+ exiting,
40
+ onDismiss,
41
+ }: UseToastAccessibilityArgs): ToastAccessibilityProps => {
42
+ const { t } = useCommonTranslation();
43
+ const { title, appearance, loading, dismissible, action } = item;
44
+
45
+ useEffect(() => {
46
+ if (Platform.OS !== 'ios' || exiting) return;
47
+ AccessibilityInfo.announceForAccessibilityWithOptions(title, {
48
+ queue: appearance !== 'warning' && appearance !== 'error',
49
+ });
50
+ }, [title, appearance, exiting]);
51
+
52
+ const accessibilityActions: AccessibilityActionInfo[] = [];
53
+ if (action) {
54
+ accessibilityActions.push({ name: TOAST_ACTION, label: action.label });
55
+ }
56
+ if (dismissible) {
57
+ accessibilityActions.push({
58
+ name: DISMISS_ACTION,
59
+ label: t('common.closeAriaLabel'),
60
+ });
61
+ }
62
+
63
+ const handleAccessibilityAction = (event: AccessibilityActionEvent): void => {
64
+ switch (event.nativeEvent.actionName) {
65
+ case TOAST_ACTION:
66
+ action?.onAction();
67
+ break;
68
+ case DISMISS_ACTION:
69
+ onDismiss();
70
+ break;
71
+ }
72
+ };
73
+
74
+ return {
75
+ accessible: true,
76
+ accessibilityLabel: title,
77
+ accessibilityState: { busy: loading },
78
+ accessibilityActions,
79
+ onAccessibilityAction: handleAccessibilityAction,
80
+ onAccessibilityEscape: dismissible ? onDismiss : undefined,
81
+ };
82
+ };
@@ -0,0 +1,38 @@
1
+ import { EXIT_ANIMATION_MS } from '@ledgerhq/lumen-utils-shared';
2
+ import { useCallback, useMemo, useState } from 'react';
3
+ import type { LayoutChangeEvent } from 'react-native';
4
+ import { useTheme } from '../../../../../styles';
5
+ import type { ToastPosition } from '../types';
6
+
7
+ type UseToastCollapseArgs = {
8
+ position: ToastPosition;
9
+ exiting: boolean;
10
+ };
11
+
12
+ export const useToastCollapse = ({
13
+ position,
14
+ exiting,
15
+ }: UseToastCollapseArgs) => {
16
+ const { theme } = useTheme();
17
+ const [measuredHeight, setMeasuredHeight] = useState<number>();
18
+ const handleLayout = useCallback((event: LayoutChangeEvent) => {
19
+ setMeasuredHeight(event.nativeEvent.layout.height);
20
+ }, []);
21
+
22
+ const collapseStyle = useMemo(() => {
23
+ const fullHeight =
24
+ measuredHeight === undefined
25
+ ? undefined
26
+ : measuredHeight + theme.spacings.s8;
27
+ return {
28
+ width: '100%',
29
+ justifyContent: position === 'top' ? 'flex-start' : 'flex-end',
30
+ height: exiting ? 0 : fullHeight,
31
+ transitionProperty: 'height',
32
+ transitionDuration: EXIT_ANIMATION_MS,
33
+ transitionTimingFunction: 'ease-out',
34
+ } as const;
35
+ }, [exiting, measuredHeight, position, theme.spacings.s8]);
36
+
37
+ return { collapseStyle, handleLayout };
38
+ };
@@ -0,0 +1,83 @@
1
+ import { useRef } from 'react';
2
+ import { useWindowDimensions } from 'react-native';
3
+ import { Gesture, type PanGesture } from 'react-native-gesture-handler';
4
+ import { withTiming, type SharedValue } from 'react-native-reanimated';
5
+ import { scheduleOnRN } from 'react-native-worklets';
6
+
7
+ const SWIPE_DISMISS_THRESHOLD_PX = 80;
8
+
9
+ type UseToastGestureArgs = {
10
+ dismissible: boolean;
11
+ translateX: SharedValue<number>;
12
+ onHoldChange: (held: boolean) => void;
13
+ onSwipeDismiss: () => void;
14
+ };
15
+
16
+ type UseToastGestureReturn = {
17
+ gesture: PanGesture;
18
+ };
19
+
20
+ export const useToastGesture = ({
21
+ dismissible,
22
+ translateX,
23
+ onHoldChange,
24
+ onSwipeDismiss,
25
+ }: UseToastGestureArgs): UseToastGestureReturn => {
26
+ const { width: windowWidth } = useWindowDimensions();
27
+
28
+ const onSwipeDismissRef = useRef(onSwipeDismiss);
29
+ onSwipeDismissRef.current = onSwipeDismiss;
30
+ const handleSwipeDismissRef = useRef(() => {
31
+ onSwipeDismissRef.current();
32
+ });
33
+
34
+ const onHoldChangeRef = useRef(onHoldChange);
35
+ onHoldChangeRef.current = onHoldChange;
36
+ const handleHoldStartRef = useRef(() => {
37
+ onHoldChangeRef.current(true);
38
+ });
39
+ const handleHoldEndRef = useRef(() => {
40
+ onHoldChangeRef.current(false);
41
+ });
42
+
43
+ const pan = Gesture.Pan()
44
+ .activeOffsetX([-10, 10])
45
+ .failOffsetY([-10, 10])
46
+ .cancelsTouchesInView(false)
47
+ .onTouchesDown(() => {
48
+ 'worklet';
49
+ scheduleOnRN(handleHoldStartRef.current);
50
+ })
51
+ .onTouchesUp((e) => {
52
+ 'worklet';
53
+ if (e.numberOfTouches === 0) scheduleOnRN(handleHoldEndRef.current);
54
+ })
55
+ .onTouchesCancelled(() => {
56
+ 'worklet';
57
+ scheduleOnRN(handleHoldEndRef.current);
58
+ })
59
+ .onFinalize(() => {
60
+ 'worklet';
61
+ scheduleOnRN(handleHoldEndRef.current);
62
+ })
63
+ .onUpdate((e) => {
64
+ 'worklet';
65
+ if (!dismissible) return;
66
+ translateX.value = e.translationX;
67
+ })
68
+ .onEnd((e) => {
69
+ 'worklet';
70
+ if (!dismissible) return;
71
+ if (Math.abs(e.translationX) > SWIPE_DISMISS_THRESHOLD_PX) {
72
+ translateX.value = withTiming(
73
+ e.translationX > 0 ? windowWidth : -windowWidth,
74
+ { duration: 150 },
75
+ );
76
+ scheduleOnRN(handleSwipeDismissRef.current);
77
+ } else {
78
+ translateX.value = withTiming(0, { duration: 150 });
79
+ }
80
+ });
81
+
82
+ return { gesture: pan };
83
+ };
@@ -0,0 +1,71 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import {
3
+ useAnimatedStyle,
4
+ useSharedValue,
5
+ withTiming,
6
+ type SharedValue,
7
+ } from 'react-native-reanimated';
8
+ import { useTimingConfig } from '../../../animations/useTimingConfig';
9
+ import type { ToastPosition } from '../types';
10
+
11
+ type UseToastMotionArgs = {
12
+ position: ToastPosition;
13
+ queued: boolean;
14
+ exiting: boolean;
15
+ };
16
+
17
+ type UseToastMotionReturn = {
18
+ animatedStyle: ReturnType<typeof useAnimatedStyle>;
19
+ translateX: SharedValue<number>;
20
+ markDismissedViaSwipe: () => void;
21
+ };
22
+
23
+ export const useToastMotion = ({
24
+ position,
25
+ queued,
26
+ exiting,
27
+ }: UseToastMotionArgs): UseToastMotionReturn => {
28
+ const enterTiming = useTimingConfig({ duration: 200, easing: 'easeIn' });
29
+ const exitTiming = useTimingConfig({ duration: 200, easing: 'easeOut' });
30
+ const edgeOffset = position === 'top' ? -10 : 10;
31
+ // A toast promoted from the backlog slides out from behind the stack
32
+ // rather than from the anchored edge.
33
+ const enterOffset = queued ? -edgeOffset : edgeOffset;
34
+
35
+ const opacity = useSharedValue(0);
36
+ const translateY = useSharedValue(enterOffset);
37
+ const translateX = useSharedValue(0);
38
+
39
+ const dismissedViaSwipeRef = useRef(false);
40
+ const markDismissedViaSwipe = useRef(() => {
41
+ dismissedViaSwipeRef.current = true;
42
+ }).current;
43
+
44
+ useEffect(() => {
45
+ translateY.value = withTiming(0, enterTiming);
46
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ }, []);
48
+
49
+ useEffect(() => {
50
+ opacity.value = withTiming(
51
+ exiting ? 0 : 1,
52
+ exiting ? exitTiming : enterTiming,
53
+ );
54
+ if (exiting && !dismissedViaSwipeRef.current) {
55
+ translateY.value = withTiming(edgeOffset, exitTiming);
56
+ }
57
+ }, [exiting, enterTiming, exitTiming, edgeOffset, opacity, translateY]);
58
+
59
+ const animatedStyle = useAnimatedStyle(
60
+ () => ({
61
+ opacity: opacity.value,
62
+ transform: [
63
+ { translateY: translateY.value },
64
+ { translateX: translateX.value },
65
+ ],
66
+ }),
67
+ [opacity, translateY, translateX],
68
+ );
69
+
70
+ return { animatedStyle, translateX, markDismissedViaSwipe };
71
+ };
@@ -0,0 +1,45 @@
1
+ import { useStyleSheet } from '../../../../../styles';
2
+ import type { ToastInsets, ToastPosition } from '../types';
3
+
4
+ type UseToastViewportStylesArgs = {
5
+ position: ToastPosition;
6
+ safeAreaTop: number;
7
+ safeAreaBottom: number;
8
+ insets: ToastInsets;
9
+ };
10
+
11
+ export const useToastViewportStyles = ({
12
+ position,
13
+ safeAreaTop,
14
+ safeAreaBottom,
15
+ insets,
16
+ }: UseToastViewportStylesArgs) =>
17
+ useStyleSheet(
18
+ (t) => ({
19
+ root: {
20
+ position: 'absolute',
21
+ left: insets.left ?? 0,
22
+ right: insets.right ?? 0,
23
+ zIndex: 50,
24
+ alignItems: 'center',
25
+ flexDirection: position === 'top' ? 'column' : 'column-reverse',
26
+ top:
27
+ position === 'top'
28
+ ? safeAreaTop + (insets.top ?? 0) + t.spacings.s24
29
+ : undefined,
30
+ bottom:
31
+ position === 'bottom'
32
+ ? safeAreaBottom + (insets.bottom ?? 0) + t.spacings.s24
33
+ : undefined,
34
+ },
35
+ }),
36
+ [
37
+ position,
38
+ safeAreaTop,
39
+ safeAreaBottom,
40
+ insets.top,
41
+ insets.bottom,
42
+ insets.left,
43
+ insets.right,
44
+ ],
45
+ );
@@ -0,0 +1,4 @@
1
+ export { toast } from '@ledgerhq/lumen-utils-shared';
2
+ export { Toast } from './Toast';
3
+ export { Toaster } from './Toaster';
4
+ export * from './types';
@@ -0,0 +1,94 @@
1
+ import type {
2
+ ToastAction,
3
+ ToastAppearance,
4
+ } from '@ledgerhq/lumen-utils-shared';
5
+ import type { StyledViewProps } from '../../../../styles';
6
+
7
+ // Re-exported for consumers importing from '@ledgerhq/lumen-ui-rnative': the
8
+ // domain model (appearance/duration/item/controller/...) is shared with
9
+ // ui-react and lives in utils-shared.
10
+ export type {
11
+ ToastAction,
12
+ ToastAppearance,
13
+ ToastController,
14
+ ToastItem,
15
+ ToastNotifyOptions,
16
+ ToastPromiseOptions,
17
+ ToastPromiseState,
18
+ ToastUpdateOptions,
19
+ } from '@ledgerhq/lumen-utils-shared';
20
+
21
+ /**
22
+ * Edge the queue is anchored to. Items enter from the same edge, and are
23
+ * dismissible by swiping left or right.
24
+ */
25
+ export type ToastPosition = 'top' | 'bottom';
26
+
27
+ /**
28
+ * Extra space to clear beyond the safe-area inset, on each edge — e.g. the
29
+ * height of a custom tab bar. `top` and `bottom` apply only to the edge
30
+ * matching `position` — the other is ignored. All default to `0`; a fixed
31
+ * breathing-room gap is always added on top of `top`/`bottom` separately,
32
+ * so this only needs to describe the extra obstruction, not the full gap.
33
+ */
34
+ export type ToastInsets = {
35
+ top?: number;
36
+ left?: number;
37
+ bottom?: number;
38
+ right?: number;
39
+ };
40
+
41
+ /**
42
+ * Props for the presentational `Toast` item.
43
+ */
44
+ export type ToastProps = {
45
+ /**
46
+ * The status of the toast, driving the leading icon.
47
+ * @default info
48
+ */
49
+ appearance?: ToastAppearance;
50
+ /**
51
+ * Replaces the leading status icon with a spinner.
52
+ * @default false
53
+ */
54
+ loading?: boolean;
55
+ /**
56
+ * The main text. Wraps over up to five lines, then truncates.
57
+ * @required
58
+ */
59
+ title: string;
60
+ /**
61
+ * Optional trailing action button. Pressing it does not dismiss the toast.
62
+ * It wraps onto its own row, aligned with the title, when it cannot share
63
+ * the title's row.
64
+ */
65
+ action?: ToastAction;
66
+ } & StyledViewProps;
67
+
68
+ /**
69
+ * Props for `Toaster`.
70
+ */
71
+ export type ToasterProps = {
72
+ /**
73
+ * Maximum number of toasts visible at once. Must be a positive integer.
74
+ * Extra items wait in a FIFO backlog and appear as visible slots free up.
75
+ * @default 1
76
+ */
77
+ maxItems?: number;
78
+ /**
79
+ * The edge the queue is anchored to.
80
+ * @default bottom
81
+ */
82
+ position?: ToastPosition;
83
+ /**
84
+ * Extra space to clear beyond the safe-area inset, on each edge — e.g.
85
+ * the height of a custom tab bar for `top`/`bottom`, or horizontal
86
+ * margins for the queue's width via `left`/`right`.
87
+ * @default {}
88
+ */
89
+ insets?: ToastInsets;
90
+ /**
91
+ * Per-appearance duration overrides, layered over the Lumen status defaults.
92
+ */
93
+ durations?: Partial<Record<ToastAppearance, number>>;
94
+ };
@@ -44,5 +44,7 @@ export * from './TextInput';
44
44
  export * from './ThemeProvider';
45
45
  export * from './Tile';
46
46
  export * from './TileButton';
47
+ export * from './Timeline';
48
+ export * from './Toast';
47
49
  export * from './Tooltip';
48
50
  export * from './Trend';