@momo-kits/foundation 0.169.16-beta.2 → 0.169.16-beta.4

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.
@@ -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
  );
@@ -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) {
@@ -98,6 +98,14 @@ const getHeaderLayout = ({
98
98
  };
99
99
  };
100
100
 
101
+ /**
102
+ * Inset from the React Navigation header row that puts an item `sidePadding` from
103
+ * the window edge: large iOS windows already inset that row by `getHeaderMargin`.
104
+ */
105
+ const getHeaderRowInset = (width: number) => {
106
+ return HeaderBarMetrics.sidePadding - getHeaderMargin(width);
107
+ };
108
+
101
109
  /**
102
110
  * Widest a title can be between back and the right cluster of the header row.
103
111
  */
@@ -135,25 +143,23 @@ const useHeaderFrameOptions = (
135
143
  contentLayout?: HeaderContentLayout,
136
144
  ): StackNavigationOptions | undefined => {
137
145
  const layout = useHeaderLayout(contentLayout);
138
- const { width } = useWindowDimensions();
139
146
  const isDuo = isIPhoneDuo();
140
147
  return useMemo(() => {
141
148
  if (!IS_STRETCH_FRAME_ENABLED || contentLayout !== 'stretch' || isDuo) {
142
149
  return undefined;
143
150
  }
144
- // the header content row already sits this far in on large iOS windows
151
+ // back and toolkit already net out the header row margin of large iOS windows
145
152
  const shift = layout.frameInset - layout.sidePadding;
146
- const containerShift = Math.max(0, shift - getHeaderMargin(width));
147
153
  return {
148
- headerLeftContainerStyle: { paddingLeft: containerShift },
149
- headerRightContainerStyle: { paddingRight: containerShift },
154
+ headerLeftContainerStyle: { paddingLeft: shift },
155
+ headerRightContainerStyle: { paddingRight: shift },
150
156
  headerTitleContainerStyle: {
151
157
  ...TITLE_CONTAINER_RESET,
152
158
  left: layout.titleGap,
153
159
  maxWidth: getTitleBudget(layout),
154
160
  },
155
161
  };
156
- }, [contentLayout, isDuo, layout, width]);
162
+ }, [contentLayout, isDuo, layout]);
157
163
  };
158
164
 
159
165
  export type { HeaderContentLayout, HeaderLayout };
@@ -163,6 +169,7 @@ export {
163
169
  HEADER_FRAME_MAX_WIDTH,
164
170
  TITLE_CONTAINER_RESET,
165
171
  getHeaderLayout,
172
+ getHeaderRowInset,
166
173
  getTitleBudget,
167
174
  useHeaderLayout,
168
175
  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 = {
@@ -14,11 +14,12 @@ import {
14
14
  } from '../Application';
15
15
  import { DuoGlassBackground } from '../Application/Components/DuoGlassBackground';
16
16
  import {
17
+ getHeaderRowInset,
17
18
  type HeaderContentLayout,
19
+ TITLE_CONTAINER_RESET,
18
20
  useHeaderFrameOptions,
19
21
  useHeaderLayout,
20
22
  } from '../Application/headerLayout';
21
- import { getHeaderMargin } from './utils';
22
23
  import { ANIMATED_BANNER_HEIGHT } from './screenTypes';
23
24
  import { HeaderType } from './types';
24
25
 
@@ -247,10 +248,11 @@ export const useScreenHeader = ({
247
248
  // the search field spans the content (or the stretch frame), clear of the side bar
248
249
  // and status bar clusters; kept as numbers so the setter below stays stable
249
250
  let searchWidth = headerLayout.frameWidth;
250
- let searchLeft = Spacing.M;
251
+ // past back, or at the row start when back is hidden or floats in the side bar
252
+ const rowStartLeft = getHeaderRowInset(layout.width);
253
+ const searchLeft = layout.sideBar ? rowStartLeft : Spacing.M;
251
254
  if (layout.sideBar) {
252
255
  searchWidth = layout.contentWidth - Spacing.M * 2;
253
- searchLeft = Spacing.M - getHeaderMargin(layout.width);
254
256
  }
255
257
  const clearance = layout.statusBarClearance;
256
258
  if (clearance) {
@@ -264,25 +266,18 @@ export const useScreenHeader = ({
264
266
  const setSearchHeader = useCallback(
265
267
  (params: SearchHeaderProps) => {
266
268
  searchHeaderParams.current = params;
269
+ const hasBack = !params?.hiddenBack;
267
270
  const options: StackNavigationOptions = {
268
271
  ...frameOptions,
269
272
  headerRight: undefined,
270
273
  headerTitleContainerStyle: {
274
+ ...TITLE_CONTAINER_RESET,
271
275
  width: searchWidth,
272
276
  maxWidth: searchWidth,
273
- marginLeft: 0,
274
- marginEnd: 0,
275
- marginStart: 0,
276
- marginHorizontal: 0,
277
- marginVertical: 0,
278
- margin: 0,
279
- left: searchLeft,
277
+ left: hasBack ? searchLeft : rowStartLeft,
280
278
  },
281
279
  headerLeft: (props: any) => {
282
- if (params?.hiddenBack) {
283
- return null;
284
- }
285
- return <HeaderLeft {...props} floating />;
280
+ return hasBack && <HeaderLeft {...props} floating />;
286
281
  },
287
282
  headerTitle: () => (
288
283
  <SearchHeader {...params} animatedValue={sharedValue} />
@@ -291,7 +286,14 @@ export const useScreenHeader = ({
291
286
 
292
287
  navigation?.instance?.setOptions(options);
293
288
  },
294
- [navigation?.instance, sharedValue, frameOptions, searchWidth, searchLeft],
289
+ [
290
+ navigation?.instance,
291
+ sharedValue,
292
+ frameOptions,
293
+ searchWidth,
294
+ searchLeft,
295
+ rowStartLeft,
296
+ ],
295
297
  );
296
298
 
297
299
  useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.16-beta.2",
3
+ "version": "0.169.16-beta.4",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},