@momo-kits/foundation 0.168.1-beta.39 → 0.168.1-beta.40

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 (153) hide show
  1. package/Application/BottomSheet.tsx +398 -86
  2. package/Application/BottomTab/BottomTabBar.tsx +275 -215
  3. package/Application/BottomTab/CustomBottomTabItem.tsx +107 -131
  4. package/Application/BottomTab/DuoBarCompression.tsx +28 -14
  5. package/Application/BottomTab/DuoTabBar.tsx +540 -32
  6. package/Application/BottomTab/TabBarIcon.tsx +72 -146
  7. package/Application/BottomTab/index.tsx +353 -89
  8. package/Application/BottomTab/useLiquidSelection.ts +374 -0
  9. package/Application/Components/BackgroundImageView.tsx +0 -4
  10. package/Application/Components/DuoGlassBackground.tsx +5 -7
  11. package/Application/Components/HeaderAnimated.tsx +13 -41
  12. package/Application/Components/HeaderBackground.tsx +3 -20
  13. package/Application/Components/HeaderExtendHeader.tsx +46 -66
  14. package/Application/Components/HeaderLeft.tsx +18 -5
  15. package/Application/Components/HeaderRight.tsx +529 -8
  16. package/Application/Components/HeaderTitle.tsx +579 -16
  17. package/Application/Components/NavigationButton.tsx +11 -18
  18. package/Application/Components/SearchHeader.tsx +18 -38
  19. package/Application/Localize.ts +0 -7
  20. package/Application/ModalScreen.tsx +18 -41
  21. package/Application/Navigation.ts +17 -15
  22. package/Application/NavigationContainer.tsx +21 -23
  23. package/Application/Navigator.ts +48 -20
  24. package/Application/ScaleSizeProvider.tsx +6 -13
  25. package/Application/StackScreen.tsx +172 -27
  26. package/Application/TooltipPortal.tsx +5 -12
  27. package/Application/WidgetContainer.tsx +7 -20
  28. package/Application/device.ts +52 -0
  29. package/Application/index.ts +1 -23
  30. package/Application/types.ts +242 -17
  31. package/Application/utils.tsx +493 -0
  32. package/Badge/Badge.tsx +0 -5
  33. package/Badge/BadgeDot.tsx +0 -1
  34. package/Badge/BadgeDotAnimation.tsx +7 -15
  35. package/Badge/BadgeRibbon.tsx +39 -47
  36. package/Badge/Shape.tsx +0 -2
  37. package/Badge/styles.ts +0 -2
  38. package/Badge/types.ts +2 -2
  39. package/Button/index.tsx +152 -21
  40. package/Button/styles.ts +1 -1
  41. package/CheckBox/index.tsx +6 -5
  42. package/Consts/theme.ts +10 -10
  43. package/Context/index.ts +1 -5
  44. package/Divider/DashDivider.tsx +11 -11
  45. package/Divider/index.tsx +7 -21
  46. package/FoundationList/index.tsx +0 -4
  47. package/Icon/index.tsx +6 -6
  48. package/Icon/types.ts +1 -1
  49. package/IconButton/index.tsx +12 -4
  50. package/Image/index.tsx +7 -9
  51. package/Input/Input.tsx +12 -10
  52. package/Input/InputDropDown.tsx +13 -10
  53. package/Input/InputMoney.tsx +152 -45
  54. package/Input/InputOTP.tsx +34 -36
  55. package/Input/InputPhoneNumber.tsx +5 -8
  56. package/Input/InputSearch.tsx +111 -19
  57. package/Input/InputTextArea.tsx +5 -5
  58. package/Input/SystemTextInput.tsx +2 -7
  59. package/Input/TextTyping.tsx +0 -4
  60. package/Input/common.tsx +17 -31
  61. package/Input/index.tsx +21 -24
  62. package/Input/styles.ts +5 -25
  63. package/Input/utils.ts +12 -14
  64. package/Layout/Card.tsx +4 -7
  65. package/Layout/FloatingButton.tsx +21 -26
  66. package/Layout/Item.tsx +2 -6
  67. package/Layout/ItemList.tsx +7 -9
  68. package/Layout/ItemSectionList.tsx +1 -2
  69. package/Layout/ReservedRegions.tsx +17 -34
  70. package/Layout/Screen.tsx +696 -122
  71. package/Layout/Section.tsx +7 -9
  72. package/Layout/TrackingScope.tsx +0 -1
  73. package/Layout/index.ts +4 -10
  74. package/Layout/styles.ts +0 -2
  75. package/Layout/types.ts +4 -2
  76. package/Layout/utils.ts +181 -40
  77. package/Loader/DotLoader.tsx +3 -11
  78. package/Loader/Loader.tsx +0 -4
  79. package/Loader/ProgressBar.tsx +6 -3
  80. package/Loader/Spinner.tsx +3 -11
  81. package/Loader/styles.ts +0 -4
  82. package/Loader/utils.ts +7 -11
  83. package/Pagination/Dot.tsx +0 -4
  84. package/Pagination/PaginationDot.tsx +0 -1
  85. package/Pagination/PaginationNumber.tsx +3 -5
  86. package/Pagination/PaginationScroll.tsx +0 -5
  87. package/Pagination/PaginationWhiteDot.tsx +0 -1
  88. package/Pagination/index.tsx +0 -4
  89. package/Pagination/types.ts +2 -2
  90. package/Popup/PopupNotify.tsx +102 -94
  91. package/Popup/PopupPromotion.tsx +11 -9
  92. package/Popup/types.ts +4 -11
  93. package/Popup/utils.ts +18 -50
  94. package/Radio/index.tsx +10 -6
  95. package/Radio/styles.ts +0 -6
  96. package/Skeleton/index.tsx +9 -9
  97. package/Skeleton/styles.ts +0 -1
  98. package/Switch/index.tsx +0 -1
  99. package/Tag/index.tsx +4 -8
  100. package/Tag/types.ts +3 -3
  101. package/Text/index.tsx +5 -25
  102. package/Text/styles.ts +1 -1
  103. package/Text/types.ts +6 -1
  104. package/Text/utils.ts +4 -20
  105. package/Title/index.tsx +40 -42
  106. package/Title/styles.ts +0 -6
  107. package/ViewBoundary/index.tsx +2 -4
  108. package/index.ts +6 -0
  109. package/package.json +1 -2
  110. package/Application/BottomSheet.hooks.ts +0 -195
  111. package/Application/BottomSheet.parts.tsx +0 -157
  112. package/Application/BottomSheet.styles.ts +0 -43
  113. package/Application/BottomTab/ActiveIndicator.tsx +0 -91
  114. package/Application/BottomTab/BottomTabBar.styles.ts +0 -65
  115. package/Application/BottomTab/BottomTabInset.tsx +0 -18
  116. package/Application/BottomTab/CurvedContainer.tsx +0 -155
  117. package/Application/BottomTab/DuoRailTabBar.tsx +0 -223
  118. package/Application/BottomTab/DuoTabBar.styles.ts +0 -81
  119. package/Application/BottomTab/TabScreen.tsx +0 -160
  120. package/Application/BottomTab/metrics.ts +0 -164
  121. package/Application/BottomTab/tabItems.ts +0 -46
  122. package/Application/BottomTab/usePressLift.ts +0 -32
  123. package/Application/Components/HeaderRight.styles.ts +0 -146
  124. package/Application/Components/HeaderTitle.shared.ts +0 -44
  125. package/Application/Components/HeaderTitle.styles.ts +0 -125
  126. package/Application/Components/HeaderToolkitAction.tsx +0 -180
  127. package/Application/Components/SwipeBackHaptic.tsx +0 -95
  128. package/Application/Components/TitleJourney.tsx +0 -110
  129. package/Application/Components/TitleLocation.tsx +0 -73
  130. package/Application/Components/TitleUser.tsx +0 -304
  131. package/Application/Components/useToolkitActions.tsx +0 -218
  132. package/Application/ModalIconButton.tsx +0 -66
  133. package/Application/StackScreen.tracking.ts +0 -143
  134. package/Application/headerLayout.ts +0 -158
  135. package/Application/hooks.ts +0 -137
  136. package/Application/modalLayout.ts +0 -176
  137. package/Application/navigationOptions.tsx +0 -212
  138. package/Application/types.header.ts +0 -121
  139. package/Application/types.tabs.ts +0 -48
  140. package/Application/types.theme.ts +0 -87
  141. package/Application/utils.ts +0 -107
  142. package/Button/utils.ts +0 -133
  143. package/Input/InputMoneyView.tsx +0 -194
  144. package/Input/SearchTextTyping.tsx +0 -108
  145. package/Input/moneyUtils.ts +0 -23
  146. package/Layout/layoutMetrics.ts +0 -58
  147. package/Layout/layoutTypes.ts +0 -86
  148. package/Layout/screenContent.tsx +0 -92
  149. package/Layout/screenFooter.tsx +0 -63
  150. package/Layout/screenHeader.tsx +0 -321
  151. package/Layout/screenQuickReturn.tsx +0 -64
  152. package/Layout/screenScroll.ts +0 -107
  153. package/Layout/screenTypes.ts +0 -143
