@momo-kits/foundation 0.169.18-beta.3 → 0.169.19-beta.1

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 (51) hide show
  1. package/Application/BottomSheet.parts.tsx +4 -4
  2. package/Application/BottomSheet.tsx +8 -18
  3. package/Application/BottomTab/BottomTabBar.styles.ts +1 -1
  4. package/Application/BottomTab/DuoTabBar.styles.ts +1 -1
  5. package/Application/BottomTab/TabBarIcon.tsx +1 -1
  6. package/Application/Components/HeaderAnimated.tsx +33 -9
  7. package/Application/Components/HeaderExtendHeader.tsx +28 -18
  8. package/Application/Components/SearchHeader.tsx +7 -5
  9. package/Application/ModalIconButton.tsx +13 -15
  10. package/Application/ModalScreen.tsx +15 -6
  11. package/Application/StackScreen.tsx +6 -2
  12. package/Application/TooltipPortal.tsx +3 -3
  13. package/Application/__tests__/headerLayout.test.ts +113 -0
  14. package/Application/headerLayout.ts +114 -30
  15. package/Application/hooks.ts +1 -1
  16. package/Application/modalLayout.ts +43 -11
  17. package/Application/types.header.ts +7 -1
  18. package/Button/index.tsx +2 -2
  19. package/Divider/DashDivider.tsx +2 -2
  20. package/Divider/index.tsx +3 -3
  21. package/FoundationList/index.tsx +1 -1
  22. package/Icon/types.ts +1 -2
  23. package/Image/index.tsx +62 -7
  24. package/Image/styles.ts +2 -0
  25. package/Image/types.ts +9 -1
  26. package/Input/CountryCodeView.tsx +18 -2
  27. package/Input/ErrorView.tsx +1 -1
  28. package/Input/Input.tsx +2 -2
  29. package/Input/InputMoney.tsx +7 -2
  30. package/Input/InputMoneyView.tsx +8 -16
  31. package/Input/InputOTP.tsx +2 -2
  32. package/Input/InputPhoneNumber.tsx +2 -2
  33. package/Input/InputSearch.tsx +2 -2
  34. package/Input/InputTextArea.tsx +2 -2
  35. package/Input/SearchTextTyping.tsx +2 -2
  36. package/Input/SystemTextInput.tsx +2 -1
  37. package/Input/TextTyping.tsx +7 -2
  38. package/Input/index.tsx +2 -1
  39. package/Layout/Screen.tsx +13 -16
  40. package/Layout/Section.tsx +3 -14
  41. package/Layout/layoutMetrics.ts +2 -2
  42. package/Layout/screenContent.tsx +4 -10
  43. package/Layout/screenFooter.tsx +22 -273
  44. package/Layout/screenHeader.tsx +26 -31
  45. package/Layout/screenTypes.ts +4 -27
  46. package/Layout/styles.ts +0 -10
  47. package/Layout/types.ts +0 -12
  48. package/Layout/useHeaderBarOptions.ts +54 -0
  49. package/Pagination/types.ts +6 -2
  50. package/package.json +28 -26
  51. package/Layout/__tests__/screenFooter.test.ts +0 -142
@@ -120,9 +120,9 @@ type SheetStyleParams = {
120
120
  };
121
121
 
122
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.
123
+ * Sheet container style. On foldables the sheet sits at `sheet.x`: centered on
124
+ * the window, clear of the iPhone Duo control column, and on the right half when
125
+ * half folded; the keyboard lift comes off its max height.
126
126
  */
