@momo-kits/foundation 0.168.1-rn862.1 → 0.169.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.
Files changed (109) hide show
  1. package/Application/BottomSheet.hooks.ts +195 -0
  2. package/Application/BottomSheet.parts.tsx +147 -0
  3. package/Application/BottomSheet.styles.ts +43 -0
  4. package/Application/BottomSheet.tsx +76 -279
  5. package/Application/BottomTab/ActiveIndicator.tsx +90 -0
  6. package/Application/BottomTab/BottomTabBar.styles.ts +65 -0
  7. package/Application/BottomTab/BottomTabBar.tsx +229 -276
  8. package/Application/BottomTab/BottomTabInset.tsx +14 -0
  9. package/Application/BottomTab/CurvedContainer.tsx +153 -0
  10. package/Application/BottomTab/CustomBottomTabItem.tsx +132 -108
  11. package/Application/BottomTab/DuoBarCompression.tsx +4 -12
  12. package/Application/BottomTab/DuoRailTabBar.tsx +227 -0
  13. package/Application/BottomTab/DuoTabBar.styles.ts +81 -0
  14. package/Application/BottomTab/DuoTabBar.tsx +29 -495
  15. package/Application/BottomTab/TabBarIcon.tsx +160 -72
  16. package/Application/BottomTab/TabScreen.tsx +164 -0
  17. package/Application/BottomTab/index.tsx +84 -351
  18. package/Application/BottomTab/metrics.ts +164 -0
  19. package/Application/BottomTab/tabItems.ts +46 -0
  20. package/Application/BottomTab/usePressLift.ts +32 -0
  21. package/Application/Components/DuoGlassBackground.tsx +7 -9
  22. package/Application/Components/HeaderAnimated.tsx +1 -1
  23. package/Application/Components/HeaderBackground.tsx +1 -1
  24. package/Application/Components/HeaderExtendHeader.tsx +17 -11
  25. package/Application/Components/HeaderRight.styles.ts +144 -0
  26. package/Application/Components/HeaderRight.tsx +6 -528
  27. package/Application/Components/HeaderTitle.shared.ts +43 -0
  28. package/Application/Components/HeaderTitle.styles.ts +125 -0
  29. package/Application/Components/HeaderTitle.tsx +12 -576
  30. package/Application/Components/HeaderToolkitAction.tsx +208 -0
  31. package/Application/Components/NavigationButton.tsx +9 -6
  32. package/Application/Components/SearchHeader.tsx +1 -1
  33. package/Application/Components/SwipeBackHaptic.tsx +95 -0
  34. package/Application/Components/TitleJourney.tsx +110 -0
  35. package/Application/Components/TitleLocation.tsx +73 -0
  36. package/Application/Components/TitleUser.tsx +304 -0
  37. package/Application/Components/useToolkitActions.tsx +233 -0
  38. package/Application/ModalIconButton.tsx +66 -0
  39. package/Application/ModalScreen.tsx +39 -18
  40. package/Application/Navigation.ts +1 -1
  41. package/Application/NavigationContainer.tsx +7 -8
  42. package/Application/StackScreen.tracking.ts +158 -0
  43. package/Application/StackScreen.tsx +10 -137
  44. package/Application/WidgetContainer.tsx +10 -3
  45. package/Application/__tests__/modalLayout.test.ts +128 -0
  46. package/Application/hooks.ts +137 -0
  47. package/Application/index.ts +13 -1
  48. package/Application/modalLayout.ts +177 -0
  49. package/Application/navigationOptions.tsx +217 -0
  50. package/Application/types.header.ts +116 -0
  51. package/Application/types.tabs.ts +48 -0
  52. package/Application/types.theme.ts +87 -0
  53. package/Application/types.ts +12 -244
  54. package/Application/utils.ts +107 -0
  55. package/Badge/BadgeRibbon.tsx +3 -3
  56. package/Badge/styles.ts +2 -0
  57. package/Button/index.tsx +16 -136
  58. package/Button/styles.ts +1 -1
  59. package/Button/utils.ts +139 -0
  60. package/CheckBox/index.tsx +1 -6
  61. package/Divider/DashDivider.tsx +10 -11
  62. package/Divider/index.tsx +18 -8
  63. package/Image/index.tsx +1 -46
  64. package/Input/Input.tsx +7 -8
  65. package/Input/InputDropDown.tsx +3 -4
  66. package/Input/InputMoney.tsx +38 -164
  67. package/Input/InputMoneyView.tsx +187 -0
  68. package/Input/InputOTP.tsx +1 -1
  69. package/Input/InputPhoneNumber.tsx +5 -1
  70. package/Input/InputSearch.tsx +2 -108
  71. package/Input/InputTextArea.tsx +1 -5
  72. package/Input/SearchTextTyping.tsx +104 -0
  73. package/Input/common.tsx +4 -4
  74. package/Input/moneyUtils.ts +17 -0
  75. package/Input/styles.ts +26 -2
  76. package/Layout/FloatingButton.tsx +22 -21
  77. package/Layout/ReservedRegions.tsx +21 -4
  78. package/Layout/Screen.tsx +74 -670
  79. package/Layout/Section.tsx +1 -2
  80. package/Layout/index.ts +10 -4
  81. package/Layout/layoutMetrics.ts +58 -0
  82. package/Layout/layoutTypes.ts +86 -0
  83. package/Layout/screenContent.tsx +90 -0
  84. package/Layout/screenFooter.tsx +53 -0
  85. package/Layout/screenHeader.tsx +315 -0
  86. package/Layout/screenQuickReturn.tsx +67 -0
  87. package/Layout/screenScroll.ts +110 -0
  88. package/Layout/screenTypes.ts +134 -0
  89. package/Layout/styles.ts +2 -0
  90. package/Layout/utils.ts +10 -144
  91. package/Loader/DotLoader.tsx +7 -3
  92. package/Loader/ProgressBar.tsx +2 -6
  93. package/Loader/Spinner.tsx +7 -3
  94. package/Loader/styles.ts +4 -0
  95. package/Popup/PopupNotify.tsx +70 -64
  96. package/Popup/PopupPromotion.tsx +5 -4
  97. package/Popup/types.ts +7 -0
  98. package/Popup/utils.ts +46 -24
  99. package/Radio/index.tsx +2 -10
  100. package/Radio/styles.ts +6 -0
  101. package/Skeleton/index.tsx +1 -9
  102. package/Skeleton/styles.ts +1 -0
  103. package/Tag/index.tsx +3 -3
  104. package/Text/index.tsx +11 -2
  105. package/Title/index.tsx +2 -9
  106. package/Title/styles.ts +6 -0
  107. package/package.json +21 -22
  108. package/Application/device.ts +0 -29
  109. package/Application/utils.tsx +0 -497