@@ -1,212 +0,0 @@
1
- import React from 'react';
2
- import { Platform } from 'react-native';
3
- import {
4
- CardStyleInterpolators,
5
- type StackCardInterpolatedStyle,
6
- type StackCardInterpolationProps,
7
- type StackNavigationOptions,
8
- TransitionPresets,
9
- } from '@react-navigation/stack';
10
- import type { SharedValue } from 'react-native-reanimated';
11
- import { Colors } from '../Consts';
12
- import { HeaderBackground } from './Components/HeaderBackground';
13
- import { HeaderLeft } from './Components/HeaderLeft';
14
- import { HeaderRight } from './Components/HeaderRight';
15
- import { HeaderTitle, TitleCustom } from './Components/HeaderTitle';
16
- import { HeaderBarMetrics, TITLE_CONTAINER_RESET } from './headerLayout';
17
- import type { HeaderTitleProps, NavigationOptions } from './types';
18
-
19
- const CARD_SHADOW_OPACITY = 0.3;
20
- const CARD_OVERLAY_OPACITY = 0.6;
21
-
22
- /**
23
- * iOS slide from right with a card shadow and a pink overlay that fades in
24
- * over the screen underneath.
25
- */
26
- const forStackTransitionWithOverlay = (
27
- props: StackCardInterpolationProps,
28
- ): StackCardInterpolatedStyle => {
29
- const { cardStyle } = CardStyleInterpolators.forHorizontalIOS(props);
30
- return {
31
- cardStyle,
32
- shadowStyle: {
33
- shadowOpacity: props.current.progress.interpolate({
34
- inputRange: [0, 1],
35
- outputRange: [0, CARD_SHADOW_OPACITY],
36
- extrapolate: 'clamp',
37
- }),
38
- },
39
- overlayStyle: {
40
- backgroundColor: Colors.pink_09,
41
- opacity: props.current.progress.interpolate({
42
- inputRange: [0, 1],
43
- outputRange: [0, CARD_OVERLAY_OPACITY],
44
- extrapolate: 'clamp',
45
- }),
46
- },
47
- };
48
- };
49
-
50
- /**
51
- * Default options for stack screens: design system header parts, swipe back
52
- * on iOS and the overlay slide transition.
53
- */
54
- const getStackOptions = (): StackNavigationOptions => {
55
- return {
56
- headerTitleAlign: 'left',
57
- headerTitle: props => <HeaderTitle {...props} />,
58
- headerTitleContainerStyle: {
59
- ...TITLE_CONTAINER_RESET,
60
- left: HeaderBarMetrics.titleGap,
61
- },
62
- headerBackground: (props: any) => <HeaderBackground {...props} />,
63
- headerLeft: (props: any) => <HeaderLeft {...props} floating />,
64
- headerRight: (props: any) => <HeaderRight {...props} floating />,
65
- headerTintColor: Colors.black_17,
66
- gestureEnabled: Platform.OS === 'ios',
67
- ...TransitionPresets.SlideFromRightIOS,
68
- cardStyleInterpolator: forStackTransitionWithOverlay,
69
- cardOverlayEnabled: true,
70
- };
71
- };
72
-
73
- /**
74
- * Default options for modal screens: transparent card, no header, no
75
- * animation and no swipe gesture.
76
- */
77
- const getModalOptions = (): StackNavigationOptions => {
78
- return {
79
- headerShown: false,
80
- headerBackground: undefined,
81
- cardStyle: { backgroundColor: 'transparent' },
82
- cardOverlayEnabled: true,
83
- animation: 'none',
84
- presentation: 'transparentModal',
85
- gestureEnabled: false,
86
- };
87
- };
88
-
89
- /**
90
- * True when params need the design system back button wired to a custom
91
- * handler, a prevent back guard or a hidden back flag.
92
- */
93
- const hasCustomHeaderLeft = (params: NavigationOptions) => {
94
- const hasLeftHandler = typeof params.onPressLeftHeader === 'function';
95
- const hasBackHandler = typeof params.onBackHandler === 'function';
96
- const hasPreventBack = params.preventBack !== undefined;
97
- const hasHiddenBack = typeof params.hiddenBack === 'boolean';
98
- return hasLeftHandler || hasBackHandler || hasPreventBack || hasHiddenBack;
99
- };
100
-
101
- /**
102
- * True when the screen owns its back flow (guard popup or no back button), so
103
- * swipe back must not bypass it.
104
- */
105
- const hasCustomBackHandling = (params: NavigationOptions) => {
106
- return params.preventBack !== undefined || params.hiddenBack === true;
107
- };
108
-
109
- /**
110
- * Header title options from `params.headerTitle`: a string renders
111
- * `HeaderTitle`, an object renders `TitleCustom`, anything else adds nothing.
112
- */
113
- const exportHeaderTitle = (
114
- params: NavigationOptions,
115
- animatedValue?: SharedValue<number>,
116
- ): StackNavigationOptions => {
117
- if (typeof params.headerTitle === 'object') {
118
- return {
119
- headerTitleAlign: 'left',
120
- headerTitle: (props: any) => {
121
- return (
122
- <TitleCustom
123
- {...props}
124
- {...(params.headerTitle as HeaderTitleProps)}
125
- animatedValue={animatedValue}
126
- />
127
- );
128
- },
129
- };
130
- } else if (typeof params.headerTitle === 'string') {
131
- return {
132
- headerTitle: (props: any) => {
133
- return (
134
- <HeaderTitle
135
- {...props}
136
- children={params.headerTitle}
137
- animatedValue={animatedValue}
138
- />
139
- );
140
- },
141
- };
142
- }
143
- return {};
144
- };
145
-
146
- /**
147
- * React Navigation options from screen params: design system header left,
148
- * title and right, and swipe back off for screens that own their back flow.
149
- */
150
- const getOptions = (
151
- params: NavigationOptions,
152
- animatedValue?: SharedValue<number>,
153
- ) => {
154
- let options: StackNavigationOptions = {};
155
-
156
- if (hasCustomHeaderLeft(params)) {
157
- let headerLeft: any = (props: any) => {
158
- return (
159
- <HeaderLeft
160
- {...props}
161
- preventBack={params.preventBack}
162
- onPressLeftHeader={params.onPressLeftHeader}
163
- onBackHandler={params.onBackHandler}
164
- floating
165
- />
166
- );
167
- };
168
- if (params.hiddenBack) {
169
- headerLeft = null;
170
- options.headerTitleContainerStyle = {
171
- ...TITLE_CONTAINER_RESET,
172
- left: HeaderBarMetrics.sidePadding,
173
- };
174
- }
175
- options = {
176
- ...options,
177
- headerLeft,
178
- };
179
- }
180
-
181
- if (params.headerTitle) {
182
- options = {
183
- ...options,
184
- ...exportHeaderTitle(params, animatedValue),
185
- };
186
- }
187
-
188
- if (params.headerRight) {
189
- options = {
190
- ...options,
191
- ...{
192
- headerRight: (props: any) => {
193
- return (
194
- <HeaderRight {...props} headerRight={params.headerRight} floating />
195
- );
196
- },
197
- },
198
- };
199
- }
200
-
201
- // Only ever turns swipe back off; screens opt in via gestureEnabled.
202
- if (params.gestureEnabled === undefined && hasCustomBackHandling(params)) {
203
- options.gestureEnabled = false;
204
- }
205
-
206
- return {
207
- ...params,
208
- ...options,
209
- };
210
- };
211
-
212
- export { getStackOptions, getModalOptions, getOptions, exportHeaderTitle };
@@ -1,121 +0,0 @@
1
- import { Animated, TouchableOpacityProps, ViewProps } from 'react-native';
2
- import type { SharedValue } from 'react-native-reanimated';
3
- import { PopupNotifyProps } from '../Popup/types';
4
- import { InputRef, InputSearchProps } from '../Input';
5
- import React, { type ReactNode } from 'react';
6
-
7
- export type ToolGroup = {
8
- title: { vi: string; en: string };
9
- items: Tool[];
10
- };
11
-
12
- export type Tool = {
13
- icon: string;
14
- name: { vi: string; en: string };
15
- key: string;
16
- showBadge?: boolean;
17
- showRightIcon?: boolean;
18
- onPress: () => void;
19
- };
20
-
21
- export interface NavigationButtonProps extends TouchableOpacityProps {
22
- icon: string;
23
- tintColor?: string;
24
- showBadge?: boolean;
25
- }
26
-
27
- export type HeaderTitleProps = {
28
- type: 'default' | 'user' | 'location' | 'journey';
29
- data: TitleUserProps | TitleLocationProps | TitleJourneyProps;
30
- };
31
-
32
- export type OnBoarding = {
33
- useOnBoarding?: boolean;
34
- onPress?: () => void;
35
- };
36
-
37
- export type HeaderRightToolkit = {
38
- useShortcut?: boolean;
39
- tools?: ToolGroup[];
40
- preventClose?: PopupNotifyProps;
41
- useMore?: boolean;
42
- useCloseIcon?: boolean;
43
- };
44
-
45
- export interface HeaderBackProps extends NavigationButtonProps {
46
- preventBack?: PopupNotifyProps;
47
- onPressLeftHeader?: () => void;
48
- onBackHandler?: (goBack: () => void) => void;
49
- /**
50
- * Optional. If `true`, the button floats into the iPhone Duo side bar while the
51
- * device shows one. Set when the button is rendered by the navigation header.
52
- */
53
- floating?: boolean;
54
- }
55
-
56
- export type HeaderBackgroundProps = {
57
- animatedValue?: Animated.Value | SharedValue<number>;
58
- useGradient?: boolean;
59
- useShadowHeader?: boolean;
60
- backgroundColor?: string;
61
- gradientColor?: string;
62
- headerBackground?: string;
63
- };
64
-
65
- export type TitleUserProps = {
66
- title: string;
67
- subTitle?: string;
68
- image?: string[] | string;
69
- dotColor?: string;
70
- verify?: boolean;
71
- tintColor?: string;
72
- onPress?: () => void;
73
- icons?: string[];
74
- isLoading?: boolean;
75
- };
76
-
77
- export type TitleLocationProps = {
78
- description?: string;
79
- location: string;
80
- tintColor?: string;
81
- onPress?: () => void;
82
- isLoading?: boolean;
83
- };
84
-
85
- export type TitleJourneyProps = {
86
- start: string;
87
- end?: string;
88
- description?: string;
89
- icon: string;
90
- iconColor?: string;
91
- tintColor?: string;
92
- onPress?: () => void;
93
- isLoading?: boolean;
94
- };
95
-
96
- export interface HeaderAnimatedProps extends ViewProps {
97
- animatedValue: Animated.Value | SharedValue<number>;
98
- image: string;
99
- useScale?: boolean;
100
- aspectRatio?: '16/9' | '3/2' | '1/1';
101
- /**
102
- * Optional. On wide windows the image keeps its phone width, centered; this
103
- * color fills the sides and fades to transparent downward. No fill when unset.
104
- */
105
- bannerBackgroundColor?: string;
106
- }
107
-
108
- export type AnimatedHeader = {
109
- headerTintColor?: string;
110
- component?: (props?: any) => React.ReactElement;
111
- headerTitle?: HeaderTitleProps | string;
112
- };
113
-
114
- export interface SearchHeaderProps extends InputSearchProps {
115
- ref?: React.RefObject<InputRef>;
116
- animatedValue?: Animated.Value | SharedValue<number>;
117
- headerRightWidth?: 0 | 84 | 124 | number;
118
- leftPosition?: 12 | 52 | number;
119
- renderButtons?: () => ReactNode;
120
- hiddenBack?: boolean;
121
- }
@@ -1,48 +0,0 @@
1
- import { EventArg } from '@react-navigation/core';
2
- import React from 'react';
3
- import type {
4
- NavigationOptions,
5
- NavigationProps,
6
- NavigationScreenProps,
7
- } from './types';
8
-
9
- export type BottomTabItemProps = {
10
- name: string;
11
- label: string;
12
- icon: string;
13
- showDot?: boolean;
14
- badgeLabel?: string | number;
15
- screen: React.ComponentType<NavigationScreenProps>;
16
- options: NavigationOptions;
17
- initialParams?: any;
18
- };
19
-
20
- export type BottomTabProps = {
21
- nested?: boolean;
22
- tabs: BottomTabItemProps[];
23
- initialRouteName?: string;
24
- navigation: NavigationProps;
25
- listeners?: {
26
- tabPress?: (e: EventArg<'tabPress', true, undefined>) => void;
27
- focus?: (e: EventArg<'focus', false, unknown>) => void;
28
- blur?: (e: EventArg<'blur', false, unknown>) => void;
29
- };
30
- floatingButton?: FloatingButtonProps;
31
- /**
32
- * iPhone Duo: when the side bar can't hold both bars, which one starts compressed;
33
- * tapping the compressed one swaps them. Defaults to 'toolbar'
34
- */
35
- compressionBehavior?: 'toolbar' | 'tabBar';
36
- };
37
-
38
- export type FloatingButtonProps = {
39
- container?: React.ReactNode;
40
- icon: string | React.ReactNode;
41
- label: string;
42
- onPress: () => void;
43
- /**
44
- * Drawn over the label text, which stays, e.g. a Lottie of the label; centered on the
45
- * label and unclipped. `icon` takes the button part (inside the 48 button)
46
- */
47
- labelContent?: React.ReactNode;
48
- };
@@ -1,87 +0,0 @@
1
- import { ViewProps } from 'react-native';
2
- import type { NavigatorProps } from './types';
3
-
4
- export type LocalizeProps = {
5
- getCurrentLanguage: 'en' | 'vi';
6
- getAssets: LocalizationObject;
7
- translate: (key: string) => string;
8
- translateData: (data: { vi: string; en: string }) => string;
9
- addTranslations: (translations: LocalizationObject) => void;
10
- };
11
-
12
- export type Theme = {
13
- dark: boolean;
14
- colors: {
15
- primary: string;
16
- secondary: string;
17
- gradient: string;
18
- background: {
19
- default: string;
20
- surface: string;
21
- tonal: string;
22
- pressed: string;
23
- selected: string;
24
- disable: string;
25
- };
26
- text: {
27
- default: string;
28
- secondary: string;
29
- hint: string;
30
- disable: string;
31
- };
32
- border: {
33
- default: string;
34
- disable: string;
35
- };
36
- success: {
37
- primary: string;
38
- secondary: string;
39
- container: string;
40
- };
41
- warning: {
42
- primary: string;
43
- secondary: string;
44
- container: string;
45
- };
46
- error: {
47
- primary: string;
48
- secondary: string;
49
- container: string;
50
- };
51
- highlight: {
52
- primary: string;
53
- secondary: string;
54
- container: string;
55
- };
56
- interactive: {
57
- primary: string;
58
- secondary: string;
59
- container: string;
60
- };
61
- };
62
- font: string;
63
- assets?: {
64
- headerBackground?: string;
65
- };
66
- };
67
-
68
- export type ScaleSizeProviderProps = {
69
- scaleSizeMaxRate?: number;
70
- children: ViewProps['children'];
71
- };
72
-
73
- export type Context = {
74
- [key: string]: any;
75
- theme: Theme;
76
- navigator?: NavigatorProps;
77
- translate?: (data: string | { vi: string; en: string }) => string;
78
- };
79
-
80
- export type LocalizationObject = {
81
- vi: {
82
- [key: string]: string;
83
- };
84
- en: {
85
- [key: string]: string;
86
- };
87
- };
@@ -1,107 +0,0 @@
1
- import { Animated, Dimensions, Platform, ScaledSize } from 'react-native';
2
- import type { NavigationState, PartialState } from '@react-navigation/native';
3
- import type { SharedValue } from 'react-native-reanimated';
4
-
5
- const IPHONE_MAX_SHORT_SIDE = 440;
6
-
7
- /**
8
- * Animation runtimes an internal header component may receive. Public Screen
9
- * props still accept RN Animated.Value only.
10
- */
11
- type AnimatedCompatValue = Animated.Value | SharedValue<number>;
12
-
13
- type NavigationTreeState = NavigationState | PartialState<NavigationState>;
14
-
15
- /**
16
- * True when `value` has a callable property `name`. Safe on null and primitives.
17
- */
18
- const hasMethod = (value: unknown, name: string) => {
19
- return typeof (value as Record<string, unknown>)?.[name] === 'function';
20
- };
21
-
22
- /**
23
- * True for a React Native `Animated.Value`.
24
- */
25
- const isRNAnimatedValue = (value: unknown): value is Animated.Value => {
26
- return hasMethod(value, 'setValue') && hasMethod(value, 'interpolate');
27
- };
28
-
29
- /**
30
- * True for a reanimated shared value: has `.value`, not an `Animated.Value`.
31
- */
32
- const isSharedValue = (value: unknown): value is SharedValue<number> => {
33
- if (!value || isRNAnimatedValue(value)) {
34
- return false;
35
- }
36
- return 'value' in (value as object);
37
- };
38
-
39
- /**
40
- * Props carrying the QA automation id: `testID` on iOS (label cleared so it
41
- * doesn't override it), `accessibilityLabel` on Android.
42
- */
43
- const setAutomationID = (accessibilityLabel = '') => {
44
- if (Platform.OS === 'ios') {
45
- return {
46
- accessible: true,
47
- testID: accessibilityLabel,
48
- accessibilityLabel: undefined,
49
- };
50
- } else {
51
- return {
52
- accessibilityLabel,
53
- };
54
- }
55
- };
56
-
57
- /**
58
- * Screens the focused navigation branch can still pop. Only stack navigators
59
- * count, switching bottom tab is not a back step.
60
- */
61
- const getStackDepth = (state?: NavigationTreeState): number => {
62
- const routes = state?.routes;
63
- if (!routes?.length) {
64
- return 0;
65
- }
66
-
67
- const index = state?.index ?? routes.length - 1;
68
- const depth = state?.type === 'stack' ? index : 0;
69
-
70
- return depth + getStackDepth(routes[index]?.state);
71
- };
72
-
73
- /**
74
- * True when the mini app context opts into the whitelisted design system.
75
- */
76
- const isWhiteListDesignSystem = (context: any): boolean => {
77
- return context?.designSystemConfig?.isWhiteListDesignSystem === true;
78
- };
79
-
80
- /**
81
- * Shorter edge of a screen or window size.
82
- */
83
- const getShortSide = (size: ScaledSize) => Math.min(size.width, size.height);
84
-
85
- /**
86
- * True on iPhone Duo. Duo reports idiom "phone" and `screen` stays on the
87
- * outer display, so this still matches when Split View narrows the window.
88
- */
89
- const isIPhoneDuo = () => {
90
- if (Platform.OS !== 'ios' || Platform.isPad) {
91
- return false;
92
- }
93
- const screenSide = getShortSide(Dimensions.get('screen'));
94
- const windowSide = getShortSide(Dimensions.get('window'));
95
- return Math.max(screenSide, windowSide) > IPHONE_MAX_SHORT_SIDE;
96
- };
97
-
98
- export type { AnimatedCompatValue, NavigationTreeState };
99
- export {
100
- hasMethod,
101
- isRNAnimatedValue,
102
- isSharedValue,
103
- setAutomationID,
104
- getStackDepth,
105
- isWhiteListDesignSystem,
106
- isIPhoneDuo,
107
- };
package/Button/utils.ts DELETED
@@ -1,133 +0,0 @@
1
- import { Colors } from '../Consts';
2
- import { Theme } from '../Application/types';
3
- import { Typography } from '../Text/types';
4
- import { ButtonProps } from './index';
5
-
6
- /**
7
- * Whether the loading spinner belongs in the `isLeft` icon slot: it takes the
8
- * right slot when there is a right icon, otherwise the left one.
9
- */
10
- export const shouldShowLoading = (
11
- left?: string,
12
- right?: string,
13
- isLeft?: boolean,
14
- ): boolean => {
15
- const hasLeft = !!left;
16
- const hasRight = !!right;
17
-
18
- const loadingOnLeft = (!hasLeft && !hasRight) || (hasLeft && !hasRight);
19
-
20
- return isLeft === loadingOnLeft;
21
- };
22
-
23
- /**
24
- * Background and border of a button `type`; `color` (mini app button color)
25
- * overrides the outline border.
26
- */
27
- export const getTypeStyle = (
28
- type: ButtonProps['type'],
29
- theme: Theme,
30
- color?: string,
31
- ) => {
32
- switch (type) {
33
- case 'disabled':
34
- return {
35
- backgroundColor: theme.colors.background.disable,
36
- };
37
- case 'primary':
38
- return { backgroundColor: theme.colors.primary };
39
- case 'secondary':
40
- return {
41
- backgroundColor: theme.colors.background.surface,
42
- borderWidth: 1,
43
- borderColor: theme.colors.border.default,
44
- };
45
- case 'outline':
46
- return {
47
- backgroundColor: theme.colors.background.surface,
48
- borderWidth: 1,
49
- borderColor: color ?? theme.colors.primary,
50
- };
51
- case 'tonal':
52
- return {
53
- backgroundColor: theme.colors.background.tonal,
54
- };
55
- case 'danger':
56
- return {
57
- backgroundColor: theme.colors.error.primary,
58
- };
59
- case 'text':
60
- return {};
61
- default:
62
- return { backgroundColor: theme.colors.primary };
63
- }
64
- };
65
-
66
- /** Icon size for a button `size`. */
67
- export const getIconSize = (size: ButtonProps['size']) => {
68
- switch (size) {
69
- case 'large':
70
- return 24;
71
- case 'medium':
72
- case 'small':
73
- return 16;
74
- default:
75
- return 24;
76
- }
77
- };
78
-
79
- /** Gap between icon and title for a button `size`. */
80
- export const getIconSpace = (size: ButtonProps['size']) => {
81
- switch (size) {
82
- case 'large':
83
- case 'medium':
84
- return 8;
85
- case 'small':
86
- return 4;
87
- default:
88
- return 8;
89
- }
90
- };
91
-
92
- /** Title typography for a button `size`. */
93
- export const getTypography = (size: ButtonProps['size']): Typography => {
94
- switch (size) {
95
- case 'large':
96
- return 'action_default_bold';
97
- case 'medium':
98
- return 'action_s_bold';
99
- case 'small':
100
- return 'action_xs_bold';
101
- default:
102
- return 'action_default_bold';
103
- }
104
- };
105
-
106
- /**
107
- * Title and icon color of a button `type`; `color` (mini app button color)
108
- * overrides the outline and text types.
109
- */
110
- export const getTextColor = (
111
- type: ButtonProps['type'],
112
- theme: Theme,
113
- color?: string,
114
- ): string => {
115
- switch (type) {
116
- case 'disabled':
117
- return theme.colors.text.disable;
118
- case 'primary':
119
- return Colors.black_01;
120
- case 'secondary':
121
- return theme.colors.text.default;
122
- case 'outline':
123
- return color ?? theme.colors.primary;
124
- case 'tonal':
125
- return theme.colors.primary;
126
- case 'danger':
127
- return Colors.black_01;
128
- case 'text':
129
- return color ?? theme.colors.primary;
130
- default:
131
- return Colors.black_01;
132
- }
133
- };