@momo-kits/foundation 0.170.4 → 0.170.5

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.
@@ -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,
@@ -71,11 +70,8 @@ const HeaderExtendHeader: React.FC<{
71
70
  const layout = useScreenLayout();
72
71
  const headerLayout = useHeaderLayout(contentLayout);
73
72
  // 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
- }
73
+ // frame; both already sit `sidePadding` from the edge on large iOS windows
74
+ const frameShift = headerLayout.frameInset - sidePadding;
79
75
 
80
76
  const backLeft = buttonSize + sidePadding + titleGap;
81
77
  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,9 @@ 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
+ // back ends at leftPosition and the measured right cluster counts from the window
50
+ // edge, so the large iOS header row margin is already netted out on both sides
51
+ const rowWidth = layout.width - leftPosition - sidePadding;
54
52
  let searchMaxWidth = rowWidth - headerRightWidth;
55
53
  if (layout.sideBar) {
56
54
  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) {
@@ -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,
@@ -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 = {
@@ -1,12 +1,14 @@
1
1
  import React from 'react';
2
2
  import { StyleSheet, TouchableOpacity, View } from 'react-native';
3
3
  import { Colors, Spacing, Styles } from '../Consts';
4
+ import { Icon } from '../Icon';
4
5
  import { Image } from '../Image';
5
6
  import { Text } from '../Text';
6
7
  import { Typography } from '../Text/types';
7
8
  import styles from './styles';
8
9
 
9
10
  const FLAG_SIZE = 24;
11
+ const CHEVRON_SIZE = 16;
10
12
 
11
13
  type CountryCodeViewProps = {
12
14
  countryCode: string;
@@ -20,8 +22,9 @@ type CountryCodeViewProps = {
20
22
  };
21
23
 
22
24
  /**
23
- * Flag, dial code and divider ahead of a phone number. Only becomes a button
24
- * when `onPress` is given, so the default render stays a plain view.
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.
25
28
  */
26
29
  const CountryCodeView: React.FC<CountryCodeViewProps> = ({
27
30
  countryCode,
@@ -45,6 +48,16 @@ const CountryCodeView: React.FC<CountryCodeViewProps> = ({
45
48
  <Text typography={typography} color={textColor}>
46
49
  {countryCode}
47
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
+ )}
48
61
  </>
49
62
  );
50
63
 
@@ -88,6 +101,9 @@ const innerStyle = StyleSheet.create({
88
101
  height: FLAG_SIZE,
89
102
  marginHorizontal: Spacing.XXS,
90
103
  },
104
+ chevron: {
105
+ marginLeft: Spacing.XS,
106
+ },
91
107
  });
92
108
 
93
109
  export { CountryCodeView };
package/Input/index.tsx CHANGED
@@ -364,7 +364,8 @@ export interface InputPhoneNumberProps extends InputProps {
364
364
 
365
365
  /**
366
366
  * Optional. Called when the flag or dial code is pressed (e.g. to pick a country),
367
- * which then reads as a button. Ignored while `disabled` or `editable={false}`.
367
+ * which then reads as a button with a chevron after the code. Ignored while
368
+ * `disabled` or `editable={false}`.
368
369
  */
369
370
  onPressLeadingIcon?: () => void;
370
371
  }
@@ -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.170.4",
3
+ "version": "0.170.5",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},