@@ -1,497 +0,0 @@
1
- import React, {
2
- useCallback,
3
- useContext,
4
- useEffect,
5
- useMemo,
6
- useRef,
7
- } from 'react';
8
- import {
9
- CardAnimationContext,
10
- CardStyleInterpolators,
11
- StackNavigationOptions,
12
- TransitionPresets,
13
- } from '@react-navigation/stack';
14
- import type {
15
- StackCardInterpolatedStyle,
16
- StackCardInterpolationProps,
17
- } from '@react-navigation/stack';
18
- import type { NavigationState, PartialState } from '@react-navigation/native';
19
- import type { HeaderTitleProps, NavigationOptions } from './types';
20
- import { ApplicationContext } from '../Context';
21
- import { Colors, Spacing } from '../Consts';
22
- import { Animated, AppState, NativeModules, Platform } from 'react-native';
23
- import type { SharedValue } from 'react-native-reanimated';
24
- import { useSharedValue } from 'react-native-reanimated';
25
- import {
26
- MiniAppContext,
27
- ScreenContext,
28
- TrackingScopeContext,
29
- } from '../Context';
30
- import { HeaderTitle, TitleCustom } from './Components/HeaderTitle';
31
- import { HeaderBackground } from './Components/HeaderBackground';
32
- import { HeaderLeft } from './Components/HeaderLeft';
33
- import { HeaderRight } from './Components/HeaderRight';
34
-
35
- const forStackTransitionWithOverlay = (
36
- props: StackCardInterpolationProps,
37
- ): StackCardInterpolatedStyle => {
38
- const { cardStyle } = CardStyleInterpolators.forHorizontalIOS(props);
39
- return {
40
- cardStyle,
41
- shadowStyle: {
42
- shadowOpacity: props.current.progress.interpolate({
43
- inputRange: [0, 1],
44
- outputRange: [0, 0.3],
45
- extrapolate: 'clamp',
46
- }),
47
- },
48
- overlayStyle: {
49
- backgroundColor: '#FDEAF4',
50
- opacity: props.current.progress.interpolate({
51
- inputRange: [0, 1],
52
- outputRange: [0, 0.6],
53
- extrapolate: 'clamp',
54
- }),
55
- },
56
- };
57
- };
58
-
59
- /**
60
- * default options for stack screen
61
- */
62
- const getStackOptions = (): StackNavigationOptions => {
63
- return {
64
- headerTitleAlign: 'left',
65
- headerTitle: props => <HeaderTitle {...props} />,
66
- headerTitleContainerStyle: {
67
- marginLeft: 0,
68
- marginEnd: 0,
69
- marginStart: 0,
70
- marginHorizontal: 0,
71
- marginVertical: 0,
72
- margin: 0,
73
- left: Spacing.S,
74
- },
75
- headerBackground: (props: any) => <HeaderBackground {...props} />,
76
- headerLeft: (props: any) => <HeaderLeft {...props} floating />,
77
- headerRight: (props: any) => <HeaderRight {...props} floating />,
78
- headerTintColor: Colors.black_17,
79
- gestureEnabled: Platform.OS === 'ios',
80
- ...TransitionPresets.SlideFromRightIOS,
81
- cardStyleInterpolator: forStackTransitionWithOverlay,
82
- cardOverlayEnabled: true,
83
- };
84
- };
85
-
86
- /**
87
- * default options for modal screen
88
- */
89
- const getModalOptions = (): StackNavigationOptions => {
90
- return {
91
- headerShown: false,
92
- headerBackground: undefined,
93
- cardStyle: { backgroundColor: 'transparent' },
94
- cardOverlayEnabled: true,
95
- animation: 'none',
96
- presentation: 'transparentModal',
97
- gestureEnabled: false,
98
- };
99
- };
100
-
101
- /**
102
- * screen owns its back flow (guard popup, custom handler or no back button),
103
- * so swipe back must not bypass it
104
- */
105
- const hasCustomBackHandling = (params: NavigationOptions) =>
106
- params.preventBack !== undefined || params.hiddenBack === true;
107
-
108
- /**
109
- * build react-navigation options
110
- */
111
- const getOptions = (
112
- params: NavigationOptions,
113
- animatedValue?: SharedValue<number>,
114
- ) => {
115
- let options: StackNavigationOptions = {};
116
-
117
- /**
118
- * left header factory
119
- */
120
- if (
121
- typeof params.onPressLeftHeader === 'function' ||
122
- typeof params.onBackHandler === 'function' ||
123
- params.preventBack !== undefined ||
124
- typeof params.hiddenBack === 'boolean'
125
- ) {
126
- let headerLeft: any = (props: any) => (
127
- <HeaderLeft
128
- {...props}
129
- preventBack={params.preventBack}
130
- onPressLeftHeader={params.onPressLeftHeader}
131
- onBackHandler={params.onBackHandler}
132
- floating
133
- />
134
- );
135
- if (params.hiddenBack) {
136
- headerLeft = null;
137
- options.headerTitleContainerStyle = {
138
- marginLeft: 0,
139
- marginEnd: 0,
140
- marginStart: 0,
141
- marginHorizontal: 0,
142
- marginVertical: 0,
143
- margin: 0,
144
- left: Spacing.M,
145
- };
146
- }
147
- options = {
148
- ...options,
149
- headerLeft,
150
- };
151
- }
152
-
153
- /**
154
- * title
155
- */
156
- if (params.headerTitle) {
157
- options = {
158
- ...options,
159
- ...exportHeaderTitle(params, animatedValue),
160
- };
161
- }
162
-
163
- /**
164
- * header right
165
- */
166
- if (params.headerRight) {
167
- options = {
168
- ...options,
169
- ...{
170
- headerRight: (props: any) => {
171
- return (
172
- <HeaderRight {...props} headerRight={params.headerRight} floating />
173
- );
174
- },
175
- },
176
- };
177
- }
178
-
179
- /**
180
- * only ever turns swipe back off, screens opt in via gestureEnabled
181
- */
182
- if (params.gestureEnabled === undefined && hasCustomBackHandling(params)) {
183
- options.gestureEnabled = false;
184
- }
185
-
186
- return {
187
- ...params,
188
- ...options,
189
- };
190
- };
191
-
192
- const exportHeaderTitle = (
193
- params: NavigationOptions,
194
- animatedValue?: SharedValue<number>,
195
- ): StackNavigationOptions => {
196
- if (typeof params.headerTitle === 'object') {
197
- return {
198
- headerTitleAlign: 'left',
199
- headerTitle: (props: any) => {
200
- return (
201
- <TitleCustom
202
- {...props}
203
- {...(params.headerTitle as HeaderTitleProps)}
204
- animatedValue={animatedValue}
205
- />
206
- );
207
- },
208
- };
209
- } else if (typeof params.headerTitle === 'string') {
210
- return {
211
- headerTitle: (props: any) => (
212
- <HeaderTitle
213
- {...props}
214
- children={params.headerTitle}
215
- animatedValue={animatedValue}
216
- />
217
- ),
218
- };
219
- }
220
- return {};
221
- };
222
-
223
- const setAutomationID = (accessibilityLabel = '') => {
224
- if (Platform.OS === 'ios') {
225
- return {
226
- accessible: true,
227
- testID: accessibilityLabel,
228
- accessibilityLabel: undefined,
229
- };
230
- } else {
231
- return {
232
- accessibilityLabel,
233
- };
234
- }
235
- };
236
-
237
- const useComponentId = (componentName: string, accessibilityLabel?: string) => {
238
- const app = useContext<any>(MiniAppContext);
239
- const screen = useContext<any>(ScreenContext);
240
- const { scopeName } = useContext<any>(TrackingScopeContext);
241
-
242
- const scope = scopeName ? `${scopeName}/` : '';
243
-
244
- const componentId = useMemo(() => {
245
- if (accessibilityLabel) {
246
- return accessibilityLabel;
247
- }
248
- return `${app.appId}/${app.code}/${screen.screenName}/${scope}${componentName}`;
249
- }, [
250
- accessibilityLabel,
251
- app.appId,
252
- app.code,
253
- screen.screenName,
254
- scope,
255
- componentName,
256
- ]);
257
-
258
- return { componentId };
259
- };
260
-
261
- const useAppState = () => {
262
- const isBackgroundToForeground = useRef(false);
263
- const appState = useRef(AppState.currentState);
264
-
265
- useEffect(() => {
266
- const subscription = AppState.addEventListener('change', nextAppState => {
267
- isBackgroundToForeground.current = !!(
268
- appState.current.match(/inactive|background/) &&
269
- nextAppState === 'active'
270
- );
271
- appState.current = nextAppState;
272
-
273
- if (isBackgroundToForeground.current) {
274
- setTimeout(() => {
275
- isBackgroundToForeground.current = false;
276
- }, 100);
277
- }
278
- });
279
-
280
- return () => {
281
- subscription.remove();
282
- };
283
- }, []);
284
-
285
- return {
286
- isBackgroundToForeground: isBackgroundToForeground.current,
287
- appState: appState.current,
288
- };
289
- };
290
-
291
- /**
292
- * screens the focused navigation branch can still pop.
293
- * only stack navigators count, switching bottom tab is not a back step
294
- */
295
- const getStackDepth = (
296
- state?: NavigationState | PartialState<NavigationState>,
297
- ): number => {
298
- const routes = state?.routes;
299
- if (!routes?.length) {
300
- return 0;
301
- }
302
-
303
- const index = state?.index ?? routes.length - 1;
304
- const depth = state?.type === 'stack' ? index : 0;
305
-
306
- return depth + getStackDepth(routes[index]?.state);
307
- };
308
-
309
- /**
310
- * report back ownership to the native container: `true` when the mini app sits
311
- * on its root screen and native may dismiss the rootview, `false` while
312
- * react-navigation still has screens (or a modal / bottom sheet) to pop.
313
- */
314
- const useNativeCanGoBack = () => {
315
- const lastValue = useRef<boolean | undefined>(undefined);
316
-
317
- return useCallback(
318
- (state?: NavigationState | PartialState<NavigationState>) => {
319
- const canDismiss = getStackDepth(state) === 0;
320
- if (lastValue.current === canDismiss) {
321
- return;
322
- }
323
-
324
- const setCanGoBack = NativeModules?.MiniAppModule?.setCanGoBack;
325
- if (typeof setCanGoBack !== 'function') {
326
- return;
327
- }
328
-
329
- lastValue.current = canDismiss;
330
- try {
331
- setCanGoBack(canDismiss);
332
- } catch (error) {
333
- console.warn('[NavigationContainer] setCanGoBack failed:', error);
334
- }
335
- },
336
- [],
337
- );
338
- };
339
-
340
- /**
341
- * Union of the two animation runtimes an internal foundation component might
342
- * receive. Public Screen props still accept React Native Animated.Value only;
343
- * this type keeps lower-level header/floating components compatible while they
344
- * render with reanimated.
345
- */
346
- export type AnimatedCompatValue = Animated.Value | SharedValue<number>;
347
-
348
- const isRNAnimatedValue = (v: unknown): v is Animated.Value =>
349
- !!v &&
350
- typeof (v as Animated.Value).setValue === 'function' &&
351
- typeof (v as Animated.Value).interpolate === 'function';
352
-
353
- const isSharedValue = (v: unknown): v is SharedValue<number> =>
354
- !!v && !isRNAnimatedValue(v) && 'value' in (v as object);
355
-
356
- const useNormalizedSharedValue = (
357
- input?: AnimatedCompatValue,
358
- ): SharedValue<number> => {
359
- const fallback = useSharedValue(0);
360
-
361
- useEffect(() => {
362
- if (!isRNAnimatedValue(input)) {
363
- return;
364
- }
365
- const id = input.addListener(({ value }) => {
366
- fallback.value = value;
367
- });
368
- return () => input.removeListener(id);
369
- }, [input, fallback]);
370
-
371
- if (isSharedValue(input)) {
372
- return input;
373
- }
374
- return fallback;
375
- };
376
-
377
- /**
378
- * Travel, in points, at which the swipe back gesture ticks. Flat and well short of
379
- * react-navigation's own `distance / 2` commit rule: the tick marks "the gesture is
380
- * recognised", not "you are past the point of no return".
381
- */
382
- const SWIPE_BACK_HAPTIC_THRESHOLD = 50;
383
-
384
- /**
385
- * `current.progress` is `gesture.interpolate(...)` built by CardStack
386
- * (@react-navigation/stack 7.4.2, views/Stack/CardStack.tsx `getProgressFromGesture`).
387
- * Only `Animated.Value.addListener` bridges native driver updates back to js, so the raw
388
- * translation has to be read off the interpolation's parent.
389
- *
390
- * Reaches into a private field. Every hop is optional and duck typed, so a shape change in
391
- * a future @react-navigation/stack degrades to "no haptic" rather than a crash.
392
- */
393
- const getSwipeGestureValue = (
394
- progress: Animated.AnimatedInterpolation<number> | undefined,
395
- ): Animated.Value | undefined => {
396
- const parent = (progress as { _parent?: unknown } | undefined)?._parent as
397
- | Animated.Value
398
- | undefined;
399
-
400
- const isListenable =
401
- typeof parent?.addListener === 'function' &&
402
- typeof parent?.removeListener === 'function';
403
- return isListenable ? parent : undefined;
404
- };
405
-
406
- const readAnimatedValue = (node: unknown, fallback: number): number => {
407
- const value = (node as { __getValue?: () => unknown } | undefined)?.__getValue?.();
408
- return typeof value === 'number' ? value : fallback;
409
- };
410
-
411
- /**
412
- * Haptic tick for the iOS swipe back gesture.
413
- *
414
- * Deliberately a leaf that renders nothing. Consuming `CardAnimationContext` re-renders on
415
- * every `Card` render, and an earlier version put that on `StackScreen` itself — which then
416
- * re-rendered the whole screen mid gesture and cost the pop: `Card` defers `onClose()` by
417
- * 32ms and clears that timer from `animate()`, which `componentDidUpdate` re-enters on any
418
- * render in the window. Keeping the subscription in a null leaf isolates it.
419
- *
420
- * Both listeners are installed on mount, never lazily inside the gesture: on the New
421
- * Architecture `addListener` queues `startListeningToAnimatedNodeValue` via
422
- * `queueOperationBlock`, and that queue is only drained by a React mount commit — which
423
- * never happens during a native driven pan.
424
- */
425
- const SwipeBackHaptic = () => {
426
- const { navigator } = useContext<any>(ApplicationContext);
427
- const animation = useContext(CardAnimationContext);
428
- const hasFired = useRef(false);
429
-
430
- useEffect(() => {
431
- if (Platform.OS !== 'ios' || !animation) {
432
- return;
433
- }
434
-
435
- const { swiping, inverted, current } = animation;
436
- const gesture = getSwipeGestureValue(current?.progress);
437
- if (!gesture || typeof swiping?.addListener !== 'function') {
438
- return;
439
- }
440
-
441
- let isSwiping = readAnimatedValue(swiping, 0) === 1;
442
-
443
- /**
444
- * sign, not magnitude: a leftward overdrag reports a negative translation and must
445
- * not count as progress toward dismissal
446
- */
447
- const direction = readAnimatedValue(inverted, 1);
448
-
449
- const swipingListener = swiping.addListener(({ value }) => {
450
- isSwiping = value === 1;
451
- if (!isSwiping) {
452
- hasFired.current = false;
453
- }
454
- });
455
-
456
- const gestureListener = gesture.addListener(({ value: translation }) => {
457
- if (!isSwiping) {
458
- return;
459
- }
460
-
461
- if (translation * direction < SWIPE_BACK_HAPTIC_THRESHOLD) {
462
- hasFired.current = false;
463
- return;
464
- }
465
-
466
- if (!hasFired.current) {
467
- hasFired.current = true;
468
- navigator?.maxApi?.triggerEventVibration?.('light');
469
- }
470
- });
471
-
472
- return () => {
473
- gesture.removeListener(gestureListener);
474
- swiping.removeListener(swipingListener);
475
- };
476
- }, [animation, navigator]);
477
-
478
- return null;
479
- };
480
-
481
- const isWhiteListDesignSystem = (context: any): boolean =>
482
- context?.designSystemConfig?.isWhiteListDesignSystem === true;
483
-
484
- export {
485
- getStackOptions,
486
- getModalOptions,
487
- getOptions,
488
- getStackDepth,
489
- exportHeaderTitle,
490
- setAutomationID,
491
- useComponentId,
492
- useAppState,
493
- useNativeCanGoBack,
494
- useNormalizedSharedValue,
495
- SwipeBackHaptic,
496
- isWhiteListDesignSystem,
497
- };