@momo-kits/foundation 0.169.7-beta.5 → 0.169.7-beta.6

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.
@@ -5,9 +5,12 @@ import { StyleSheet, TouchableOpacity, View, ViewStyle } from 'react-native';
5
5
  import { Colors, Spacing } from '../../Consts';
6
6
  import { Icon } from '../../Icon';
7
7
  import { BadgeDot } from '../../Badge';
8
+ import { HeaderBarMetrics } from '../headerLayout';
9
+
10
+ const { buttonSize, iconSize } = HeaderBarMetrics;
8
11
 
9
12
  /**
10
- * Round 28pt icon button of the header (back, shortcut) with an optional badge
13
+ * Round 32pt icon button of the header (back, shortcut) with an optional badge
11
14
  * dot; switches to a dark fill under a white tint so the icon stays readable.
12
15
  */
13
16
  const NavigationButton: React.FC<NavigationButtonProps> = ({
@@ -35,7 +38,7 @@ const NavigationButton: React.FC<NavigationButtonProps> = ({
35
38
  <Icon
36
39
  source={icon}
37
40
  color={tintColor ?? theme.colors.text.default}
38
- size={20}
41
+ size={iconSize}
39
42
  />
40
43
  </TouchableOpacity>
41
44
  {showBadge && <BadgeDot size={'small'} style={styles.badgeDot} />}
@@ -45,12 +48,12 @@ const NavigationButton: React.FC<NavigationButtonProps> = ({
45
48
 
46
49
  const styles = StyleSheet.create({
47
50
  container: {
48
- width: 28,
51
+ width: buttonSize,
49
52
  },
50
53
  navigationButton: {
51
- height: 28,
52
- width: 28,
53
- borderRadius: 14,
54
+ height: buttonSize,
55
+ width: buttonSize,
56
+ borderRadius: buttonSize / 2,
54
57
  justifyContent: 'center',
55
58
  alignItems: 'center',
56
59
  backgroundColor: Colors.black_01 + '99',
@@ -1,5 +1,5 @@
1
1
  import { Colors, Radius, Spacing, Styles } from '../../Consts';
2
- import { InputRef, InputSearch } from '../../Input';
2
+ import { InputRef, InputSearch, type InputSearchProps } 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';
@@ -9,6 +9,13 @@ import { Text } from '../../Text';
9
9
  import { useNormalizedSharedValue } from '../hooks';
10
10
  import { useScreenLayout } from '../../Layout';
11
11
  import { DuoMetrics } from '../../Layout/utils';
12
+ import { HeaderBarMetrics } from '../headerLayout';
13
+
14
+ const { buttonSize, pillWidth, sidePadding, titleGap } = HeaderBarMetrics;
15
+ // help center | home pill and the bar padding right of it
16
+ const TOOLKIT_WIDTH = pillWidth + sidePadding;
17
+ // the iPhone Duo side bar and status bar row keep their right header width
18
+ const DUO_TOOLKIT_WIDTH = 73;
12
19
 
13
20
  /**
14
21
  * Header search bar whose fill turns from surface to default once scrolled, with
@@ -29,14 +36,25 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
29
36
  const context = useContext<any>(MiniAppContext);
30
37
  const layout = useScreenLayout();
31
38
  // the iPhone Duo status bar row keeps a side bar sized back button
32
- const BACK_WIDTH = layout.statusBarClearance ? DuoMetrics.controlSize : 28;
39
+ let backWidth = buttonSize;
40
+ if (layout.statusBarClearance) {
41
+ backWidth = DuoMetrics.controlSize;
42
+ }
43
+ let defaultRightWidth = TOOLKIT_WIDTH;
44
+ let searchSize: InputSearchProps['size'] = 'header';
45
+ if (layout.sideBar || layout.statusBarClearance) {
46
+ defaultRightWidth = DUO_TOOLKIT_WIDTH;
47
+ searchSize = 'default';
48
+ }
33
49
 
34
50
  const sharedValue = useNormalizedSharedValue(animatedValue);
35
- const leftPosition = props?.leftPosition ?? BACK_WIDTH + 20;
36
- const headerRightWidth = props?.headerRightWidth ?? 73;
51
+ const defaultLeft = backWidth + sidePadding + titleGap;
52
+ const leftPosition = props?.leftPosition ?? defaultLeft;
53
+ const headerRightWidth = props?.headerRightWidth ?? defaultRightWidth;
37
54
 
38
55
  // iPhone Duo side bar holds back: the search shares the content width with the buttons only
39
- let searchMaxWidth = layout.width - leftPosition - 12 - headerRightWidth;
56
+ const rowWidth = layout.width - leftPosition - sidePadding;
57
+ let searchMaxWidth = rowWidth - headerRightWidth;
40
58
  if (layout.sideBar) {
41
59
  searchMaxWidth = layout.contentWidth - Spacing.M * 2 - headerRightWidth;
42
60
  }
@@ -105,6 +123,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
105
123
  <InputSearch
106
124
  ref={ref}
107
125
  {...props}
126
+ size={searchSize}
108
127
  backgroundColor={'transparent'}
109
128
  showButtonText={false}
110
129
  />
@@ -8,6 +8,7 @@ import { SwipeBackHaptic } from './Components/SwipeBackHaptic';
8
8
  import { useAppState } from './hooks';
9
9
  import { createScreenTracking } from './StackScreen.tracking';
10
10
  import { TooltipPortalHost, TooltipPortalProvider } from './TooltipPortal';
11
+ import { useHeaderFrameOptions } from './headerLayout';
11
12
 
12
13
  const runAfterInteractions = InteractionManager.runAfterInteractions;
13
14
 
@@ -51,6 +52,7 @@ const StackScreen: React.FC<any> = props => {
51
52
  const navigation = useRef(new Navigation(props.navigation, context)).current;
52
53
  const heightHeader = useHeaderHeight();
53
54
  const { isBackgroundToForeground } = useAppState();
55
+ const headerFrameOptions = useHeaderFrameOptions(options?.contentLayout);
54
56
 
55
57
  const data = {
56
58
  ...initialParams,
@@ -69,6 +71,13 @@ const StackScreen: React.FC<any> = props => {
69
71
  }
70
72
  }, [navigation, options]);
71
73
 
74
+ // re-applied on fold, unfold and rotation, apart from the other options
75
+ useLayoutEffect(() => {
76
+ if (headerFrameOptions) {
77
+ navigation.instance.setOptions(headerFrameOptions);
78
+ }
79
+ }, [navigation, headerFrameOptions]);
80
+
72
81
  useEffect(() => {
73
82
  let focusScreen: any;
74
83
  let onFocusApp: any;
@@ -0,0 +1,158 @@
1
+ import { useMemo } from 'react';
2
+ import { useWindowDimensions, type ViewStyle } from 'react-native';
3
+ import type { StackNavigationOptions } from '@react-navigation/stack';
4
+ import { Spacing } from '../Consts';
5
+ import { getHeaderMargin } from '../Layout/utils';
6
+ import { FOLDABLE_MIN_WIDTH } from './modalLayout';
7
+ import { isIPhoneDuo } from './utils';
8
+
9
+ // Top navigation spec, shared with the Compose / SwiftUI kits
10
+ const HEADER_FRAME_MAX_WIDTH = 600;
11
+
12
+ /**
13
+ * Top navigation geometry on every device
14
+ * - buttonSize / iconSize: round back and shortcut buttons, icons inside them and the pill
15
+ * - pillWidth / pillHeight: help center | home capsule
16
+ * - clusterWidth: shortcut, gap and pill on the right of the bar
17
+ * - searchHeight: search field inside the header
18
+ * - titleGap: space between back and the title, and the title and the right cluster
19
+ * - sidePadding: bar edge to back and to the right cluster
20
+ * - gradientHeight: header gradient, kept at the phone height on wide windows
21
+ * - bannerWidth: animated banner image, kept at the phone width on wide windows
22
+ */
23
+ const HeaderBarMetrics = {
24
+ buttonSize: 32,
25
+ iconSize: 20,
26
+ pillWidth: 72,
27
+ pillHeight: 32,
28
+ clusterWidth: 112,
29
+ searchHeight: 32,
30
+ titleGap: Spacing.S,
31
+ sidePadding: Spacing.M,
32
+ gradientHeight: 154,
33
+ bannerWidth: 375,
34
+ };
35
+
36
+ /**
37
+ * `grid` keeps the header row at the bar edges, `stretch` centers it in a 600pt
38
+ * frame on wide windows. Background and status bar always span the window.
39
+ */
40
+ type HeaderContentLayout = 'grid' | 'stretch';
41
+
42
+ type HeaderLayout = typeof HeaderBarMetrics & {
43
+ /**
44
+ * Window whose short side is at least 600 (Galaxy Z Fold / Pixel Fold inner
45
+ * display, tablets), iPhone Duo excluded. Phones, landscape included, are not.
46
+ */
47
+ isWide: boolean;
48
+ /**
49
+ * Window edge to back and to the right cluster: `sidePadding`, or centering the
50
+ * row in the 600pt frame with `stretch` on a wide window.
51
+ */
52
+ frameInset: number;
53
+ /**
54
+ * Header row width between the two `frameInset`s.
55
+ */
56
+ frameWidth: number;
57
+ };
58
+
59
+ type HeaderLayoutInput = {
60
+ width: number;
61
+ height: number;
62
+ isDuo: boolean;
63
+ contentLayout?: HeaderContentLayout;
64
+ };
65
+
66
+ /**
67
+ * Header geometry for a window, pure so it can be tested without a device.
68
+ */
69
+ const getHeaderLayout = ({
70
+ width,
71
+ height,
72
+ isDuo,
73
+ contentLayout = 'grid',
74
+ }: HeaderLayoutInput): HeaderLayout => {
75
+ const { sidePadding } = HeaderBarMetrics;
76
+ const isWide = !isDuo && Math.min(width, height) >= FOLDABLE_MIN_WIDTH;
77
+ let frameInset = sidePadding;
78
+ if (isWide && contentLayout === 'stretch') {
79
+ const centered = (width - HEADER_FRAME_MAX_WIDTH) / 2;
80
+ frameInset = Math.max(sidePadding, centered);
81
+ }
82
+ return {
83
+ ...HeaderBarMetrics,
84
+ isWide,
85
+ frameInset,
86
+ frameWidth: width - frameInset * 2,
87
+ };
88
+ };
89
+
90
+ /**
91
+ * Widest a title can be between back and the right cluster of the header row.
92
+ */
93
+ const getTitleBudget = (layout: HeaderLayout) => {
94
+ const { buttonSize, titleGap, clusterWidth } = layout;
95
+ return layout.frameWidth - buttonSize - titleGap * 2 - clusterWidth;
96
+ };
97
+
98
+ /**
99
+ * Header geometry for the current window; follows fold, unfold and rotation.
100
+ */
101
+ const useHeaderLayout = (contentLayout?: HeaderContentLayout): HeaderLayout => {
102
+ const { width, height } = useWindowDimensions();
103
+ const isDuo = isIPhoneDuo();
104
+ return useMemo(() => {
105
+ return getHeaderLayout({ width, height, isDuo, contentLayout });
106
+ }, [width, height, isDuo, contentLayout]);
107
+ };
108
+
109
+ const TITLE_CONTAINER_RESET: ViewStyle = {
110
+ marginLeft: 0,
111
+ marginEnd: 0,
112
+ marginStart: 0,
113
+ marginHorizontal: 0,
114
+ marginVertical: 0,
115
+ margin: 0,
116
+ };
117
+
118
+ /**
119
+ * React Navigation container styles that keep back, title and the right cluster
120
+ * in the `stretch` frame. `undefined` for `grid`, and on iPhone Duo, which keeps
121
+ * its own header row.
122
+ */
123
+ const useHeaderFrameOptions = (
124
+ contentLayout?: HeaderContentLayout,
125
+ ): StackNavigationOptions | undefined => {
126
+ const layout = useHeaderLayout(contentLayout);
127
+ const { width } = useWindowDimensions();
128
+ const isDuo = isIPhoneDuo();
129
+ return useMemo(() => {
130
+ if (contentLayout !== 'stretch' || isDuo) {
131
+ return undefined;
132
+ }
133
+ // the header content row already sits this far in on large iOS windows
134
+ const shift = layout.frameInset - layout.sidePadding;
135
+ const containerShift = Math.max(0, shift - getHeaderMargin(width));
136
+ return {
137
+ headerLeftContainerStyle: { paddingLeft: containerShift },
138
+ headerRightContainerStyle: { paddingRight: containerShift },
139
+ headerTitleContainerStyle: {
140
+ ...TITLE_CONTAINER_RESET,
141
+ left: layout.titleGap,
142
+ maxWidth: getTitleBudget(layout),
143
+ },
144
+ };
145
+ }, [contentLayout, isDuo, layout, width]);
146
+ };
147
+
148
+ export type { HeaderContentLayout, HeaderLayout };
149
+
150
+ export {
151
+ HeaderBarMetrics,
152
+ HEADER_FRAME_MAX_WIDTH,
153
+ TITLE_CONTAINER_RESET,
154
+ getHeaderLayout,
155
+ getTitleBudget,
156
+ useHeaderLayout,
157
+ useHeaderFrameOptions,
158
+ };
@@ -26,6 +26,13 @@ import {
26
26
  type ModalLayout,
27
27
  type ModalRect,
28
28
  } from './modalLayout';
29
+ import {
30
+ HeaderBarMetrics,
31
+ getHeaderLayout,
32
+ useHeaderLayout,
33
+ type HeaderContentLayout,
34
+ type HeaderLayout,
35
+ } from './headerLayout';
29
36
 
30
37
  export {
31
38
  NavigationContainer,
@@ -41,6 +48,9 @@ export {
41
48
  useTooltipPortal,
42
49
  getModalLayout,
43
50
  useModalLayout,
51
+ HeaderBarMetrics,
52
+ getHeaderLayout,
53
+ useHeaderLayout,
44
54
  };
45
55
 
46
- export type { ModalLayout, ModalRect };
56
+ export type { ModalLayout, ModalRect, HeaderContentLayout, HeaderLayout };
@@ -8,11 +8,12 @@ import {
8
8
  TransitionPresets,
9
9
  } from '@react-navigation/stack';
10
10
  import type { SharedValue } from 'react-native-reanimated';
11
- import { Colors, Spacing } from '../Consts';
11
+ import { Colors } from '../Consts';
12
12
  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
17
  import type { HeaderTitleProps, NavigationOptions } from './types';
17
18
 
18
19
  const CARD_SHADOW_OPACITY = 0.3;
@@ -55,13 +56,8 @@ const getStackOptions = (): StackNavigationOptions => {
55
56
  headerTitleAlign: 'left',
56
57
  headerTitle: props => <HeaderTitle {...props} />,
57
58
  headerTitleContainerStyle: {
58
- marginLeft: 0,
59
- marginEnd: 0,
60
- marginStart: 0,
61
- marginHorizontal: 0,
62
- marginVertical: 0,
63
- margin: 0,
64
- left: Spacing.S,
59
+ ...TITLE_CONTAINER_RESET,
60
+ left: HeaderBarMetrics.titleGap,
65
61
  },
66
62
  headerBackground: (props: any) => <HeaderBackground {...props} />,
67
63
  headerLeft: (props: any) => <HeaderLeft {...props} floating />,
@@ -172,13 +168,8 @@ const getOptions = (
172
168
  if (params.hiddenBack) {
173
169
  headerLeft = null;
174
170
  options.headerTitleContainerStyle = {
175
- marginLeft: 0,
176
- marginEnd: 0,
177
- marginStart: 0,
178
- marginHorizontal: 0,
179
- marginVertical: 0,
180
- margin: 0,
181
- left: Spacing.M,
171
+ ...TITLE_CONTAINER_RESET,
172
+ left: HeaderBarMetrics.sidePadding,
182
173
  };
183
174
  }
184
175
  options = {
@@ -98,6 +98,11 @@ export interface HeaderAnimatedProps extends ViewProps {
98
98
  image: string;
99
99
  useScale?: boolean;
100
100
  aspectRatio?: '16/9' | '3/2' | '1/1';
101
+ /**
102
+ * Optional. On wide windows the image keeps its phone width, centered; this
103
+ * color fills the sides and fades to transparent downward. No fill when unset.
104
+ */
105
+ bannerBackgroundColor?: string;
101
106
  }
102
107
 
103
108
  export type AnimatedHeader = {
@@ -109,8 +114,8 @@ export type AnimatedHeader = {
109
114
  export interface SearchHeaderProps extends InputSearchProps {
110
115
  ref?: React.RefObject<InputRef>;
111
116
  animatedValue?: Animated.Value | SharedValue<number>;
112
- headerRightWidth?: 0 | 74 | 110 | number;
113
- leftPosition?: 12 | 48 | number;
117
+ headerRightWidth?: 0 | 84 | 124 | number;
118
+ leftPosition?: 12 | 52 | number;
114
119
  renderButtons?: () => ReactNode;
115
120
  hiddenBack?: boolean;
116
121
  }
@@ -36,6 +36,7 @@ export type BottomTabProps = {
36
36
  };
37
37
 
38
38
  export type FloatingButtonProps = {
39
+ container?: React.ReactNode;
39
40
  icon: string | React.ReactNode;
40
41
  label: string;
41
42
  onPress: () => void;
@@ -9,6 +9,7 @@ import type {
9
9
  OnBoarding,
10
10
  } from './types.header';
11
11
  import type { LocalizeProps, Theme } from './types.theme';
12
+ import type { HeaderContentLayout } from './headerLayout';
12
13
 
13
14
  export * from './types.theme';
14
15
  export * from './types.header';
@@ -128,4 +129,10 @@ export interface NavigationOptions
128
129
  hiddenBack?: boolean;
129
130
  headerTitle?: HeaderTitleProps | string;
130
131
  headerRight?: OnBoarding | HeaderRightToolkit | any;
132
+ /**
133
+ * Optional. `stretch` centers back, title and the right cluster in a 600pt
134
+ * frame on wide windows (foldable inner display, tablet); the background stays
135
+ * full width. Defaults to `grid`, the header row at the window edges.
136
+ */
137
+ contentLayout?: HeaderContentLayout;
131
138
  }
@@ -13,6 +13,7 @@ import {
13
13
  View,
14
14
  } from 'react-native';
15
15
  import { useComponentId } from '../Application';
16
+ import { HeaderBarMetrics } from '../Application/headerLayout';
16
17
  import {
17
18
  ApplicationContext,
18
19
  ComponentContext,
@@ -26,6 +27,8 @@ import styles from './styles';
26
27
  import { Styles } from '../Consts';
27
28
  import SystemTextInput from './SystemTextInput';
28
29
 
30
+ const SEARCH_ICON_SIZE = 24;
31
+
29
32
  /**
30
33
  * Search field with search icon, clear icon, optional trailing icon and a
31
34
  * cancel button; with `typingData` it shows an animated placeholder instead.
@@ -49,6 +52,7 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
49
52
  backgroundColor,
50
53
  onPress,
51
54
  typingData,
55
+ size = 'default',
52
56
  ...props
53
57
  },
54
58
  ref,
@@ -59,6 +63,13 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
59
63
  const searchFontFamily = exportFontFamily('regular');
60
64
 
61
65
  const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
66
+ const isHeaderSize = size === 'header';
67
+ const inputHeightStyle = isHeaderSize && {
68
+ height: HeaderBarMetrics.searchHeight,
69
+ };
70
+ const searchIconSize = isHeaderSize
71
+ ? HeaderBarMetrics.iconSize
72
+ : SEARCH_ICON_SIZE;
62
73
 
63
74
  const [focused, setFocused] = useState(false);
64
75
  const [internalText, setInternalText] = useState(defaultValue || '');
@@ -114,7 +125,11 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
114
125
  if (typingData && typingData?.length > 0) {
115
126
  return (
116
127
  <TouchableOpacity
117
- style={[styles.searchInput, styles.searchInputTyping]}
128
+ style={[
129
+ styles.searchInput,
130
+ styles.searchInputTyping,
131
+ inputHeightStyle,
132
+ ]}
118
133
  onPress={onPress}
119
134
  activeOpacity={onPress ? 0.6 : 1}
120
135
  >
@@ -132,6 +147,7 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
132
147
  ref={inputRef}
133
148
  style={[
134
149
  styles.searchInput,
150
+ inputHeightStyle,
135
151
  {
136
152
  fontSize: scaledFontSize,
137
153
  color: theme.colors.text.default,
@@ -225,7 +241,7 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
225
241
  >
226
242
  <Icon
227
243
  source={'navigation_search'}
228
- size={24}
244
+ size={searchIconSize}
229
245
  color={theme.colors.text.hint}
230
246
  />
231
247
  {renderInputView()}
package/Input/index.tsx CHANGED
@@ -194,6 +194,12 @@ export interface InputSearchProps extends TextInputProps {
194
194
  */
195
195
  typingData?: string[];
196
196
 
197
+ /**
198
+ * Optional. `header` is the 32pt field with a 20pt search icon that sits in the
199
+ * navigation header. Defaults to `default`, the 36pt field for content.
200
+ */
201
+ size?: 'default' | 'header';
202
+
197
203
  /**
198
204
  * Optional. Called when the field is pressed while showing `typingData`.
199
205
  */
@@ -367,4 +373,4 @@ export {
367
373
  InputPhoneNumber,
368
374
  };
369
375
 
370
- export {checkValidPhoneNumber};
376
+ export { checkValidPhoneNumber };
package/Layout/Screen.tsx CHANGED
@@ -67,6 +67,7 @@ const Screen = forwardRef(
67
67
  headerBackground,
68
68
  gradientColor,
69
69
  trackingParams,
70
+ contentLayout,
70
71
  }: ScreenProps,
71
72
  ref: any,
72
73
  ) => {
@@ -144,6 +145,7 @@ const Screen = forwardRef(
144
145
  gradientColor,
145
146
  headerBackground,
146
147
  layoutOffset,
148
+ contentLayout,
147
149
  });
148
150
 
149
151
  // mutates the content node so callers keep its methods plus the header setters
@@ -223,6 +225,7 @@ const Screen = forwardRef(
223
225
  useShadowHeader={useShadowHeader}
224
226
  gradientColor={gradientColor}
225
227
  headerBackground={headerBackground}
228
+ contentLayout={contentLayout}
226
229
  />
227
230
  );
228
231
  };