@momo-kits/foundation 0.169.18 → 0.169.19-beta.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.
@@ -120,9 +120,9 @@ type SheetStyleParams = {
120
120
  };
121
121
 
122
122
  /**
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.
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
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: sheet.x ?? placement.x + (placement.width - width) / 2,
141
+ marginLeft: placement.x + (placement.width - width) / 2,
142
142
  maxHeight: maxHeight - keyboardLift,
143
143
  minHeight: sheet.minHeight,
144
144
  };
@@ -7,7 +7,6 @@ import {
7
7
  Pressable,
8
8
  StyleSheet,
9
9
  View,
10
- ViewStyle,
11
10
  } from 'react-native';
12
11
  import { ApplicationContext, MiniAppContext } from '../Context';
13
12
  import { BottomSheetParams } from './types';
@@ -191,10 +190,22 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
191
190
  />
192
191
  );
193
192
 
194
- // same tree on every layout so fold / unfold keeps the screen mounted (state, scroll)
195
- let contentStyle: ViewStyle | undefined;
193
+ let content: React.ReactNode;
196
194
  if (isFoldable) {
197
- contentStyle = styles.shrink;
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
+ );
198
209
  }
199
210
 
200
211
  return (
@@ -242,8 +253,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
242
253
  }),
243
254
  ]}
244
255
  >
245
- {renderSheetHeader(headerParams)}
246
- <View style={contentStyle}>{screen}</View>
256
+ {content}
247
257
  {renderSheetFooter({ footerComponent, theme })}
248
258
  {useBottomInset && (
249
259
  <View
@@ -17,7 +17,6 @@ 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 { getHeaderMargin } from '../../Layout/utils';
21
20
  import {
22
21
  HeaderBarMetrics,
23
22
  type HeaderContentLayout,
@@ -70,12 +69,8 @@ const HeaderExtendHeader: React.FC<{
70
69
  const headerBackground = customBackground ?? theme.assets?.headerBackground;
71
70
  const layout = useScreenLayout();
72
71
  const headerLayout = useHeaderLayout(contentLayout);
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
- }
72
+ // collapsed into the bar, the search follows back and the right cluster into the frame
73
+ const frameShift = headerLayout.frameInset - sidePadding;
79
74
 
80
75
  const backLeft = buttonSize + sidePadding + titleGap;
81
76
  const defaultLeft = layout.sideBar ? SCREEN_PADDING : backLeft;
@@ -1,4 +1,4 @@
1
- import { BackHandler, StyleSheet, View } from 'react-native';
1
+ import { BackHandler, useWindowDimensions, View } from 'react-native';
2
2
  import type { HeaderBackProps } from '../types';
3
3
  import React, { useCallback, useContext, useEffect } from 'react';
4
4
  import { ApplicationContext, MiniAppContext } from '../../Context';
@@ -8,11 +8,12 @@ import { SideBarButton } from './SideBarButton';
8
8
  import Animated from 'react-native-reanimated';
9
9
  import { useSideBarItemStyle } from '../../Layout/utils';
10
10
  import { useSideBarCounterStyle } from './DuoQuickReturnHeader';
11
- import { HeaderBarMetrics } from '../headerLayout';
11
+ import { getHeaderRowInset } from '../headerLayout';
12
12
 
13
13
  /**
14
14
  * Header back button, also bound to the Android hardware back. `preventBack`
15
15
  * confirms in a popup first; the iPhone Duo side bar uses the 48pt side bar button.
16
+ * In the bar it sits `sidePadding` from the window edge on every iPhone width.
16
17
  */