127
127
  export const getSheetStyle = ({
128
128
  backgroundColor,
@@ -138,7 +138,7 @@ export const getSheetStyle = ({
138
138
  if (isFoldable && width !== undefined && maxHeight !== undefined) {
139
139
  foldableStyle = {
140
140
  width,
141
- marginLeft: placement.x + (placement.width - width) / 2,
141
+ marginLeft: sheet.x ?? placement.x + (placement.width - width) / 2,
142
142
  maxHeight: maxHeight - keyboardLift,
143
143
  minHeight: sheet.minHeight,
144
144
  };
@@ -7,6 +7,7 @@ import {
7
7
  Pressable,
8
8
  StyleSheet,
9
9
  View,
10
+ ViewStyle,
10
11
  } from 'react-native';
11
12
  import { ApplicationContext, MiniAppContext } from '../Context';
12
13
  import { BottomSheetParams } from './types';
@@ -190,22 +191,10 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
190
191
  />
191
192
  );
192
193
 
193
- let content: React.ReactNode;
194
+ // same tree on every layout so fold / unfold keeps the screen mounted (state, scroll)
195
+ let contentStyle: ViewStyle | undefined;
194
196
  if (isFoldable) {
195
- // Content shrinks so a tall sheet keeps its header and footer.
196
- content = (
197
- <View style={styles.shrink}>
198
- {renderSheetHeader(headerParams)}
199
- <View style={styles.shrink}>{screen}</View>
200
- </View>
201
- );
202
- } else {
203
- content = (
204
- <>
205
- {renderSheetHeader(headerParams)}
206
- {screen}
207
- </>
208
- );
197
+ contentStyle = styles.shrink;
209
198
  }
210
199
 
211
200
  return (
@@ -215,7 +204,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
215
204
  onRequestClose={() => {
216
205
  handleDismiss();
217
206
  }}
218
- style={StyleSheet.absoluteFillObject}
207
+ style={StyleSheet.absoluteFill}
219
208
  isModalKit={true}
220
209
  supportedOrientations={isDuo ? DUO_ORIENTATIONS : undefined}
221
210
  >
@@ -230,7 +219,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
230
219
  style={styles.container}
231
220
  >
232
221
  <Pressable
233
- style={StyleSheet.absoluteFillObject}
222
+ style={StyleSheet.absoluteFill}
234
223
  onPress={() => {
235
224
  action.current = 'touch';
236
225
  handleDismiss();
@@ -253,7 +242,8 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
253
242
  }),
254
243
  ]}
255
244
  >
256
- {content}
245
+ {renderSheetHeader(headerParams)}
246
+ <View style={contentStyle}>{screen}</View>
257
247
  {renderSheetFooter({ footerComponent, theme })}
258
248
  {useBottomInset && (
259
249
  <View
@@ -68,7 +68,7 @@ export const styles = StyleSheet.create({
68
68
  },
69
69
  // custom label content over the label text, centered and unclipped
70
70
  ctaLabelOverlay: {
71
- ...StyleSheet.absoluteFillObject,
71
+ ...{position: 'absolute', top: 0, bottom: 0, left: 0, right: 0},
72
72
  alignItems: 'center',
73
73
  justifyContent: 'center',
74
74
  },
@@ -57,7 +57,7 @@ export const styles = StyleSheet.create({
57
57
  },
58
58
  // custom label content over the label text, centered and unclipped
59
59
  railCtaLabelOverlay: {
60
- ...StyleSheet.absoluteFillObject,
60
+ ...{position: 'absolute', top: 0, bottom: 0, left: 0, right: 0},
61
61
  alignItems: 'center',
62
62
  justifyContent: 'center',
63
63
  },
@@ -150,7 +150,7 @@ const styles = StyleSheet.create({
150
150
  height: TabBarMetrics.iconSize,
151
151
  },
152
152
  layer: {
153
- ...StyleSheet.absoluteFillObject,
153
+ ...{position: 'absolute', top: 0, bottom: 0, left: 0, right: 0},
154
154
  alignItems: 'center',
155
155
  justifyContent: 'center',
156
156
  },
@@ -12,6 +12,8 @@ import { Colors } from '../../Consts';
12
12
  import { useNormalizedSharedValue } from '../hooks';
13
13
  import { HeaderBarMetrics, useHeaderLayout } from '../headerLayout';
14
14
 
15
+ const TRANSPARENT_ALPHA = '00';
16
+
15
17
  const ASPECT_RATIOS: Record<
16
18
  NonNullable<HeaderAnimatedProps['aspectRatio']>,
17
19
  number
@@ -21,10 +23,30 @@ const ASPECT_RATIOS: Record<
21
23
  '1/1': 1 / 1,
22
24
  };
23
25
 
26
+ /**
27
+ * Side fill colors behind the centered banner: `gradientColors` (one color fills
28
+ * solid, as LinearGradient needs two), else `backgroundColor` fading to transparent.
29
+ */
30
+ const getBannerGradientColors = (
31
+ gradientColors?: string[],
32
+ backgroundColor?: string,
33
+ ) => {
34
+ if (gradientColors?.length === 1) {
35
+ return [gradientColors[0], gradientColors[0]];
36
+ }
37
+ if (gradientColors?.length) {
38
+ return gradientColors;
39
+ }
40
+ if (backgroundColor) {
41
+ return [backgroundColor, backgroundColor + TRANSPARENT_ALPHA];
42
+ }
43
+ return undefined;
44
+ };
45
+
24
46
  /**
25
47
  * Parallax header image (or `children`): stretches when pulled down and fades out
26
- * as the content scrolls up. Wide windows and the iPhone Duo inner display keep
27
- * it at phone size, centered.
48
+ * as the content scrolls up. Wide windows and the iPhone Duo inner display center
49
+ * it at phone size × 1.2 over the side gradient.
28
50
  */
29
51
  const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
30
52
  animatedValue,
@@ -32,11 +54,16 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
32
54
  useScale = true,
33
55
  aspectRatio = '16/9',
34
56
  bannerBackgroundColor,
57
+ bannerGradientColors,
35
58
  children,
36
59
  }) => {
37
60
  const sharedValue = useNormalizedSharedValue(animatedValue);
38
61
  const { isBannerCentered, bannerWidth } = useHeaderLayout();
39
62
  const ratio = ASPECT_RATIOS[aspectRatio];
63
+ const sideColors = getBannerGradientColors(
64
+ bannerGradientColors,
65
+ bannerBackgroundColor,
66
+ );
40
67
  const animatedStyle = useAnimatedStyle(() => {
41
68
  let scale = 1;
42
69
  if (useScale) {
@@ -88,13 +115,10 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
88
115
  <Animated.View
89
116
  style={[styles.container, { height: bannerWidth / ratio }, animatedStyle]}
90
117
  >
91
- {!!bannerBackgroundColor && (
92
- <LinearGradient
93
- colors={[bannerBackgroundColor, bannerBackgroundColor + '00']}
94
- style={StyleSheet.absoluteFill}
95
- />
118
+ {sideColors && (
119
+ <LinearGradient colors={sideColors} style={StyleSheet.absoluteFill} />
96
120
  )}
97
- <View style={styles.phoneBanner}>{content}</View>
121
+ <View style={styles.centeredBanner}>{content}</View>
98
122
  </Animated.View>
99
123
  );
100
124
  };
@@ -110,7 +134,7 @@ const styles = StyleSheet.create({
110
134
  alignSelf: 'center',
111
135
  },
112
136
  full: { width: '100%', height: '100%' },
113
- phoneBanner: {
137
+ centeredBanner: {
114
138
  width: HeaderBarMetrics.bannerWidth,
115
139
  height: '100%',
116
140
  alignSelf: 'center',
@@ -17,7 +17,7 @@ import BackgroundImageView from './BackgroundImageView';
17
17
  import { type AnimatedCompatValue } from '../utils';
18
18
  import { useNormalizedSharedValue } from '../hooks';
19
19
  import { useScreenLayout } from '../../Layout';
20
- import { HeaderMetrics } from '../../Layout/utils';
20
+ import { getHeaderMargin } from '../../Layout/utils';
21
21
  import {
22
22
  HeaderBarMetrics,
23
23
  type HeaderContentLayout,
@@ -28,10 +28,12 @@ import { useHeaderRightWidth } from './useHeaderRightWidth';
28
28
  const { buttonSize, pillWidth, sidePadding, titleGap } = HeaderBarMetrics;
29
29
  const SCREEN_PADDING = sidePadding;
30
30
  const TOOLKIT_WIDTH = pillWidth + sidePadding;
31
+ // the extended header without search grows this much past the bar until scrolled
32
+ const EXTENDED_HEIGHT_EXTRA = 52;
31
33
 
32
34
  /**
33
35
  * Extended header background: a gradient that collapses on scroll and, with
34
- * `inputSearchProps`, a full-width search that slides into the bar beside back/toolkit.
36
+ * `inputSearchProps`, a window-wide search that slides into the bar beside back/toolkit.
35
37
  */
36
38
  const HeaderExtendHeader: React.FC<{
37
39
  headerType?: HeaderType;
@@ -44,6 +46,10 @@ const HeaderExtendHeader: React.FC<{
44
46
  useShadowHeader?: boolean;
45
47
  gradientColor?: string;
46
48
  headerBackground?: string;
49
+ /**
50
+ * `stretch` keeps the collapsed search beside back and the right cluster in the
51
+ * 600pt frame; the expanded search row spans the window with either layout.
52
+ */
47
53
  contentLayout?: HeaderContentLayout;
48
54
  }> = ({
49
55
  headerType = 'default',
@@ -64,8 +70,12 @@ const HeaderExtendHeader: React.FC<{
64
70
  const headerBackground = customBackground ?? theme.assets?.headerBackground;
65
71
  const layout = useScreenLayout();
66
72
  const headerLayout = useHeaderLayout(contentLayout);
67
- // the stretch frame pulls the search in from both bar edges
68
- const frameShift = headerLayout.frameInset - sidePadding;
73
+ // collapsed into the bar, the search follows back and the right cluster into the
74
+ // frame, or the side margin React Navigation adds on large iOS windows (the larger)
75
+ let frameShift = headerLayout.frameInset - sidePadding;
76
+ if (!layout.sideBar) {
77
+ frameShift = Math.max(frameShift, getHeaderMargin(layout.width));
78
+ }
69
79
 
70
80
  const backLeft = buttonSize + sidePadding + titleGap;
71
81
  const defaultLeft = layout.sideBar ? SCREEN_PADDING : backLeft;
@@ -73,22 +83,22 @@ const HeaderExtendHeader: React.FC<{
73
83
  const measuredRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
74
84
  const defaultRightWidth = layout.sideBar ? 0 : measuredRightWidth;
75
85
  const headerRightWidth = customHeaderRightWidth ?? defaultRightWidth;
76
- const contentLeft = layout.insetLeft + SCREEN_PADDING + frameShift;
77
- const contentRight = layout.insetLeft + layout.contentWidth - frameShift;
86
+ const contentLeft = layout.insetLeft + SCREEN_PADDING;
87
+ const contentRight = layout.insetLeft + layout.contentWidth;
78
88
  // collapsed on the status bar row, the search stays between its clusters
79
89
  const clearanceLeft = layout.statusBarClearance?.left ?? 0;
80
90
  const clearanceRight = layout.statusBarClearance?.right ?? 0;
81
- const searchLeft = leftPosition + clearanceLeft + frameShift;
82
- const collapsedLeft = layout.insetLeft + searchLeft;
83
- const collapsedRight = contentRight - clearanceRight - headerRightWidth;
91
+ const searchLeft = leftPosition + clearanceLeft;
92
+ const collapsedLeft = layout.insetLeft + searchLeft + frameShift;
93
+ const barRight = contentRight - clearanceRight - frameShift;
94
+ const collapsedRight = barRight - headerRightWidth;
84
95
  const searchWidth = contentRight - contentLeft - SCREEN_PADDING;
85
96
  const collapsedSearchWidth = collapsedRight - collapsedLeft - SCREEN_PADDING;
86
- // a row taller than barHeight (iPhone Duo) centers the collapsed search on the title
87
- const titleRowHeight = layout.headerHeight - layout.headerStatusBarHeight;
88
- const collapsedRaise = (titleRowHeight - HeaderMetrics.barHeight) / 2;
89
-
90
- // the iPhone Duo side bar keeps the content search size
91
- const searchSize = layout.sideBar ? 'default' : 'header';
97
+ // expanded search row under the bar: the search plus its vertical margins
98
+ const searchRowHeight = HeaderBarMetrics.searchBarHeight;
99
+ // a row taller than the search row (iPhone Duo) centers the collapsed search on the title
100
+ const titleRowHeight = heightHeader - layout.headerStatusBarHeight;
101
+ const collapsedRaise = (titleRowHeight - searchRowHeight) / 2;
92
102
 
93
103
  let useShadowHeader = useShadowHeaderProp;
94
104
  if (inputSearchProps && Platform.OS === 'android') {
@@ -101,7 +111,7 @@ const HeaderExtendHeader: React.FC<{
101
111
  height: interpolate(
102
112
  sharedValue.value,
103
113
  [0, 100],
104
- [heightHeader + 52, heightHeader],
114
+ [heightHeader + searchRowHeight, heightHeader],
105
115
  Extrapolation.CLAMP,
106
116
  ),
107
117
  }));
@@ -154,7 +164,7 @@ const HeaderExtendHeader: React.FC<{
154
164
  height: interpolate(
155
165
  sharedValue.value,
156
166
  [0, 100],
157
- [heightHeader + 52, heightHeader],
167
+ [heightHeader + EXTENDED_HEIGHT_EXTRA, heightHeader],
158
168
  Extrapolation.CLAMP,
159
169
  ),
160
170
  }));
@@ -215,7 +225,7 @@ const HeaderExtendHeader: React.FC<{
215
225
  <InputSearch
216
226
  {...inputSearchProps}
217
227
  ref={inputSearchRef}
218
- size={searchSize}
228
+ size={'header'}
219
229
  backgroundColor={'transparent'}
220
230
  showButtonText={false}
221
231
  />
@@ -1,5 +1,5 @@
1
1
  import { Colors, Radius, Spacing, Styles } from '../../Consts';
2
- import { InputRef, InputSearch, type InputSearchProps } from '../../Input';
2
+ import { InputRef, InputSearch } from '../../Input';
3
3
  import { StyleSheet, TouchableOpacity, View } from 'react-native';
4
4
  import Animated, { useAnimatedStyle } from 'react-native-reanimated';
5
5
  import React, { useContext } from 'react';
@@ -8,6 +8,7 @@ import { ApplicationContext, MiniAppContext } from '../../Context';
8
8
  import { Text } from '../../Text';
9
9
  import { useNormalizedSharedValue } from '../hooks';
10
10
  import { useScreenLayout } from '../../Layout';
11
+ import { getHeaderMargin } from '../../Layout/utils';
11
12
  import { HeaderBarMetrics } from '../headerLayout';
12
13
  import { useHeaderRightWidth } from './useHeaderRightWidth';
13
14
 
@@ -36,10 +37,8 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
36
37
  const context = useContext<any>(MiniAppContext);
37
38
  const layout = useScreenLayout();
38
39
  let defaultRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
39
- let searchSize: InputSearchProps['size'] = 'header';
40
40
  if (layout.sideBar) {
41
41
  defaultRightWidth = DUO_TOOLKIT_WIDTH;
42
- searchSize = 'default';
43
42
  }
44
43
 
45
44
  const sharedValue = useNormalizedSharedValue(animatedValue);
@@ -48,7 +47,10 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
48
47
  const headerRightWidth = props?.headerRightWidth ?? defaultRightWidth;
49
48
 
50
49
  // iPhone Duo side bar holds back: the search shares the content width with the buttons only
51
- const rowWidth = layout.width - leftPosition - sidePadding;
50
+ // large iOS windows: React Navigation narrows the header row by a margin each side
51
+ const headerMargin = getHeaderMargin(layout.width);
52
+ const rowWidth =
53
+ layout.width - leftPosition - sidePadding - headerMargin * 2;
52
54
  let searchMaxWidth = rowWidth - headerRightWidth;
53
55
  if (layout.sideBar) {
54
56
  searchMaxWidth = layout.contentWidth - Spacing.M * 2 - headerRightWidth;
@@ -118,7 +120,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
118
120
  <InputSearch
119
121
  ref={ref}
120
122
  {...props}
121
- size={searchSize}
123
+ size={'header'}
122
124
  backgroundColor={'transparent'}
123
125
  showButtonText={false}
124
126
  />
@@ -6,12 +6,14 @@ import {
6
6
  ViewStyle,
7
7
  } from 'react-native';
8
8
  import { ApplicationContext } from '../Context';
9
- import { Radius, Spacing } from '../Consts';
9
+ import { Colors } from '../Consts';
10
10
  import { Icon } from '../Icon';
11
+ import { HeaderBarMetrics } from './headerLayout';
11
12
 
12
- // modal spec: icon button 32, icon 20, shared with the Compose / SwiftUI kits
13
- const MODAL_ICON_BUTTON_SIZE = Spacing.XXL;
14
- const MODAL_ICON_SIZE = 20;
13
+ // same round button as the Top nav (NavigationButton), shared with the Compose / SwiftUI kits
14
+ const MODAL_ICON_BUTTON_SIZE = HeaderBarMetrics.buttonSize;
15
+ const MODAL_ICON_SIZE = HeaderBarMetrics.iconSize;
16
+ const MODAL_ICON_BUTTON_BORDER_WIDTH = 0.2;
15
17
 
16
18
  type ModalIconButtonProps = {
17
19
  icon: string;
@@ -21,7 +23,8 @@ type ModalIconButtonProps = {
21
23
  };
22
24
 
23
25
  /**
24
- * Close / back button of popups and bottom sheet headers
26
+ * Close / back button of popups and bottom sheet headers, drawn like the round
27
+ * Top nav icon button so modals and headers share one look.
25
28
  */
26
29
  const ModalIconButton: React.FC<ModalIconButtonProps> = ({
27
30
  icon,
@@ -34,14 +37,7 @@ const ModalIconButton: React.FC<ModalIconButtonProps> = ({
34
37
  <TouchableOpacity
35
38
  accessibilityLabel={accessibilityLabel}
36
39
  onPress={onPress}
37
- style={[
38
- styles.button,
39
- {
40
- backgroundColor: theme.colors.background.surface,
41
- borderColor: theme.colors.border.default,
42
- },
43
- style,
44
- ]}
40
+ style={[styles.button, style]}
45
41
  >
46
42
  <Icon
47
43
  source={icon}
@@ -56,10 +52,12 @@ const styles = StyleSheet.create({
56
52
  button: {
57
53
  width: MODAL_ICON_BUTTON_SIZE,
58
54
  height: MODAL_ICON_BUTTON_SIZE,
59
- borderRadius: Radius.L,
60
- borderWidth: 1,
55
+ borderRadius: MODAL_ICON_BUTTON_SIZE / 2,
56
+ borderWidth: MODAL_ICON_BUTTON_BORDER_WIDTH,
61
57
  alignItems: 'center',
62
58
  justifyContent: 'center',
59
+ backgroundColor: Colors.black_01 + '99',
60
+ borderColor: Colors.black_20 + '33',
63
61
  },
64
62
  });
65
63
 
@@ -46,7 +46,8 @@ const ModalScreen: React.FC<any> = props => {
46
46
 
47
47
  /**
48
48
  * Centered popup that fades and scales in over a scrim. On foldables it is
49
- * centered in the modal placement area, at most a popup wide.
49
+ * centered on the window (`popup.x`), clear of the iPhone Duo control column,
50
+ * at most a popup wide.
50
51
  */
51
52
  const Modal: React.FC<ModalParams> = props => {
52
53
  const { navigator } = useContext(ApplicationContext);
@@ -156,12 +157,20 @@ const Modal: React.FC<ModalParams> = props => {
156
157
  return () => backHandler.remove();
157
158
  }, [barrierDismissible, handleDismiss]);
158
159
 
160
+ // popup.x centers it on the window; without it, centered in the placement
161
+ let popupLeft = placement.x;
162
+ let popupRight = width - placement.x - placement.width;
163
+ if (popup.x !== undefined) {
164
+ popupLeft = popup.x;
165
+ popupRight = Math.max(width - popup.x - popup.width, 0);
166
+ }
167
+
159
168
  return (
160
169
  <Container
161
170
  transparent
162
171
  visible={true}
163
172
  onRequestClose={handleDismiss}
164
- style={StyleSheet.absoluteFillObject}
173
+ style={StyleSheet.absoluteFill}
165
174
  isModalKit={true}
166
175
  supportedOrientations={isDuo ? DUO_ORIENTATIONS : undefined}
167
176
  >
@@ -170,7 +179,7 @@ const Modal: React.FC<ModalParams> = props => {
170
179
  behavior={Platform.OS === 'ios' ? 'padding' : undefined}
171
180
  >
172
181
  <Pressable
173
- style={StyleSheet.absoluteFillObject}
182
+ style={StyleSheet.absoluteFill}
174
183
  onPress={() => handleDismiss(undefined, barrierDismissible)}
175
184
  >
176
185
  <Animated.View style={[styles.overlayContent, scrimStyle]} />
@@ -181,13 +190,13 @@ const Modal: React.FC<ModalParams> = props => {
181
190
  opacity,
182
191
  transform: [{ scale }],
183
192
  },
184
- // centered in the placement area, at most a popup wide
193
+ // centered on the window at popup.x, clear of the control column, at most a popup wide
185
194
  isFoldable && styles.shrink,
186
195
  isFoldable && {
187
196
  marginTop: placement.y,
188
197
  marginBottom: height - placement.y - placement.height,
189
- marginLeft: placement.x,
190
- marginRight: width - placement.x - placement.width,
198
+ marginLeft: popupLeft,
199
+ marginRight: popupRight,
191
200
  maxWidth: popup.width,
192
201
  maxHeight: popup.maxHeight,
193
202
  },
@@ -1,5 +1,4 @@
1
1
  import React, { useContext, useEffect, useLayoutEffect, useRef } from 'react';
2
- import { InteractionManager } from 'react-native';
3
2
  import { useHeaderHeight } from '@react-navigation/elements';
4
3
  import { ScreenTrackingParams } from './types';
5
4
  import Navigation from './Navigation';
@@ -14,7 +13,12 @@ const TRACKING_TIMEOUT = 5000;
14
13
  const ELEMENT_IDLE_TIMEOUT = 2000;
15
14
  const LOADING_IDLE_TIMEOUT = 2000;
16
15
 
17
- const runAfterInteractions = InteractionManager.runAfterInteractions;
16
+ // RN 0.87+: InteractionManager đã bị xoá khỏi react-native → thay bằng requestIdleCallback.
17
+ // Giữ nguyên shape trả về { cancel } để code bên dưới (timeoutInteraction?.cancel?.()) không đổi.
18
+ const runAfterInteractions = (task: () => void) => {
19
+ const handle = requestIdleCallback(() => task());
20
+ return { cancel: () => cancelIdleCallback(handle) };
21
+ };
18
22
 
19
23
  /**
20
24
  * Hosts a feature screen in the stack: applies its header options, provides
@@ -8,13 +8,13 @@ import React, {
8
8
  useReducer,
9
9
  useRef,
10
10
  } from 'react';
11
- import { StyleSheet, View } from 'react-native';
11
+ import { StyleSheet, View, type ViewInstance } from 'react-native';
12
12
 
13
13
  interface TooltipPortalContextValue {
14
14
  register: (id: string, content: ReactNode) => void;
15
15
  unregister: (id: string, immediate?: boolean) => void;
16
16
  portals: Map<string, ReactNode>;
17
- hostRef: RefObject<View | null>;
17
+ hostRef: RefObject<ViewInstance | null>;
18
18
  }
19
19
 
20
20
  const TooltipPortalContext = createContext<TooltipPortalContextValue | null>(
@@ -30,7 +30,7 @@ export const TooltipPortalProvider: React.FC<{ children: ReactNode }> = ({
30
30
  }) => {
31
31
  // The ref map updates synchronously; the reducer only triggers re-renders.
32
32
  const portalsRef = useRef<Map<string, ReactNode>>(new Map());
33
- const hostRef = useRef<View>(null);
33
+ const hostRef = useRef<ViewInstance>(null);
34
34
  const [updateCounter, forceUpdate] = useReducer((x: number) => x + 1, 0);
35
35
  const pendingUpdateRef = useRef<any>(null);
36
36
 
@@ -0,0 +1,113 @@
1
+ import {
2
+ getHeaderFrameOptions,
3
+ getHeaderLayout,
4
+ getSearchHeaderHeight,
5
+ HeaderBarMetrics,
6
+ } from '../headerLayout';
7
+
8
+ const PHONE = { width: 375, height: 812 };
9
+ const FOLD_INNER = { width: 760, height: 840 };
10
+ const DUO_INNER = { width: 932, height: 678 };
11
+
12
+ describe('getHeaderLayout', () => {
13
+ it('keeps the phone row at the bar edges with a full-width banner', () => {
14
+ const layout = getHeaderLayout({ ...PHONE, isDuo: false });
15
+ expect(layout.isWide).toBe(false);
16
+ expect(layout.isBannerCentered).toBe(false);
17
+ expect(layout.bannerScale).toBe(1);
18
+ expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
19
+ expect(layout.frameWidth).toBe(351);
20
+ });
21
+
22
+ it('keeps the grid row at the bar edges on a 760 window', () => {
23
+ const layout = getHeaderLayout({ ...FOLD_INNER, isDuo: false });
24
+ expect(layout.isWide).toBe(true);
25
+ expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
26
+ expect(layout.frameWidth).toBe(736);
27
+ });
28
+
29
+ it('centers the stretch row in the 600 frame on a 760 window', () => {
30
+ const input = { ...FOLD_INNER, isDuo: false };
31
+ const layout = getHeaderLayout({ ...input, contentLayout: 'stretch' });
32
+ expect(layout.frameInset).toBe(80);
33
+ expect(layout.frameWidth).toBe(600);
34
+ });
35
+
36
+ it('scales the centered banner to 450 on a 760 window', () => {
37
+ const layout = getHeaderLayout({ ...FOLD_INNER, isDuo: false });
38
+ expect(layout.isBannerCentered).toBe(true);
39
+ expect(layout.bannerScale).toBe(1.2);
40
+ expect(layout.bannerWidth).toBe(450);
41
+ });
42
+
43
+ it('centers the banner on the iPhone Duo inner display, without the frame', () => {
44
+ const input = { ...DUO_INNER, isDuo: true };
45
+ const layout = getHeaderLayout({ ...input, contentLayout: 'stretch' });
46
+ expect(layout.isWide).toBe(false);
47
+ expect(layout.isBannerCentered).toBe(true);
48
+ expect(layout.bannerScale).toBe(1.2);
49
+ expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
50
+ });
51
+ });
52
+
53
+ describe('getSearchHeaderHeight', () => {
54
+ it('grows a 48 bar row to the 56 search row', () => {
55
+ expect(getSearchHeaderHeight(48 + 47, 47)).toBe(56 + 47);
56
+ });
57
+
58
+ it('keeps a row taller than the search row', () => {
59
+ expect(getSearchHeaderHeight(72, 0)).toBe(72);
60
+ });
61
+ });
62
+
63
+ describe('getHeaderFrameOptions', () => {
64
+ const NO_EDGE = { left: 0, right: 0 };
65
+ const DUO_EDGE = { left: 60, right: 90 };
66
+ const frameInput = (contentLayout?: 'grid' | 'stretch') => {
67
+ const layout = getHeaderLayout({
68
+ ...FOLD_INNER,
69
+ isDuo: false,
70
+ contentLayout,
71
+ });
72
+ return { layout, isDuo: false, headerMargin: 0, edgePadding: NO_EDGE };
73
+ };
74
+
75
+ it('leaves the options alone when contentLayout is unset', () => {
76
+ expect(getHeaderFrameOptions(frameInput())).toBeUndefined();
77
+ });
78
+
79
+ it('pulls the stretch row into the 600 frame on a 760 window', () => {
80
+ const options = getHeaderFrameOptions({
81
+ ...frameInput('stretch'),
82
+ contentLayout: 'stretch',
83
+ });
84
+ expect(options?.headerLeftContainerStyle).toEqual({ paddingLeft: 68 });
85
+ expect(options?.headerRightContainerStyle).toEqual({ paddingRight: 68 });
86
+ });
87
+
88
+ it('resets grid to the bar edges, so a former stretch frame does not stay', () => {
89
+ const options = getHeaderFrameOptions({
90
+ ...frameInput('grid'),
91
+ contentLayout: 'grid',
92
+ });
93
+ expect(options?.headerLeftContainerStyle).toEqual({ paddingLeft: 0 });
94
+ expect(options?.headerRightContainerStyle).toEqual({ paddingRight: 0 });
95
+ expect(options?.headerTitleContainerStyle).toMatchObject({
96
+ left: HeaderBarMetrics.titleGap,
97
+ });
98
+ expect(options?.headerTitleContainerStyle).not.toHaveProperty('maxWidth');
99
+ });
100
+
101
+ it('keeps the iPhone Duo status bar clearance with stretch', () => {
102
+ const layout = getHeaderLayout({ ...DUO_INNER, isDuo: true });
103
+ const options = getHeaderFrameOptions({
104
+ layout,
105
+ isDuo: true,
106
+ headerMargin: 0,
107
+ edgePadding: DUO_EDGE,
108
+ contentLayout: 'stretch',
109
+ });
110
+ expect(options?.headerLeftContainerStyle).toEqual({ paddingLeft: 60 });
111
+ expect(options?.headerRightContainerStyle).toEqual({ paddingRight: 90 });
112
+ });
113
+ });