@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
package/Text/index.tsx CHANGED
@@ -1,10 +1,5 @@
1
1
  import React, { useContext } from 'react';
2
- import {
3
- StyleSheet,
4
- Text as RNText,
5
- TextProps as RNTextProps,
6
- View,
7
- } from 'react-native';
2
+ import { Text as RNText, TextProps as RNTextProps, View } from 'react-native';
8
3
  import styles from './styles';
9
4
  import { Typography, TypographyWeight } from './types';
10
5
  import {
@@ -111,10 +106,6 @@ const deprecatedValues: Typography[] = [
111
106
  'action_s',
112
107
  ];
113
108
 
114
- /**
115
- * Text style of a typography token with sizes scaled by `useScaleSize` and the
116
- * font file name for its weight. Calls hooks, so it only runs during render.
117
- */
118
109
  const TypoStyles = (typo: Typography, newFontFamily?: string) => {
119
110
  const { theme } = useContext(ApplicationContext);
120
111
  const styleSheet: {
@@ -162,20 +153,13 @@ const TypoStyles = (typo: Typography, newFontFamily?: string) => {
162
153
  fontSize: useScaleSize(fontSize),
163
154
  lineHeight: useScaleSize(lineHeight),
164
155
  fontStyle,
165
- // Weight is in fontFamily; fontWeight >= 700 makes Android seek a missing <family>_bold.ttf.
156
+ // fontFamily da mang san weight. Tren Android, ReactFontManager doi
157
+ // `fonts/<family>_bold.ttf` khi fontWeight >= 700; file do khong ton tai nen
158
+ // font se roi ve font he thong. Bo fontWeight de Android dung dung file.
166
159
  fontWeight: undefined,
167
160
  };
168
161
  };
169
162
 
170
- const skeletonStyles = StyleSheet.create({
171
- overlay: { position: 'absolute' },
172
- });
173
-
174
- /**
175
- * Design-system text: renders a `typography` token in the theme font with
176
- * scaled sizes and OS font scaling off. Warns on deprecated tokens and shows a
177
- * skeleton overlay while a SkeletonContext is loading.
178
- */
179
163
  const Text: React.FC<TextProps> = ({
180
164
  typography = 'body_default_regular',
181
165
  color,
@@ -212,7 +196,7 @@ const Text: React.FC<TextProps> = ({
212
196
  >
213
197
  {children ?? ''}
214
198
  </RNText>
215
- <Skeleton style={skeletonStyles.overlay} />
199
+ <Skeleton style={{ position: 'absolute' }} />
216
200
  </View>
217
201
  );
218
202
  }
@@ -235,10 +219,6 @@ const Text: React.FC<TextProps> = ({
235
219
  );
236
220
  };
237
221
 
238
- /**
239
- * Theme font family for a loose weight name ('bold', 'semibold', 'regular').
240
- * The `typography` argument is ignored; it calls hooks, so use it during render.
241
- */
242
222
  const exportFontFamily = (
243
223
  fontWeight: string,
244
224
  typography?: Typography,
package/Text/styles.ts CHANGED
@@ -39,7 +39,7 @@ export default {
39
39
  action_s_bold: { fontSize: 14, lineHeight: 20, fontWeight: '700' },
40
40
  action_xs_bold: { fontSize: 12, lineHeight: 18, fontWeight: '700' },
41
41
  action_xxs_bold: { fontSize: 10, lineHeight: 14, fontWeight: '700' },
42
- // Legacy tokens kept for old callers; not in the current type scale.
42
+ /**non-support**/
43
43
  headline_default: {
44
44
  fontSize: 28,
45
45
  lineHeight: 34,
package/Text/types.ts CHANGED
@@ -14,7 +14,9 @@ export type TypographyWeight = {
14
14
  };
15
15
 
16
16
  export type Typography =
17
- // Deprecated up to 'action_s': Text warns at runtime when one is used.
17
+ /**
18
+ * @deprecated
19
+ **/
18
20
  | 'headline_default'
19
21
  | 'headline_l'
20
22
  | 'headline_xl'
@@ -27,6 +29,9 @@ export type Typography =
27
29
  | 'paragraph_italic'
28
30
  | 'label_xxs'
29
31
  | 'action_s'
32
+ /**
33
+ * end
34
+ **/
30
35
  | 'headline_l_bold'
31
36
  | 'headline_default_bold'
32
37
  | 'header_m_bold'
package/Text/utils.ts CHANGED
@@ -6,28 +6,16 @@ const DEFAULT_SCREEN_SIZE = 375;
6
6
  const MAX_FONT_SCALE = 1.5;
7
7
  const MAX_DEVICE_SCALE = 5;
8
8
 
9
- type MiniAppScale = {
10
- scaleSizeMaxRate?: number;
11
- fontScale?: { useOSScaleRate?: boolean; userScaleRate?: number };
12
- };
13
-
14
- /**
15
- * Scales `size` by screen width (+5 max) and OS font scale (max `scaleRate`,
16
- * else the ScaleSizeProvider rate, else 1.5), taking the larger, or by the mini
17
- * app `fontScale.userScaleRate`; a provider rate caps both at `size × rate`.
18
- */
19
9
  const useScaleSize = (size: number, scaleRate?: number) => {
20
10
  const { width } = useWindowDimensions();
21
- const context = useContext<MiniAppScale | undefined>(MiniAppContext);
22
- const scaleSizeMaxRate = context?.scaleSizeMaxRate;
23
- const maxSize = scaleSizeMaxRate ? size * scaleSizeMaxRate : Infinity;
11
+ const context = useContext<any>(MiniAppContext);
24
12
  if (context?.fontScale?.useOSScaleRate === false) {
25
- return Math.min(size * (context.fontScale.userScaleRate ?? 1), maxSize);
13
+ return size * (context.fontScale.userScaleRate ?? 1);
26
14
  }
27
15
  const fontScale = PixelRatio.getFontScale();
28
16
  const deviceScale = width / DEFAULT_SCREEN_SIZE;
29
17
 
30
- const maxScaleRate = scaleRate ?? scaleSizeMaxRate ?? MAX_FONT_SCALE;
18
+ const maxScaleRate = scaleRate ?? MAX_FONT_SCALE;
31
19
 
32
20
  let fontSizeDeviceScale = size;
33
21
  let fontSizeOSScale = size;
@@ -46,13 +34,9 @@ const useScaleSize = (size: number, scaleRate?: number) => {
46
34
  );
47
35
  }
48
36
 
49
- return Math.min(Math.max(fontSizeDeviceScale, fontSizeOSScale), maxSize);
37
+ return Math.max(fontSizeDeviceScale, fontSizeOSScale);
50
38
  };
51
39
 
52
- /**
53
- * Non-hook `useScaleSize` with the default cap and no mini app rate, for use
54
- * outside render. Reads the window width at call time, so it misses resizes.
55
- */
56
40
  const scaleSize = (size: number) => {
57
41
  const fontScale = PixelRatio.getFontScale();
58
42
  const deviceScale = Dimensions.get('window').width / DEFAULT_SCREEN_SIZE;
package/Title/index.tsx CHANGED
@@ -15,11 +15,6 @@ import styles from './styles';
15
15
  import { TitleProps } from './types';
16
16
  import { Typography } from '../Text/types';
17
17
 
18
- /**
19
- * Section or card heading with optional icon, badge, description, trailing
20
- * chevron and right action (chevron, or a text button when `buttonTitle` is
21
- * set). `textOnly` renders the title text alone.
22
- */
23
18
  const Title: FC<TitleProps> = ({
24
19
  accessibilityLabel,
25
20
  title = 'Title',
@@ -48,6 +43,7 @@ const Title: FC<TitleProps> = ({
48
43
 
49
44
  const size18 = useScaleSize(18);
50
45
  const size22 = useScaleSize(22);
46
+ // Dynamic styles using useScaleSize hook
51
47
  const dynamicStyles = {
52
48
  card_small: {
53
49
  fontSize: useScaleSize(14),
@@ -151,7 +147,9 @@ const Title: FC<TitleProps> = ({
151
147
  setBadgeWidth(e.nativeEvent.layout.width);
152
148
  }
153
149
  }}
154
- style={styles.badgeView}
150
+ style={{
151
+ alignItems: 'center',
152
+ }}
155
153
  >
156
154
  <Badge
157
155
  style={styles.badge}
@@ -208,44 +206,44 @@ const Title: FC<TitleProps> = ({
208
206
 
209
207
  const lineHeight = styleSheet[typography].lineHeight;
210
208
 
211
- let action = (
212
- <TouchableOpacity
213
- onPress={onPressRightAction}
214
- style={[
215
- styles.iconRight,
216
- {
217
- backgroundColor: theme.colors.primary + '0F',
218
- },
219
- ]}
220
- accessibilityLabel={componentId + '|label-right-action-touch'}
209
+ return (
210
+ <View
211
+ style={{
212
+ height: lineHeight,
213
+ justifyContent: 'center',
214
+ }}
221
215
  >
222
- <Icon
223
- source={'arrow_chevron_right_small'}
224
- size={size22}
225
- color={theme.colors.primary}
226
- />
227
- </TouchableOpacity>
228
- );
229
- if (buttonTitle) {
230
- action = (
231
- <TouchableOpacity
232
- onPress={onPressRightAction}
233
- accessibilityLabel={componentId + '|label-right-action-touch'}
234
- >
235
- <Text
236
- color={theme.colors.primary}
237
- typography={buttonTypo}
238
- accessibilityLabel={componentId + '|label-right-action-text'}
216
+ {!buttonTitle ? (
217
+ <TouchableOpacity
218
+ onPress={onPressRightAction}
219
+ style={[
220
+ styles.iconRight,
221
+ {
222
+ backgroundColor: theme.colors.primary + '0F',
223
+ },
224
+ ]}
225
+ accessibilityLabel={componentId + '|label-right-action-touch'}
239
226
  >
240
- {buttonTitle}
241
- </Text>
242
- </TouchableOpacity>
243
- );
244
- }
245
-
246
- return (
247
- <View style={[styles.actionRightView, { height: lineHeight }]}>
248
- {action}
227
+ <Icon
228
+ source={'arrow_chevron_right_small'}
229
+ size={size22}
230
+ color={theme.colors.primary}
231
+ />
232
+ </TouchableOpacity>
233
+ ) : (
234
+ <TouchableOpacity
235
+ onPress={onPressRightAction}
236
+ accessibilityLabel={componentId + '|label-right-action-touch'}
237
+ >
238
+ <Text
239
+ color={theme.colors.primary}
240
+ typography={buttonTypo}
241
+ accessibilityLabel={componentId + '|label-right-action-text'}
242
+ >
243
+ {buttonTitle}
244
+ </Text>
245
+ </TouchableOpacity>
246
+ )}
249
247
  </View>
250
248
  );
251
249
  };
package/Title/styles.ts CHANGED
@@ -47,12 +47,6 @@ export default StyleSheet.create({
47
47
  badge: {
48
48
  marginLeft: Spacing.XS,
49
49
  },
50
- badgeView: {
51
- alignItems: 'center',
52
- },
53
- actionRightView: {
54
- justifyContent: 'center',
55
- },
56
50
  description: {
57
51
  marginTop: Spacing.XS,
58
52
  },
@@ -14,10 +14,6 @@ interface ViewBoundaryState {
14
14
  error: Error | null;
15
15
  }
16
16
 
17
- /**
18
- * Error boundary: renders `fallback` (or nothing) after a render error and
19
- * reports it to native `MiniAppModule.onJSBoundaryCrash` when available.
20
- */
21
17
  class ViewBoundary extends React.Component<
22
18
  ViewBoundaryProps,
23
19
  ViewBoundaryState
@@ -37,6 +33,7 @@ class ViewBoundary extends React.Component<
37
33
  this.props.onError?.(error, errorInfo);
38
34
 
39
35
  const context = (this as any).context ?? {};
36
+ // check exist native module method onJSBoundaryCrash
40
37
  const nativeMethod = NativeModules?.MiniAppModule?.onJSBoundaryCrash;
41
38
  if (typeof nativeMethod === 'function') {
42
39
  try {
@@ -52,6 +49,7 @@ class ViewBoundary extends React.Component<
52
49
  componentStack: errorInfo?.componentStack?.substring(0, 500) ?? '',
53
50
  },
54
51
  });
52
+ console.info('[ViewBoundary] onJSBoundaryCrash success!');
55
53
  } catch (_e) {
56
54
  console.warn('[ViewBoundary] onJSBoundaryCrash failed:', _e);
57
55
  }
package/index.ts CHANGED
@@ -1,8 +1,14 @@
1
+ /**
2
+ * native export
3
+ */
1
4
  import { TouchableOpacity } from 'react-native';
2
5
 
3
6
  export * from 'react-native-linear-gradient';
4
7
  export * from 'react-native-safe-area-context';
5
8
 
9
+ /**
10
+ * foundation component
11
+ */
6
12
  export * from './Consts';
7
13
  export * from './Context';
8
14
  export * from './Layout';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.168.1-beta.39",
3
+ "version": "0.168.1-beta.40",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -26,7 +26,6 @@
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react-native": "*",
29
- "react-native-svg": "*",
30
29
  "react-native-worklets": "0.6.1"
31
30
  },
32
31
  "devDependencies": {
@@ -1,195 +0,0 @@
1
- import { MutableRefObject, useCallback, useEffect, useState } from 'react';
2
- import {
3
- Extrapolation,
4
- interpolate,
5
- SharedValue,
6
- useAnimatedStyle,
7
- } from 'react-native-reanimated';
8
- import {
9
- BackHandler,
10
- Dimensions,
11
- Keyboard,
12
- KeyboardEvent,
13
- LayoutAnimation,
14
- Platform,
15
- useWindowDimensions,
16
- } from 'react-native';
17
- import { useSafeAreaInsets } from 'react-native-safe-area-context';
18
- import { useHeaderHeight } from '@react-navigation/elements';
19
- import { scheduleOnRN } from 'react-native-worklets';
20
- import { BottomSheetParams, NavigatorProps } from './types';
21
- import { isIPhoneDuo } from './utils';
22
- import { useModalLayout } from './modalLayout';
23
-
24
- /**
25
- * Sheet geometry for the current window: foldable placement and size from
26
- * `useModalLayout`, plus the insets and offsets the keyboard handling needs.
27
- */
28
- export const useBottomSheetLayout = () => {
29
- const windowSize = useWindowDimensions();
30
- const isDuo = isIPhoneDuo();
31
- const { isFoldable, placement, sheet, scrimOpacity } = useModalLayout();
32
- // 'screen' is the outer display on iPhone Duo, even when unfolded
33
- const screenHeight = Dimensions.get('screen').height;
34
- const heightDevice = isDuo ? windowSize.height : screenHeight;
35
- const insets = useSafeAreaInsets();
36
- const heightHeader = useHeaderHeight();
37
- const isIOS = Platform.OS === 'ios';
38
- const bottomInset = isIOS ? Math.min(insets.bottom, 21) : insets.bottom;
39
- const keyboardOffset = heightHeader - bottomInset;
40
-
41
- return {
42
- windowSize,
43
- isDuo,
44
- isFoldable,
45
- placement,
46
- sheet,
47
- scrimOpacity,
48
- heightDevice,
49
- bottomInset,
50
- keyboardOffset,
51
- };
52
- };
53
-
54
- /**
55
- * Keyboard lift of the sheet on iPhone Duo, where KeyboardAvoidingView pushes
56
- * the whole sheet past the top; the sheet lifts by it and shrinks its maxHeight.
57
- */
58
- export const useDuoKeyboardLift = (
59
- isDuo: boolean,
60
- useKeyboardAvoidingView: boolean,
61
- windowHeight: number,
62
- bottomInset: number,
63
- keyboardVerticalOffset?: number,
64
- ) => {
65
- const [keyboardLift, setKeyboardLift] = useState(0);
66
-
67
- useEffect(() => {
68
- if (!isDuo || !useKeyboardAvoidingView) {
69
- return;
70
- }
71
- const onKeyboardChange = (e: KeyboardEvent) => {
72
- const overlap = windowHeight - e.endCoordinates.screenY;
73
- const lift = Math.max(
74
- overlap - bottomInset - (keyboardVerticalOffset ?? 0),
75
- 0,
76
- );
77
- if (e.duration) {
78
- LayoutAnimation.configureNext({
79
- duration: e.duration,
80
- update: {
81
- duration: e.duration,
82
- type: LayoutAnimation.Types[e.easing] || 'keyboard',
83
- },
84
- });
85
- }
86
- setKeyboardLift(lift);
87
- };
88
- const subscriptions = [
89
- Keyboard.addListener('keyboardWillChangeFrame', onKeyboardChange),
90
- Keyboard.addListener('keyboardWillHide', onKeyboardChange),
91
- ];
92
- return () => subscriptions.forEach(sub => sub.remove());
93
- }, [
94
- bottomInset,
95
- isDuo,
96
- keyboardVerticalOffset,
97
- useKeyboardAvoidingView,
98
- windowHeight,
99
- ]);
100
-
101
- return keyboardLift;
102
- };
103
-
104
- /**
105
- * Slide of the sheet and fade of the scrim behind it, up to the
106
- * `scrimOpacity` of the modal spec (lighter on foldables).
107
- */
108
- export const useSheetAnimatedStyles = (
109
- translateY: SharedValue<number>,
110
- heightDevice: number,
111
- scrimOpacity: number,
112
- ) => {
113
- const animatedStyle = useAnimatedStyle(() => {
114
- return {
115
- transform: [{ translateY: translateY.value }],
116
- };
117
- });
118
-
119
- const animatedOverlayStyle = useAnimatedStyle(() => {
120
- return {
121
- opacity: interpolate(
122
- translateY.value,
123
- [0, heightDevice],
124
- [scrimOpacity, 0],
125
- Extrapolation.CLAMP,
126
- ),
127
- };
128
- });
129
-
130
- return { animatedStyle, animatedOverlayStyle };
131
- };
132
-
133
- type SheetDismissParams = {
134
- barrierDismissible: boolean;
135
- closeAnimation: (callback?: () => void) => void;
136
- navigator?: NavigatorProps;
137
- leftOptions: BottomSheetParams['leftOptions'];
138
- action: MutableRefObject<undefined | string>;
139
- };
140
-
141
- /**
142
- * Close handlers of a bottom sheet. A non-forced dismiss (scrim tap, hardware
143
- * back) is ignored while `barrierDismissible` is set.
144
- */
145
- export const useSheetDismiss = ({
146
- barrierDismissible,
147
- closeAnimation,
148
- navigator,
149
- leftOptions,
150
- action,
151
- }: SheetDismissParams) => {
152
- const onDismiss = useCallback(
153
- (force = false, callback?: () => void) => {
154
- if (barrierDismissible && !force) {
155
- return;
156
- }
157
- closeAnimation(() => {
158
- navigator?.pop();
159
- scheduleOnRN(() => {
160
- callback?.();
161
- });
162
- });
163
- },
164
- [barrierDismissible, closeAnimation, navigator],
165
- );
166
-
167
- const onRequestClose = useCallback(
168
- (callback?: () => void) => {
169
- onDismiss(true, callback);
170
- },
171
- [onDismiss],
172
- );
173
-
174
- useEffect(() => {
175
- const backHandler = BackHandler.addEventListener(
176
- 'hardwareBackPress',
177
- () => {
178
- onDismiss();
179
- return true;
180
- },
181
- );
182
- return () => backHandler.remove();
183
- }, [barrierDismissible, onDismiss]);
184
-
185
- const onPressBack = useCallback(() => {
186
- onDismiss(true, leftOptions?.onPressIconLeft);
187
- }, [leftOptions, onDismiss]);
188
-
189
- const onPressClose = useCallback(() => {
190
- action.current = 'icon_close';
191
- onDismiss(true);
192
- }, [action, onDismiss]);
193
-
194
- return { onDismiss, onRequestClose, onPressBack, onPressClose };
195
- };
@@ -1,157 +0,0 @@
1
- import React from 'react';
2
- import { PanResponderInstance, View, ViewStyle } from 'react-native';
3
- import { Spacing, Styles } from '../Consts';
4
- import layoutStyles from '../Layout/styles';
5
- import { Text } from '../Text';
6
- import { INDICATOR_HEIGHT, styles } from './BottomSheet.styles';
7
- import { ModalIconButton } from './ModalIconButton';
8
- import { type ModalLayout } from './modalLayout';
9
- import { BottomSheetParams, Theme } from './types';
10
-
11
- type SheetHeaderParams = {
12
- panHandlers: PanResponderInstance['panHandlers'];
13
- useDivider: boolean;
14
- theme: Theme;
15
- showBack: boolean;
16
- onPressBack: () => void;
17
- onPressClose: () => void;
18
- iconBack: string;
19
- options: BottomSheetParams['options'];
20
- leftOptions: BottomSheetParams['leftOptions'];
21
- };
22
-
23
- /**
24
- * Drag handle and header row: back, title (or a custom header) and close, with
25
- * the 32 modal icon buttons on every device.
26
- */
27
- export const renderSheetHeader = ({
28
- panHandlers,
29
- useDivider,
30
- theme,
31
- showBack,
32
- onPressBack,
33
- onPressClose,
34
- iconBack,
35
- options,
36
- leftOptions,
37
- }: SheetHeaderParams) => {
38
- let backButton: React.ReactNode = null;
39
- if (showBack) {
40
- backButton = <ModalIconButton icon={iconBack} onPress={onPressBack} />;
41
- }
42
-
43
- let headerContent: React.ReactNode;
44
- if (options.header) {
45
- headerContent = <View style={Styles.flex}>{options.header}</View>;
46
- } else {
47
- headerContent = (
48
- <>
49
- {!leftOptions ? <View style={styles.iconButtonSpace} /> : null}
50
- <Text
51
- style={[Styles.flex, styles.title]}
52
- numberOfLines={1}
53
- typography="header_default_bold"
54
- >
55
- {options.title ?? ''}
56
- </Text>
57
- </>
58
- );
59
- }
60
-
61
- return (
62
- <View {...panHandlers}>
63
- <View style={{ height: INDICATOR_HEIGHT }}>
64
- <View style={styles.indicator} />
65
- </View>
66
- <View
67
- style={[
68
- styles.header,
69
- useDivider && styles.headerDivider,
70
- useDivider && {
71
- borderBottomColor: theme.colors.border.default,
72
- },
73
- ]}
74
- >
75
- {backButton}
76
-
77
- {headerContent}
78
- <ModalIconButton icon="navigation_close" onPress={onPressClose} />
79
- </View>
80
- </View>
81
- );
82
- };
83
-
84
- /**
85
- * Footer pinned under the sheet content, `null` when the sheet has none.
86
- */
87
- export const renderSheetFooter = ({
88
- footerComponent,
89
- theme,
90
- }: {
91
- footerComponent: BottomSheetParams['footerComponent'];
92
- theme: Theme;
93
- }) => {
94
- if (!footerComponent) {
95
- return null;
96
- }
97
- return (
98
- <View
99
- style={[
100
- layoutStyles.shadow,
101
- {
102
- paddingBottom: Spacing.S,
103
- backgroundColor: theme.colors.background.surface,
104
- },
105
- ]}
106
- >
107
- {footerComponent}
108
- </View>
109
- );
110
- };
111
-
112
- type SheetStyleParams = {
113
- backgroundColor: string;
114
- isDuo: boolean;
115
- isFoldable: boolean;
116
- placement: ModalLayout['placement'];
117
- sheet: ModalLayout['sheet'];
118
- keyboardLift: number;
119
- showBaseLineDebug: boolean;
120
- };
121
-
122
- /**
123
- * Sheet container style. On foldables the sheet is centered in the placement
124
- * area, clear of the iPhone Duo control column and on the right half when half
125
- * folded; the keyboard lift comes off its max height.
126
- */
127
- export const getSheetStyle = ({
128
- backgroundColor,
129
- isDuo,
130
- isFoldable,
131
- placement,
132
- sheet,
133
- keyboardLift,
134
- showBaseLineDebug,
135
- }: SheetStyleParams) => {
136
- const { width, maxHeight } = sheet;
137
- let foldableStyle: ViewStyle | undefined;
138
- if (isFoldable && width !== undefined && maxHeight !== undefined) {
139
- foldableStyle = {
140
- width,
141
- marginLeft: placement.x + (placement.width - width) / 2,
142
- maxHeight: maxHeight - keyboardLift,
143
- minHeight: sheet.minHeight,
144
- };
145
- }
146
- return [
147
- styles.sheetContainer,
148
- {
149
- backgroundColor,
150
- borderTopLeftRadius: sheet.radius,
151
- borderTopRightRadius: sheet.radius,
152
- },
153
- isDuo && { marginBottom: keyboardLift },
154
- foldableStyle,
155
- showBaseLineDebug && styles.debugBaseLine,
156
- ];
157
- };