17
18
  const HeaderLeft: React.FC<HeaderBackProps> = ({
18
19
  tintColor,
@@ -25,6 +26,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
25
26
  const { navigator } = useContext(ApplicationContext);
26
27
  const sideBarStyle = useSideBarItemStyle('left', 0);
27
28
  const counterStyle = useSideBarCounterStyle();
29
+ const { width } = useWindowDimensions();
28
30
 
29
31
  const goBack = useCallback(() => {
30
32
  const canGoBack = navigator?.ref?.current?.canGoBack?.();
@@ -98,7 +100,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
98
100
  }
99
101
 
100
102
  return (
101
- <View style={styles.headerLeft}>
103
+ <View style={{ marginLeft: getHeaderRowInset(width) }}>
102
104
  <NavigationButton
103
105
  accessibilityLabel="btn_navigation_back"
104
106
  icon="arrow-back"
@@ -109,10 +111,4 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
109
111
  );
110
112
  };
111
113
 
112
- const styles = StyleSheet.create({
113
- headerLeft: {
114
- marginLeft: HeaderBarMetrics.sidePadding,
115
- },
116
- });
117
-
118
114
  export { HeaderLeft };
@@ -2,7 +2,7 @@ import { Platform, StyleSheet } from 'react-native';
2
2
  import { Colors, Spacing } from '../../Consts';
3
3
  import { HeaderBarMetrics } from '../headerLayout';
4
4
 
5
- const { buttonSize, pillWidth, pillHeight, sidePadding } = HeaderBarMetrics;
5
+ const { buttonSize, pillWidth, pillHeight } = HeaderBarMetrics;
6
6
 
7
7
  export const styles = StyleSheet.create({
8
8
  navigationButton: {
@@ -48,7 +48,6 @@ export const styles = StyleSheet.create({
48
48
  flexDirection: 'row',
49
49
  justifyContent: 'center',
50
50
  alignItems: 'center',
51
- paddingRight: sidePadding,
52
51
  },
53
52
  toolkitContainer: {
54
53
  height: pillHeight,
@@ -134,9 +133,6 @@ export const styles = StyleSheet.create({
134
133
  },
135
134
  }),
136
135
  },
137
- onBoarding: {
138
- marginRight: Spacing.M,
139
- },
140
136
  toolkitWide: {
141
137
  width: pillWidth,
142
138
  },
@@ -1,10 +1,16 @@
1
1
  import React, { useCallback, useContext, useEffect } from 'react';
2
- import { type LayoutChangeEvent, TouchableOpacity, View } from 'react-native';
2
+ import {
3
+ type LayoutChangeEvent,
4
+ TouchableOpacity,
5
+ useWindowDimensions,
6
+ View,
7
+ } from 'react-native';
3
8
  import { NavigationRouteContext } from '@react-navigation/native';
4
9
  import { ApplicationContext } from '../../Context';
5
10
  import { Text } from '../../Text';
6
11
  import Animated from 'react-native-reanimated';
7
- import { useSideBarItemStyle } from '../../Layout/utils';
12
+ import { getHeaderMargin, useSideBarItemStyle } from '../../Layout/utils';
13
+ import { getHeaderRowInset } from '../headerLayout';
8
14
  import { useSideBarCounterStyle } from './DuoQuickReturnHeader';
9
15
  import { HeaderToolkitAction } from './HeaderToolkitAction';
10
16
  import { styles } from './HeaderRight.styles';
@@ -13,7 +19,8 @@ import { setHeaderRightWidth } from './useHeaderRightWidth';
13
19
  /**
14
20
  * Header right slot: a custom `headerRight` render function, the onboarding skip
15
21
  * button, or the toolkit (stacked vertically in the floating iPhone Duo side bar).
16
- * The bar toolkit reports its width so header searches stop short of it.
22
+ * The bar toolkit sits `sidePadding` from the window edge and reports its width
23
+ * from that edge so header searches stop short of it.
17
24
  */
18
25
  const HeaderRight: React.FC<any> = props => {
19
26
  const { translate } = useContext(ApplicationContext);
@@ -22,14 +29,18 @@ const HeaderRight: React.FC<any> = props => {
22
29
  const sideBarStyle = useSideBarItemStyle('right', 1);
23
30
  const counterStyle = useSideBarCounterStyle();
24
31
  const routeKey = useContext(NavigationRouteContext)?.key;
32
+ const { width } = useWindowDimensions();
33
+ const rowMargin = getHeaderMargin(width);
34
+ const rowInset = getHeaderRowInset(width);
25
35
 
26
36
  const handleToolkitLayout = useCallback(
27
37
  (event: LayoutChangeEvent) => {
28
38
  if (routeKey) {
29
- setHeaderRightWidth(routeKey, event.nativeEvent.layout.width);
39
+ const toolkitWidth = event.nativeEvent.layout.width + rowMargin;
40
+ setHeaderRightWidth(routeKey, toolkitWidth);
30
41
  }
31
42
  },
32
- [routeKey],
43
+ [routeKey, rowMargin],
33
44
  );
34
45
 
35
46
  useEffect(() => {
@@ -46,7 +57,7 @@ const HeaderRight: React.FC<any> = props => {
46
57
 
47
58
  if (useOnBoarding && onPress) {
48
59
  return (
49
- <TouchableOpacity onPress={onPress} style={styles.onBoarding}>
60
+ <TouchableOpacity onPress={onPress} style={{ marginRight: rowInset }}>
50
61
  <Text typography={'action_s_bold'}>
51
62
  {buttonOnBoarding || translate?.('skip')}
52
63
  </Text>
@@ -70,7 +81,10 @@ const HeaderRight: React.FC<any> = props => {
70
81
  }
71
82
 
72
83
  return (
73
- <View style={styles.headerRightButton} onLayout={handleToolkitLayout}>
84
+ <View
85
+ style={[styles.headerRightButton, { paddingRight: rowInset }]}
86
+ onLayout={handleToolkitLayout}
87
+ >
74
88
  <HeaderToolkitAction {...props.headerRight} tintColor={props.tintColor} />
75
89
  </View>
76
90
  );
@@ -8,7 +8,6 @@ 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';
12
11
  import { HeaderBarMetrics } from '../headerLayout';
13
12
  import { useHeaderRightWidth } from './useHeaderRightWidth';
14
13
 
@@ -47,10 +46,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
47
46
  const headerRightWidth = props?.headerRightWidth ?? defaultRightWidth;
48
47
 
49
48
  // iPhone Duo side bar holds back: the search shares the content width with the buttons only
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;
49
+ const rowWidth = layout.width - leftPosition - sidePadding;
54
50
  let searchMaxWidth = rowWidth - headerRightWidth;
55
51
  if (layout.sideBar) {
56
52
  searchMaxWidth = layout.contentWidth - Spacing.M * 2 - headerRightWidth;
@@ -16,8 +16,8 @@ const subscribe = (listener: () => void) => {
16
16
  };
17
17
 
18
18
  /**
19
- * Records the laid out width of a route's header right, side padding included;
20
- * `undefined` clears it when the header right unmounts.
19
+ * Records how far a route's header right reaches in from the window edge, side
20
+ * padding included; `undefined` clears it when the header right unmounts.
21
21
  */
22
22
  const setHeaderRightWidth = (routeKey: string, width?: number) => {
23
23
  if (widths.get(routeKey) === width) {
@@ -6,14 +6,12 @@ import {
6
6
  ViewStyle,
7
7
  } from 'react-native';
8
8
  import { ApplicationContext } from '../Context';
9
- import { Colors } from '../Consts';
9
+ import { Radius, Spacing } from '../Consts';
10
10
  import { Icon } from '../Icon';
11
- import { HeaderBarMetrics } from './headerLayout';
12
11
 
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;
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;
17
15
 
18
16
  type ModalIconButtonProps = {
19
17
  icon: string;
@@ -23,8 +21,7 @@ type ModalIconButtonProps = {
23
21
  };
24
22
 
25
23
  /**
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.
24
+ * Close / back button of popups and bottom sheet headers
28
25
  */
29
26
  const ModalIconButton: React.FC<ModalIconButtonProps> = ({
30
27
  icon,
@@ -37,7 +34,14 @@ const ModalIconButton: React.FC<ModalIconButtonProps> = ({
37
34
  <TouchableOpacity
38
35
  accessibilityLabel={accessibilityLabel}
39
36
  onPress={onPress}
40
- style={[styles.button, style]}
37
+ style={[
38
+ styles.button,
39
+ {
40
+ backgroundColor: theme.colors.background.surface,
41
+ borderColor: theme.colors.border.default,
42
+ },
43
+ style,
44
+ ]}
41
45
  >
42
46
  <Icon
43
47
  source={icon}
@@ -52,12 +56,10 @@ const styles = StyleSheet.create({
52
56
  button: {
53
57
  width: MODAL_ICON_BUTTON_SIZE,
54
58
  height: MODAL_ICON_BUTTON_SIZE,
55
- borderRadius: MODAL_ICON_BUTTON_SIZE / 2,
56
- borderWidth: MODAL_ICON_BUTTON_BORDER_WIDTH,
59
+ borderRadius: Radius.L,
60
+ borderWidth: 1,
57
61
  alignItems: 'center',
58
62
  justifyContent: 'center',
59
- backgroundColor: Colors.black_01 + '99',
60
- borderColor: Colors.black_20 + '33',
61
63
  },
62
64
  });
63
65
 
@@ -46,8 +46,7 @@ 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 on the window (`popup.x`), clear of the iPhone Duo control column,
50
- * at most a popup wide.
49
+ * centered in the modal placement area, at most a popup wide.
51
50
  */
52
51
  const Modal: React.FC<ModalParams> = props => {
53
52
  const { navigator } = useContext(ApplicationContext);
@@ -157,14 +156,6 @@ const Modal: React.FC<ModalParams> = props => {
157
156
  return () => backHandler.remove();
158
157
  }, [barrierDismissible, handleDismiss]);
159
158
 
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
-
168
159
  return (
169
160
  <Container
170
161
  transparent
@@ -190,13 +181,13 @@ const Modal: React.FC<ModalParams> = props => {
190
181
  opacity,
191
182
  transform: [{ scale }],
192
183
  },
193
- // centered on the window at popup.x, clear of the control column, at most a popup wide
184
+ // centered in the placement area, at most a popup wide
194
185
  isFoldable && styles.shrink,
195
186
  isFoldable && {
196
187
  marginTop: placement.y,
197
188
  marginBottom: height - placement.y - placement.height,
198
- marginLeft: popupLeft,
199
- marginRight: popupRight,
189
+ marginLeft: placement.x,
190
+ marginRight: width - placement.x - placement.width,
200
191
  maxWidth: popup.width,
201
192
  maxHeight: popup.maxHeight,
202
193
  },
@@ -69,7 +69,7 @@ describe('getHeaderFrameOptions', () => {
69
69
  isDuo: false,
70
70
  contentLayout,
71
71
  });
72
- return { layout, isDuo: false, headerMargin: 0, edgePadding: NO_EDGE };
72
+ return { layout, isDuo: false, edgePadding: NO_EDGE };
73
73
  };
74
74
 
75
75
  it('leaves the options alone when contentLayout is unset', () => {
@@ -103,7 +103,6 @@ describe('getHeaderFrameOptions', () => {
103
103
  const options = getHeaderFrameOptions({
104
104
  layout,
105
105
  isDuo: true,
106
- headerMargin: 0,
107
106
  edgePadding: DUO_EDGE,
108
107
  contentLayout: 'stretch',
109
108
  });
@@ -85,8 +85,6 @@ type EdgePadding = { left: number; right: number };
85
85
  type HeaderFrameInput = {
86
86
  layout: HeaderLayout;
87
87
  isDuo: boolean;
88
- // side margin @react-navigation/elements already adds to the row
89
- headerMargin: number;
90
88
  // padding of the plain row containers: the iPhone Duo status bar clearance, else 0
91
89
  edgePadding: EdgePadding;
92
90
  contentLayout?: HeaderContentLayout;
@@ -123,6 +121,14 @@ const getHeaderLayout = ({
123
121
  };
124
122
  };
125
123
 
124
+ /**
125
+ * Inset from the React Navigation header row that puts an item `sidePadding` from
126
+ * the window edge: large iOS windows already inset that row by `getHeaderMargin`.
127
+ */
128
+ const getHeaderRowInset = (width: number) => {
129
+ return HeaderBarMetrics.sidePadding - getHeaderMargin(width);
130
+ };
131
+
126
132
  /**
127
133
  * Widest a title can be between back and the right cluster of the header row.
128
134
  */
@@ -189,7 +195,6 @@ const getEdgeFrameOptions = (
189
195
  const getHeaderFrameOptions = ({
190
196
  layout,
191
197
  isDuo,
192
- headerMargin,
193
198
  edgePadding,
194
199
  contentLayout,
195
200
  }: HeaderFrameInput): StackNavigationOptions | undefined => {
@@ -199,12 +204,11 @@ const getHeaderFrameOptions = ({
199
204
  if (contentLayout !== 'stretch' || isDuo) {
200
205
  return getEdgeFrameOptions(edgePadding);
201
206
  }
202
- // the header content row already sits this far in on large iOS windows
207
+ // back and toolkit already net out the header row margin of large iOS windows
203
208
  const shift = layout.frameInset - layout.sidePadding;
204
- const containerShift = Math.max(0, shift - headerMargin);
205
209
  return {
206
- headerLeftContainerStyle: { paddingLeft: containerShift },
207
- headerRightContainerStyle: { paddingRight: containerShift },
210
+ headerLeftContainerStyle: { paddingLeft: shift },
211
+ headerRightContainerStyle: { paddingRight: shift },
208
212
  headerTitleContainerStyle: {
209
213
  ...TITLE_CONTAINER_RESET,
210
214
  left: layout.titleGap,
@@ -225,17 +229,15 @@ const useHeaderFrameOptions = (
225
229
  const rowOptions = getHeaderRowOptions(screenLayout);
226
230
  const edgeLeft = rowOptions.headerLeftContainerStyle?.paddingLeft ?? 0;
227
231
  const edgeRight = rowOptions.headerRightContainerStyle?.paddingRight ?? 0;
228
- const headerMargin = getHeaderMargin(screenLayout.width);
229
232
  const isDuo = isIPhoneDuo();
230
233
  return useMemo(() => {
231
234
  return getHeaderFrameOptions({
232
235
  layout,
233
236
  isDuo,
234
- headerMargin,
235
237
  edgePadding: { left: edgeLeft, right: edgeRight },
236
238
  contentLayout,
237
239
  });
238
- }, [contentLayout, isDuo, layout, headerMargin, edgeLeft, edgeRight]);
240
+ }, [contentLayout, isDuo, layout, edgeLeft, edgeRight]);
239
241
  };
240
242
 
241
243
  export type { HeaderContentLayout, HeaderLayout };
@@ -247,6 +249,7 @@ export {
247
249
  getHeaderFrameOptions,
248
250
  getHeaderLayout,
249
251
  getSearchHeaderHeight,
252
+ getHeaderRowInset,
250
253
  getTitleBudget,
251
254
  useHeaderLayout,
252
255
  useHeaderFrameOptions,
@@ -8,7 +8,7 @@ import { isIPhoneDuo } from './utils';
8
8
  const POPUP_MAX_WIDTH = 450;
9
9
  const POPUP_MIN_WIDTH = 280;
10
10
  const POPUP_MAX_HEIGHT = 600;
11
- const SHEET_MAX_WIDTH = 600;
11
+ const SHEET_MAX_WIDTH = 653;
12
12
  const SHEET_MIN_WIDTH = 296;
13
13
  const SHEET_MIN_HEIGHT = 230;
14
14
  const FOLDABLE_MIN_WIDTH = 600;
@@ -46,12 +46,6 @@ export type ModalLayout = {
46
46
  maxHeight?: number;
47
47
  margin: number;
48
48
  radius: number;
49
- /**
50
- * Window x of the left edge of a `width` wide popup, `undefined` on phones.
51
- * Centered on the window, but a margin clear of the iPhone Duo control
52
- * column / system insets; half folded it is centered in the right half.
53
- */
54
- x?: number;
55
49
  };
56
50
 
57
51
  sheet: {
@@ -59,12 +53,6 @@ export type ModalLayout = {
59
53
  * `undefined` on phones, the sheet spans the window.
60
54
  */
61
55
  width?: number;
62
- /**
63
- * Window x of the sheet's left edge, `undefined` on phones. Centered on the
64
- * window, but kept a margin clear of the iPhone Duo control column / system
65
- * insets; half folded it is centered in the right half.
66
- */
67
- x?: number;
68
56
  maxHeight?: number;
69
57
  minHeight?: number;
70
58
  margin: number;
@@ -90,25 +78,6 @@ const clamp = (value: number, min: number, max: number) => {
90
78
  return Math.min(Math.max(value, min), max);
91
79
  };
92
80
 
93
- /**
94
- * Window x of a `boxWidth` wide overlay: centered on `center` (the window, so
95
- * an inset on one side does not push it off center) but `margin` inside the
96
- * placement; centered in the placement when it does not fit with the margins.
97
- */
98
- const overlayX = (
99
- center: number,
100
- placement: ModalRect,
101
- boxWidth: number,
102
- margin: number,
103
- ) => {
104
- const min = placement.x + margin;
105
- const max = placement.x + placement.width - margin - boxWidth;
106
- if (max < min) {
107
- return placement.x + (placement.width - boxWidth) / 2;
108
- }
109
- return clamp(center - boxWidth / 2, min, max);
110
- };
111
-
112
81
  /**
113
82
  * Modal geometry for a window, pure so it can be tested without a device.
114
83
  */
@@ -161,20 +130,12 @@ const getModalLayout = ({
161
130
  const sheetSpace = placement.width - sheetMargin * 2;
162
131
  const sheetMinWidth = Math.min(SHEET_MIN_WIDTH, sheetSpace);
163
132
  const sheetMaxHeight = height - insets.top - Spacing.M;
164
- const sheetWidth = clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH);
165
- const popupWidth = clamp(popupSpace, popupMinWidth, POPUP_MAX_WIDTH);
166
- // the window center; half folded, the right half's
167
- let overlayCenter = width / 2;
168
- if (isHalfFolded) {
169
- overlayCenter = placement.x + placement.width / 2;
170
- }
171
133
 
172
134
  return {
173
135
  isFoldable,
174
136
  placement,
175
137
  popup: {
176
- width: popupWidth,
177
- x: overlayX(overlayCenter, placement, popupWidth, popupMargin),
138
+ width: clamp(popupSpace, popupMinWidth, POPUP_MAX_WIDTH),
178
139
  minWidth: popupMinWidth,
179
140
  maxWidth: POPUP_MAX_WIDTH,
180
141
  maxHeight: Math.min(POPUP_MAX_HEIGHT, placement.height - Spacing.XL * 2),
@@ -182,8 +143,7 @@ const getModalLayout = ({
182
143
  radius: Radius.XL,
183
144
  },
184
145
  sheet: {
185
- width: sheetWidth,
186
- x: overlayX(overlayCenter, placement, sheetWidth, sheetMargin),
146
+ width: clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH),
187
147
  maxHeight: sheetMaxHeight,
188
148
  minHeight: Math.min(SHEET_MIN_HEIGHT, sheetMaxHeight),
189
149
  margin: sheetMargin,
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Platform } from 'react-native';
2
+ import { Dimensions, Platform } from 'react-native';
3
3
  import {
4
4
  CardStyleInterpolators,
5
5
  type StackCardInterpolatedStyle,
@@ -13,7 +13,11 @@ import { HeaderBackground } from './Components/HeaderBackground';
13
13
  import { HeaderLeft } from './Components/HeaderLeft';
14
14
  import { HeaderRight } from './Components/HeaderRight';
15
15
  import { HeaderTitle, TitleCustom } from './Components/HeaderTitle';
16
- import { HeaderBarMetrics, TITLE_CONTAINER_RESET } from './headerLayout';
16
+ import {
17
+ getHeaderRowInset,
18
+ HeaderBarMetrics,
19
+ TITLE_CONTAINER_RESET,
20
+ } from './headerLayout';
17
21
  import type { HeaderTitleProps, NavigationOptions } from './types';
18
22
 
19
23
  const CARD_SHADOW_OPACITY = 0.3;
@@ -144,8 +148,9 @@ const exportHeaderTitle = (
144
148
  };
145
149
 
146
150
  /**
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.
151
+ * React Navigation options from screen params: design system header left, title
152
+ * (`sidePadding` from the window edge with hidden back) and right, and swipe back
153
+ * off for screens that own their back flow.
149
154
  */
150
155
  const getOptions = (
151
156
  params: NavigationOptions,
@@ -167,9 +172,11 @@ const getOptions = (
167
172
  };
168
173
  if (params.hiddenBack) {
169
174
  headerLeft = null;
175
+ // options are static, so the window width is read once when they are built
176
+ const { width } = Dimensions.get('window');
170
177
  options.headerTitleContainerStyle = {
171
178
  ...TITLE_CONTAINER_RESET,
172
- left: HeaderBarMetrics.sidePadding,
179
+ left: getHeaderRowInset(width),
173
180
  };
174
181
  }
175
182
  options = {
@@ -45,7 +45,7 @@ const ErrorView: FC<ErrorViewProps> = ({
45
45
  color={messageColor}
46
46
  typography={'description_default_regular'}
47
47
  >
48
- {errorMessage || hintTextDefault}
48
+ {errorMessage ?? hintTextDefault}
49
49
  </Text>
50
50
  </View>
51
51
  );
@@ -53,8 +53,8 @@ type InputMoneyViewProps = Pick<
53
53
  };
54
54
 
55
55
  /**
56
- * Presentational body of InputMoney: bordered field, currency suffix (shown
57
- * once there is a value) and the clear/trailing icons.
56
+ * Presentational body of InputMoney: bordered field, currency suffix (kept
57
+ * after a placeholder that ends with it) and the clear/trailing icons.
58
58
  */
59
59
  export const InputMoneyView = ({
60
60
  size,
@@ -101,8 +101,13 @@ export const InputMoneyView = ({
101
101
  fontSize: scaledFontSize,
102
102
  fontFamily: inputFontFamily,
103
103
  };
104
- const hasValue = displayValue.length > 0;
104
+ const hasCurrencyInPlaceholder = placeholder.endsWith(currency);
105
+ const shouldShowCurrency = !!displayValue || hasCurrencyInPlaceholder;
105
106
  const shouldShowClearIcon = !!(showClearIcon && focused && displayValue);
107
+ let inputPlaceholder = placeholder;
108
+ if (hasCurrencyInPlaceholder) {
109
+ inputPlaceholder = placeholder.slice(0, -currency.length);
110
+ }
106
111
  return (
107
112
  <View
108
113
  style={[
@@ -143,15 +148,18 @@ export const InputMoneyView = ({
143
148
  onChangeText={onChangeText}
144
149
  onFocus={onFocus}
145
150
  onBlur={onBlur}
146
- placeholder={placeholder}
151
+ placeholder={inputPlaceholder}
147
152
  selectionColor={theme.colors.primary}
148
153
  placeholderTextColor={placeholderColor}
149
154
  keyboardType={'numeric'}
150
155
  maxLength={undefined}
151
156
  />
152
- {hasValue && (
157
+ {shouldShowCurrency && (
153
158
  <Text
154
- style={[textStyle, { color: textColor }]}
159
+ style={[
160
+ textStyle,
161
+ { color: displayValue ? textColor : placeholderColor },
162
+ ]}
155
163
  allowFontScaling={false}
156
164
  >
157
165
  {currency}
@@ -6,6 +6,7 @@ import React, {
6
6
  useState,
7
7
  } from 'react';
8
8
  import {
9
+ StyleSheet,
9
10
  TextInput,
10
11
  TextInputFocusEvent,
11
12
  TouchableOpacity,
@@ -17,11 +18,12 @@ import {
17
18
  ComponentContext,
18
19
  MiniAppContext,
19
20
  } from '../Context';
21
+ import { Colors, Spacing, Styles } from '../Consts';
20
22
  import { Icon } from '../Icon';
21
- import { useScaleSize, exportFontFamily } from '../Text';
23
+ import { Image } from '../Image';
24
+ import { useScaleSize, Text, exportFontFamily } from '../Text';
22
25
  import { Typography } from '../Text/types';
23
26
  import { CLEAR_ICON_SIZE } from './constants';
24
- import { CountryCodeView } from './CountryCodeView';
25
27
  import { ErrorView } from './ErrorView';
26
28
  import { InputPhoneNumberProps } from './index';
27
29
  import { RenderTrailing } from './RenderTrailing';
@@ -34,13 +36,11 @@ const LARGE_FONT_SIZE = 18;
34
36
  const SMALL_DIVIDER_HEIGHT = 24;
35
37
  const LARGE_DIVIDER_HEIGHT = 32;
36
38
  const FOCUSED_BORDER_WIDTH = 1.5;
37
- const DEFAULT_COUNTRY_CODE = '+84';
38
- const DEFAULT_COUNTRY_FLAG =
39
- 'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png';
39
+ const FLAG_SIZE = 24;
40
40
 
41
41
  /**
42
- * Phone number input behind a country flag and dial code (Vietnam `+84` by
43
- * default), number pad by default, plus clear and trailing icons.
42
+ * Vietnamese phone number input with a fixed flag and `+84` prefix, number pad
43
+ * by default, plus clear and trailing icons.
44
44
  */
45
45
  const InputPhoneNumber = forwardRef(
46
46
  (
@@ -66,9 +66,6 @@ const InputPhoneNumber = forwardRef(
66
66
  editable = true,
67
67
  showClearIcon = true,
68
68
  defaultValue,
69
- countryCode = DEFAULT_COUNTRY_CODE,
70
- countryFlag = DEFAULT_COUNTRY_FLAG,
71
- onPressLeadingIcon,
72
69
  ...props
73
70
  }: InputPhoneNumberProps,
74
71
  ref,
@@ -185,16 +182,29 @@ const InputPhoneNumber = forwardRef(
185
182
  ]}
186
183
  >
187
184
  <View style={styles.inputView}>
188
- <CountryCodeView
189
- countryCode={countryCode}
190
- countryFlag={countryFlag}
191
- typography={typography}
192
- textColor={textColor}
193
- dividerHeight={dividerHeight}
194
- componentId={componentId}
195
- isDisabled={disabled || !editable}
196
- onPress={onPressLeadingIcon}
197
- />
185
+ <View style={[styles.leadingIconContainer, Styles.row]}>
186
+ <Image
187
+ source={{
188
+ uri: 'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png',
189
+ }}
190
+ style={innerStyle.iconFlag}
191
+ resizeMode="contain"
192
+ accessibilityLabel={`${componentId}|leading-icon`}
193
+ />
194
+ <View style={{ width: Spacing.XS }} />
195
+ <Text typography={typography} color={textColor}>
196
+ {'+84'}
197
+ </Text>
198
+ <View
199
+ style={[
200
+ styles.phoneNumberDivider,
201
+ {
202
+ height: dividerHeight,
203
+ backgroundColor: Colors.black_04,
204
+ },
205
+ ]}
206
+ />
207
+ </View>
198
208
  <SystemTextInput
199
209
  {...props}
200
210
  accessibilityLabel={`${componentId}`}
@@ -292,4 +302,12 @@ const InputPhoneNumber = forwardRef(
292
302
  },
293
303
  );
294
304
 
305
+ const innerStyle = StyleSheet.create({
306
+ iconFlag: {
307
+ width: FLAG_SIZE,
308
+ height: FLAG_SIZE,
309
+ marginHorizontal: Spacing.XXS,
310
+ },
311
+ });
312
+
295
313
  export default InputPhoneNumber;
package/Input/index.tsx CHANGED
@@ -351,23 +351,9 @@ export interface InputDropDownProps extends TouchableOpacityProps {
351
351
 
352
352
  export interface InputPhoneNumberProps extends InputProps {
353
353
  /**
354
- * Optional. Dial code shown verbatim before the number.
355
- * Defaults to `+84` if not provided.
354
+ * Optional. Currently unused: the displayed prefix is always `+84`.
356
355
  */
357
356
  countryCode?: string;
358
-
359
- /**
360
- * Optional. URL of the flag image shown before the dial code.
361
- * Defaults to the Vietnam flag if not provided.
362
- */
363
- countryFlag?: string;
364
-
365
- /**
366
- * Optional. Called when the flag or dial code is pressed (e.g. to pick a country),
367
- * which then reads as a button with a chevron after the code. Ignored while
368
- * `disabled` or `editable={false}`.
369
- */
370
- onPressLeadingIcon?: () => void;
371
357
  }
372
358
 
373
359
  export type InputRef = {
@@ -13,8 +13,11 @@ import {
13
13
  SearchHeader,
14
14
  } from '../Application';
15
15
  import { DuoGlassBackground } from '../Application/Components/DuoGlassBackground';
16
- import { type HeaderContentLayout } from '../Application/headerLayout';
17
- import { getHeaderMargin } from './utils';
16
+ import {
17
+ getHeaderRowInset,
18
+ type HeaderContentLayout,
19
+ TITLE_CONTAINER_RESET,
20
+ } from '../Application/headerLayout';
18
21
  import { useHeaderBarOptions } from './useHeaderBarOptions';
19
22
  import { HeaderType } from './types';
20
23
 
@@ -242,10 +245,11 @@ export const useScreenHeader = ({
242
245
  // the search field spans the content, clear of the side bar and status bar
243
246
  // clusters; kept as numbers so the setter below stays stable
244
247
  let searchWidth = layout.width - Spacing.M * 2;
245
- let searchLeft = Spacing.M;
248
+ // past back, or at the row start when back is hidden or floats in the side bar
249
+ const rowStartLeft = getHeaderRowInset(layout.width);
250
+ const searchLeft = layout.sideBar ? rowStartLeft : Spacing.M;
246
251
  if (layout.sideBar) {
247
252
  searchWidth = layout.contentWidth - Spacing.M * 2;
248
- searchLeft = Spacing.M - getHeaderMargin(layout.width);
249
253
  }
250
254
  const clearance = layout.statusBarClearance;
251
255
  if (clearance) {
@@ -259,25 +263,18 @@ export const useScreenHeader = ({
259
263
  const setSearchHeader = useCallback(
260
264
  (params: SearchHeaderProps) => {
261
265
  searchHeaderParams.current = params;
266
+ const hasBack = !params?.hiddenBack;
262
267
  const options: StackNavigationOptions = {
263
268
  ...searchOptions,
264
269
  headerRight: undefined,
265
270
  headerTitleContainerStyle: {
271
+ ...TITLE_CONTAINER_RESET,
266
272
  width: searchWidth,
267
273
  maxWidth: searchWidth,
268
- marginLeft: 0,
269
- marginEnd: 0,
270
- marginStart: 0,
271
- marginHorizontal: 0,
272
- marginVertical: 0,
273
- margin: 0,
274
- left: searchLeft,
274
+ left: hasBack ? searchLeft : rowStartLeft,
275
275
  },
276
276
  headerLeft: (props: any) => {
277
- if (params?.hiddenBack) {
278
- return null;
279
- }
280
- return <HeaderLeft {...props} floating />;
277
+ return hasBack && <HeaderLeft {...props} floating />;
281
278
  },
282
279
  headerTitle: () => (
283
280
  <SearchHeader {...params} animatedValue={sharedValue} />
@@ -286,7 +283,14 @@ export const useScreenHeader = ({
286
283
 
287
284
  navigation?.instance?.setOptions(options);
288
285
  },
289
- [navigation?.instance, sharedValue, searchOptions, searchWidth, searchLeft],
286
+ [
287
+ navigation?.instance,
288
+ sharedValue,
289
+ searchOptions,
290
+ searchWidth,
291
+ searchLeft,
292
+ rowStartLeft,
293
+ ],
290
294
  );
291
295
 
292
296
  useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.18",
3
+ "version": "0.169.19-beta.2",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -1,109 +0,0 @@
1
- import React from 'react';
2
- import { StyleSheet, TouchableOpacity, View } from 'react-native';
3
- import { Colors, Spacing, Styles } from '../Consts';
4
- import { Icon } from '../Icon';
5
- import { Image } from '../Image';
6
- import { Text } from '../Text';
7
- import { Typography } from '../Text/types';
8
- import styles from './styles';
9
-
10
- const FLAG_SIZE = 24;
11
- const CHEVRON_SIZE = 16;
12
-
13
- type CountryCodeViewProps = {
14
- countryCode: string;
15
- countryFlag: string;
16
- typography: Typography;
17
- textColor: string;
18
- dividerHeight: number;
19
- componentId: string;
20
- isDisabled: boolean;
21
- onPress?: () => void;
22
- };
23
-
24
- /**
25
- * Flag, dial code and divider ahead of a phone number. Only becomes a button,
26
- * with a chevron after the code, when `onPress` is given, so the default
27
- * render stays a plain view.
28
- */
29
- const CountryCodeView: React.FC<CountryCodeViewProps> = ({
30
- countryCode,
31
- countryFlag,
32
- typography,
33
- textColor,
34
- dividerHeight,
35
- componentId,
36
- isDisabled,
37
- onPress,
38
- }) => {
39
- const content = (
40
- <>
41
- <Image
42
- source={{ uri: countryFlag }}
43
- style={innerStyle.iconFlag}
44
- resizeMode="contain"
45
- accessibilityLabel={`${componentId}|leading-icon`}
46
- />
47
- <View style={{ width: Spacing.XS }} />
48
- <Text typography={typography} color={textColor}>
49
- {countryCode}
50
- </Text>
51
- {/* Kept while disabled (greyed by textColor) so the layout doesn't shift. */}
52
- {onPress && (
53
- <Icon
54
- source="arrow_chevron_down_small"
55
- size={CHEVRON_SIZE}
56
- color={textColor}
57
- style={innerStyle.chevron}
58
- accessibilityLabel={`${componentId}|leading-chevron`}
59
- />
60
- )}
61
- </>
62
- );
63
-
64
- const renderContent = () => {
65
- if (!onPress) {
66
- return content;
67
- }
68
- return (
69
- <TouchableOpacity
70
- style={Styles.row}
71
- onPress={onPress}
72
- disabled={isDisabled}
73
- accessibilityRole="button"
74
- accessibilityLabel={`${componentId}|leading-icon-touch|${countryCode}`}
75
- accessibilityState={{ disabled: isDisabled }}
76
- >
77
- {content}
78
- </TouchableOpacity>
79
- );
80
- };
81
-
82
- return (
83
- <View style={[styles.leadingIconContainer, Styles.row]}>
84
- {renderContent()}
85
- <View
86
- style={[
87
- styles.phoneNumberDivider,
88
- {
89
- height: dividerHeight,
90
- backgroundColor: Colors.black_04,
91
- },
92
- ]}
93
- />
94
- </View>
95
- );
96
- };
97
-
98
- const innerStyle = StyleSheet.create({
99
- iconFlag: {
100
- width: FLAG_SIZE,
101
- height: FLAG_SIZE,
102
- marginHorizontal: Spacing.XXS,
103
- },
104
- chevron: {
105
- marginLeft: Spacing.XS,
106
- },
107
- });
108
-
109
- export { CountryCodeView };