@momo-kits/foundation 0.169.17 → 0.169.18-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.
@@ -1,63 +1,308 @@
1
- import React, { ReactNode } from 'react';
2
- import { View } from 'react-native';
1
+ import React, { ReactNode, useCallback, useContext, useState } from 'react';
2
+ import { LayoutChangeEvent, StyleProp, View, ViewStyle } from 'react-native';
3
+ import { isFoldableWindow } from '../Application/modalLayout';
4
+ import { ApplicationContext, MiniAppContext } from '../Context';
3
5
  import { Spacing } from '../Consts';
6
+ import { ScreenLayout } from './layoutTypes';
7
+ import { ScreenFooterSeparator, ScreenFooterStyle } from './types';
4
8
  import Section from './Section';
5
9
  import styles from './styles';
6
10
 
11
+ // Foldable footer spec, shared with the Compose / SwiftUI kits
12
+ const FOOTER_MAX_WIDTH = 600;
13
+ const FOOTER_WIDE_MAX_WIDTH = 800;
14
+ const FOOTER_WIDE_WINDOW_MIN_WIDTH = 800;
15
+ const FOOTER_BORDER_WIDTH = 1;
16
+
17
+ type FooterKind = 'phone' | 'anchored' | 'sheet';
18
+
19
+ type HorizontalInsets = { left: number; right: number };
20
+
21
+ type FooterGeometry = {
22
+ kind: FooterKind;
23
+ /**
24
+ * Sheet width or anchored content area, both before the 12pt row margins.
25
+ */
26
+ width: number;
27
+ /**
28
+ * Footer margins from the window edges: only the phone bar keeps clear of the
29
+ * iPhone Duo side column, the foldable bar and sheet are laid on the window.
30
+ */
31
+ barMargin: HorizontalInsets;
32
+ };
33
+
34
+ type DesignSystemContext = {
35
+ designSystemConfig?: {
36
+ config?: { footerStyle?: unknown; footerSeparator?: unknown };
37
+ };
38
+ };
39
+
40
+ type FooterGeometryInput = {
41
+ width: number;
42
+ height: number;
43
+ contentWidth: number;
44
+ insetLeft: number;
45
+ insetRight: number;
46
+ footerStyle: ScreenFooterStyle;
47
+ hasImageBackground: boolean;
48
+ };
49
+
50
+ type FooterLayout = FooterGeometry & {
51
+ /**
52
+ * `true` for the anchored bar without an image background, which draws a separator.
53
+ */
54
+ hasSeparator: boolean;
55
+ /**
56
+ * `false` on a foldable with an image background, so the screen's image shows through.
57
+ */
58
+ hasSurface: boolean;
59
+ /**
60
+ * Height the sheet overlaps the body by; 0 while the footer sits below the body.
61
+ */
62
+ overlap: number;
63
+ handleLayout: (event: LayoutChangeEvent) => void;
64
+ };
65
+
7
66
  type ScreenFooterProps = {
8
67
  footer: ReactNode;
9
68
  marginFooter: boolean;
10
- insetLeft: number;
11
- insetRight: number;
12
- hasContentInset: boolean;
69
+ layout: FooterLayout;
70
+ separator?: ScreenFooterSeparator;
13
71
  isTab: boolean;
14
72
  duoTabInset: number;
15
73
  bottomInset: number;
16
- surfaceColor: string;
17
74
  };
18
75
 
76
+ const NO_INSETS: HorizontalInsets = { left: 0, right: 0 };
77
+
19
78
  /**
20
- * Screen footer on the surface color with a top shadow, padded above the home indicator,
21
- * or above the floating tab bar on a tab screen.
79
+ * The screen prop wins over the host's design system config; anything else is `anchored`.
22
80
  */
23
- export const ScreenFooter = ({
24
- footer,
25
- marginFooter,
81
+ const getFooterStyle = (
82
+ footerStyle?: ScreenFooterStyle,
83
+ configured?: unknown,
84
+ ): ScreenFooterStyle => {
85
+ if ((footerStyle ?? configured) === 'sheet') {
86
+ return 'sheet';
87
+ }
88
+ return 'anchored';
89
+ };
90
+
91
+ /**
92
+ * The screen prop wins over the host's design system config; anything else is `border`.
93
+ */
94
+ const getFooterSeparator = (
95
+ separator?: ScreenFooterSeparator,
96
+ configured?: unknown,
97
+ ): ScreenFooterSeparator => {
98
+ if ((separator ?? configured) === 'shadow') {
99
+ return 'shadow';
100
+ }
101
+ return 'border';
102
+ };
103
+
104
+ /**
105
+ * Footer kind, width and side insets for a window, pure so it can be tested without a
106
+ * device. Phones, iPhone Duo outer included, keep the shadowed bar.
107
+ */
108
+ const getFooterGeometry = ({
109
+ width,
110
+ height,
111
+ contentWidth,
26
112
  insetLeft,
27
113
  insetRight,
28
- hasContentInset,
114
+ footerStyle,
115
+ hasImageBackground,
116
+ }: FooterGeometryInput): FooterGeometry => {
117
+ const contentInsets = { left: insetLeft, right: insetRight };
118
+ if (!isFoldableWindow(width, height)) {
119
+ return {
120
+ kind: 'phone',
121
+ width: contentWidth,
122
+ barMargin: contentInsets,
123
+ };
124
+ }
125
+
126
+ let maxWidth = FOOTER_MAX_WIDTH;
127
+ if (width >= FOOTER_WIDE_WINDOW_MIN_WIDTH) {
128
+ maxWidth = FOOTER_WIDE_MAX_WIDTH;
129
+ }
130
+ const footerWidth = Math.min(contentWidth - Spacing.M * 2, maxWidth);
131
+ // an image background spans the window, so it never sits in a sheet
132
+ if (footerStyle === 'sheet' && !hasImageBackground) {
133
+ // Figma centers the sheet on the window, side column included
134
+ return {
135
+ kind: 'sheet',
136
+ width: footerWidth,
137
+ barMargin: NO_INSETS,
138
+ };
139
+ }
140
+ // Figma centers the anchored content on the window too, side column included
141
+ return { kind: 'anchored', width: footerWidth, barMargin: NO_INSETS };
142
+ };
143
+
144
+ /**
145
+ * Cap of the footer grid row: the foldable area minus the 12pt margins it keeps
146
+ * inside; `undefined` on a phone, where the row spans the content.
147
+ */
148
+ const getFooterRowWidth = (
149
+ geometry: FooterGeometry,
150
+ hasMargin: boolean,
151
+ ): number | undefined => {
152
+ if (geometry.kind === 'phone') {
153
+ return undefined;
154
+ }
155
+ let margin = 0;
156
+ if (hasMargin) {
157
+ margin = Spacing.M;
158
+ }
159
+ return geometry.width - margin * 2;
160
+ };
161
+
162
+ /**
163
+ * Top edge of the anchored bar: a 1pt border line or the phone footer shadow.
164
+ */
165
+ const getSeparatorStyle = (
166
+ separator: ScreenFooterSeparator,
167
+ borderColor: string,
168
+ ): StyleProp<ViewStyle> => {
169
+ if (separator === 'shadow') {
170
+ return styles.shadow;
171
+ }
172
+ return { borderTopWidth: FOOTER_BORDER_WIDTH, borderTopColor: borderColor };
173
+ };
174
+
175
+ /**
176
+ * Footer layout for the screen layout. A sheet overlaps the body, so its measured
177
+ * height comes back as `overlap` for the body to pad its end by.
178
+ */
179
+ const useFooterLayout = (
180
+ layout: ScreenLayout,
181
+ footerStyle?: ScreenFooterStyle,
182
+ hasImageBackground = false,
183
+ ): FooterLayout => {
184
+ const context: DesignSystemContext | undefined = useContext(MiniAppContext);
185
+ const [height, setHeight] = useState(0);
186
+ const handleLayout = useCallback((event: LayoutChangeEvent) => {
187
+ setHeight(event.nativeEvent.layout.height);
188
+ }, []);
189
+
190
+ const configured = context?.designSystemConfig?.config?.footerStyle;
191
+ const geometry = getFooterGeometry({
192
+ width: layout.width,
193
+ height: layout.height,
194
+ contentWidth: layout.contentWidth,
195
+ insetLeft: layout.insetLeft,
196
+ insetRight: layout.insetRight,
197
+ footerStyle: getFooterStyle(footerStyle, configured),
198
+ hasImageBackground,
199
+ });
200
+
201
+ let overlap = 0;
202
+ if (geometry.kind === 'sheet') {
203
+ overlap = height;
204
+ }
205
+ return {
206
+ ...geometry,
207
+ hasSeparator: geometry.kind === 'anchored' && !hasImageBackground,
208
+ hasSurface: geometry.kind === 'phone' || !hasImageBackground,
209
+ overlap,
210
+ handleLayout,
211
+ };
212
+ };
213
+
214
+ /**
215
+ * Spacer at the end of the body so a sheet footer does not cover its last element.
216
+ */
217
+ const renderFooterSpacer = (overlap: number) => {
218
+ if (!overlap) {
219
+ return null;
220
+ }
221
+ return <View style={{ height: overlap }} />;
222
+ };
223
+
224
+ /**
225
+ * Screen footer on the surface color above the home indicator or the floating tab bar.
226
+ * Phones keep the top shadow; foldables cap the content under a window-wide bar with a
227
+ * top border or shadow (`anchored`) or in a sheet centered over the body (`sheet`).
228
+ */
229
+ const ScreenFooter = ({
230
+ footer,
231
+ marginFooter,
232
+ layout,
233
+ separator,
29
234
  isTab,
30
235
  duoTabInset,
31
236
  bottomInset,
32
- surfaceColor,
33
237
  }: ScreenFooterProps) => {
238
+ const { theme } = useContext(ApplicationContext);
239
+ const context: DesignSystemContext | undefined = useContext(MiniAppContext);
34
240
  let bottomSpace = bottomInset;
35
241
  if (isTab && duoTabInset) {
36
242
  bottomSpace = duoTabInset;
37
243
  }
38
244
 
245
+ const { kind, barMargin } = layout;
246
+ const hasBarMargin = barMargin.left > 0 || barMargin.right > 0;
247
+
248
+ // one view tree for every kind, so folding keeps the footer content's state
249
+ let containerStyle: StyleProp<ViewStyle> = [
250
+ hasBarMargin && styles.footerClip,
251
+ { marginLeft: barMargin.left, marginRight: barMargin.right },
252
+ ];
253
+ let surfaceStyle: StyleProp<ViewStyle> = styles.shadow;
254
+ if (kind === 'anchored') {
255
+ const configured = context?.designSystemConfig?.config?.footerSeparator;
256
+ const resolved = getFooterSeparator(separator, configured);
257
+ const separatorStyle = getSeparatorStyle(
258
+ resolved,
259
+ theme.colors.border.default,
260
+ );
261
+ surfaceStyle = [styles.footerBar, layout.hasSeparator && separatorStyle];
262
+ }
263
+ if (kind === 'sheet') {
264
+ containerStyle = [containerStyle, { marginTop: -layout.overlap }];
265
+ surfaceStyle = [styles.footerSheet, { width: layout.width }];
266
+ }
267
+ let surfaceColor: string | undefined;
268
+ if (layout.hasSurface) {
269
+ surfaceColor = theme.colors.background.surface;
270
+ }
271
+
39
272
  return (
40
273
  <View
41
274
  pointerEvents={'box-none'}
42
- style={[
43
- hasContentInset && styles.footerClip,
44
- {
45
- marginLeft: insetLeft,
46
- marginRight: insetRight,
47
- },
48
- ]}
275
+ onLayout={layout.handleLayout}
276
+ style={containerStyle}
49
277
  >
50
278
  <View
51
279
  style={[
52
- styles.shadow,
280
+ surfaceStyle,
53
281
  {
54
282
  paddingBottom: bottomSpace + Spacing.S,
55
283
  backgroundColor: surfaceColor,
56
284
  },
57
285
  ]}
58
286
  >
59
- <Section useMargin={marginFooter}>{footer}</Section>
287
+ <Section
288
+ useMargin={marginFooter}
289
+ maxWidth={getFooterRowWidth(layout, marginFooter)}
290
+ >
291
+ {footer}
292
+ </Section>
60
293
  </View>
61
294
  </View>
62
295
  );
63
296
  };
297
+
298
+ export type { FooterLayout };
299
+
300
+ export {
301
+ ScreenFooter,
302
+ getFooterGeometry,
303
+ getFooterRowWidth,
304
+ getFooterSeparator,
305
+ getFooterStyle,
306
+ renderFooterSpacer,
307
+ useFooterLayout,
308
+ };
@@ -13,9 +13,13 @@ import {
13
13
  SearchHeader,
14
14
  } from '../Application';
15
15
  import { DuoGlassBackground } from '../Application/Components/DuoGlassBackground';
16
- import { type HeaderContentLayout } from '../Application/headerLayout';
16
+ import {
17
+ type HeaderContentLayout,
18
+ useHeaderFrameOptions,
19
+ useHeaderLayout,
20
+ } from '../Application/headerLayout';
17
21
  import { getHeaderMargin } from './utils';
18
- import { useHeaderBarOptions } from './useHeaderBarOptions';
22
+ import { ANIMATED_BANNER_HEIGHT } from './screenTypes';
19
23
  import { HeaderType } from './types';
20
24
 
21
25
  type ScreenHeaderParams = {
@@ -30,20 +34,18 @@ type ScreenHeaderParams = {
30
34
  useShadowHeader: boolean;
31
35
  gradientColor?: string;
32
36
  headerBackground?: string;
33
- bannerBottom: number;
37
+ layoutOffset: number;
34
38
  contentLayout?: HeaderContentLayout;
35
39
  };
36
40
 
37
41
  /**
38
42
  * Transparent header for an `inputSearchProps` Screen: its title fades out over the
39
- * first 50pt of scroll while the search collapses into the bar (`searchTitleOptions`).
43
+ * first 50pt of scroll while the search collapses into the bar.
40
44
  */
41
45
  const getSearchTitleOptions = (
42
46
  sharedValue: SharedValue<number>,
43
- searchTitleOptions: StackNavigationOptions,
44
47
  ): StackNavigationOptions => {
45
48
  return {
46
- ...searchTitleOptions,
47
49
  headerShown: true,
48
50
  headerTransparent: true,
49
51
  headerBackground: () => null,
@@ -77,14 +79,14 @@ export const useScreenHeader = ({
77
79
  useShadowHeader,
78
80
  gradientColor,
79
81
  headerBackground,
80
- bannerBottom,
82
+ layoutOffset,
81
83
  contentLayout,
82
84
  }: ScreenHeaderParams) => {
83
85
  const currentTint = useRef<string | undefined>(undefined);
84
86
  const appliedHeaderMode = useRef<string | undefined>(undefined);
85
87
  const searchHeaderParams = useRef<SearchHeaderProps | undefined>(undefined);
86
- const headerBarOptions = useHeaderBarOptions(layout, contentLayout);
87
- const { barOptions, searchTitleOptions, searchOptions } = headerBarOptions;
88
+ const headerLayout = useHeaderLayout(contentLayout);
89
+ const frameOptions = useHeaderFrameOptions(contentLayout);
88
90
 
89
91
  // keepTitle leaves a title the screen set itself when the same type is re-applied
90
92
  const setHeaderType = useCallback(
@@ -113,7 +115,7 @@ export const useScreenHeader = ({
113
115
  headerTitle: (props: any) => <HeaderTitle {...props} />,
114
116
  };
115
117
  if (inputSearchProps) {
116
- options = getSearchTitleOptions(sharedValue, searchTitleOptions);
118
+ options = getSearchTitleOptions(sharedValue);
117
119
  }
118
120
  break;
119
121
 
@@ -147,7 +149,7 @@ export const useScreenHeader = ({
147
149
  headerTitle: (props: any) => <HeaderTitle {...props} />,
148
150
  };
149
151
  if (inputSearchProps) {
150
- options = getSearchTitleOptions(sharedValue, searchTitleOptions);
152
+ options = getSearchTitleOptions(sharedValue);
151
153
  }
152
154
  }
153
155
 
@@ -157,7 +159,7 @@ export const useScreenHeader = ({
157
159
 
158
160
  navigation?.instance?.setOptions({
159
161
  header: undefined,
160
- ...barOptions,
162
+ ...frameOptions,
161
163
  ...options,
162
164
  });
163
165
  },
@@ -170,8 +172,7 @@ export const useScreenHeader = ({
170
172
  useShadowHeader,
171
173
  hasSideBar,
172
174
  quickReturnOptions,
173
- barOptions,
174
- searchTitleOptions,
175
+ frameOptions,
175
176
  ],
176
177
  );
177
178
 
@@ -192,7 +193,7 @@ export const useScreenHeader = ({
192
193
  return (
193
194
  <DuoGlassBackground
194
195
  animatedValue={sharedValue}
195
- bannerBottom={bannerBottom}
196
+ bannerBottom={ANIMATED_BANNER_HEIGHT + layoutOffset}
196
197
  />
197
198
  );
198
199
  }
@@ -219,7 +220,7 @@ export const useScreenHeader = ({
219
220
  };
220
221
  }
221
222
 
222
- navigation?.instance?.setOptions({ ...barOptions, ...options });
223
+ navigation?.instance?.setOptions({ ...frameOptions, ...options });
223
224
  },
224
225
  [
225
226
  gradientColor,
@@ -228,20 +229,24 @@ export const useScreenHeader = ({
228
229
  sharedValue,
229
230
  useShadowHeader,
230
231
  hasSideBar,
231
- bannerBottom,
232
+ layoutOffset,
232
233
  quickReturnOptions,
233
- barOptions,
234
+ frameOptions,
234
235
  ],
235
236
  );
236
237
 
237
238
  const setAnimatedSearch = useCallback(() => {
238
- const options = getSearchTitleOptions(sharedValue, searchTitleOptions);
239
- navigation?.instance?.setOptions({ header: undefined, ...options });
240
- }, [navigation?.instance, sharedValue, searchTitleOptions]);
239
+ const options = getSearchTitleOptions(sharedValue);
240
+ navigation?.instance?.setOptions({
241
+ header: undefined,
242
+ ...frameOptions,
243
+ ...options,
244
+ });
245
+ }, [navigation?.instance, sharedValue, frameOptions]);
241
246
 
242
- // the search field spans the content, clear of the side bar and status bar
243
- // clusters; kept as numbers so the setter below stays stable
244
- let searchWidth = layout.width - Spacing.M * 2;
247
+ // the search field spans the content (or the stretch frame), clear of the side bar
248
+ // and status bar clusters; kept as numbers so the setter below stays stable
249
+ let searchWidth = headerLayout.frameWidth;
245
250
  let searchLeft = Spacing.M;
246
251
  if (layout.sideBar) {
247
252
  searchWidth = layout.contentWidth - Spacing.M * 2;
@@ -260,7 +265,7 @@ export const useScreenHeader = ({
260
265
  (params: SearchHeaderProps) => {
261
266
  searchHeaderParams.current = params;
262
267
  const options: StackNavigationOptions = {
263
- ...searchOptions,
268
+ ...frameOptions,
264
269
  headerRight: undefined,
265
270
  headerTitleContainerStyle: {
266
271
  width: searchWidth,
@@ -286,7 +291,7 @@ export const useScreenHeader = ({
286
291
 
287
292
  navigation?.instance?.setOptions(options);
288
293
  },
289
- [navigation?.instance, sharedValue, searchOptions, searchWidth, searchLeft],
294
+ [navigation?.instance, sharedValue, frameOptions, searchWidth, searchLeft],
290
295
  );
291
296
 
292
297
  useEffect(() => {
@@ -7,7 +7,7 @@ import {
7
7
  SearchHeaderProps,
8
8
  } from '../Application/types';
9
9
  import { FloatingButtonProps } from './FloatingButton';
10
- import { HeaderType } from './types';
10
+ import { HeaderType, ScreenFooterSeparator, ScreenFooterStyle } from './types';
11
11
  import { InputRef } from '../Input';
12
12
  import type { HeaderContentLayout } from '../Application/headerLayout';
13
13
 
@@ -65,6 +65,29 @@ export interface ScreenProps extends ViewProps {
65
65
  */
66
66
  marginFooter?: boolean;
67
67
 
68
+ /**
69
+ * Optional. Footer look on foldable inner displays and wide windows: `anchored`, a
70
+ * full-width bar with a top separator, or `sheet`, a centered sheet over the body. Content
71
+ * is capped at 600pt (800pt on windows from 800pt). Defaults to the host's design
72
+ * system config (`footerStyle`), else `anchored`. Phones keep the current footer.
73
+ */
74
+ footerStyle?: ScreenFooterStyle;
75
+
76
+ /**
77
+ * Optional. Top edge of the `anchored` footer on foldables: `border`, a 1pt line, or
78
+ * `shadow`, the phone footer's shadow. Defaults to the host's design system config
79
+ * (`footerSeparator`), else `border`. Phones keep their shadow; an image background
80
+ * draws neither.
81
+ */
82
+ footerSeparator?: ScreenFooterSeparator;
83
+
84
+ /**
85
+ * Optional. If `true`, the screen draws an image behind the footer: on foldables the
86
+ * footer drops its surface fill, sheet and top border so the image shows through.
87
+ * Defaults to `false`.
88
+ */
89
+ footerHasImageBackground?: boolean;
90
+
68
91
  /**
69
92
  * Optional. Background color of the screen.
70
93
  */
@@ -83,9 +106,9 @@ export interface ScreenProps extends ViewProps {
83
106
  headerRightWidth?: 0 | 84 | 124 | number;
84
107
 
85
108
  /**
86
- * Optional. `stretch` centers back, title and the right cluster of the header in a
87
- * 600pt frame on wide windows (foldable inner display, tablet); the background,
88
- * status bar and a search header stay full width. Defaults to `grid`.
109
+ * Optional. `stretch` centers back, title or search and the right cluster of the
110
+ * header in a 600pt frame on wide windows (foldable inner display, tablet); the
111
+ * background and status bar stay full width. Defaults to `grid`.
89
112
  */
90
113
  contentLayout?: HeaderContentLayout;
91
114
 
package/Layout/styles.ts CHANGED
@@ -91,6 +91,15 @@ export default StyleSheet.create({
91
91
  },
92
92
  }),
93
93
  },
94
+ footerBar: {
95
+ paddingTop: Spacing.S,
96
+ },
97
+ footerSheet: {
98
+ paddingTop: Spacing.S,
99
+ alignSelf: 'center',
100
+ borderTopLeftRadius: Radius.XL,
101
+ borderTopRightRadius: Radius.XL,
102
+ },
94
103
  footerClip: {
95
104
  marginTop: -Spacing.XL,
96
105
  paddingTop: Spacing.XL,
@@ -98,5 +107,6 @@ export default StyleSheet.create({
98
107
  },
99
108
  debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
100
109
  expanded: { flex: 1 },
110
+ centered: { alignSelf: 'center' },
101
111
  rowWrap: { flexDirection: 'row', flexWrap: 'wrap' },
102
112
  });
package/Layout/types.ts CHANGED
@@ -2,6 +2,18 @@ import { NavigationOptions, SearchHeaderProps } from '../Application/types';
2
2
 
3
3
  export type HeaderType = 'default' | 'extended' | 'none';
4
4
 
5
+ /**
6
+ * Screen footer look on foldable inner displays and wide windows: `anchored` is a
7
+ * full-width bar with a top separator, `sheet` a centered sheet over the body.
8
+ */
9
+ export type ScreenFooterStyle = 'anchored' | 'sheet';
10
+
11
+ /**
12
+ * Top edge of the anchored footer on foldables: a 1pt `border` line, or the phone
13
+ * footer's `shadow`.
14
+ */
15
+ export type ScreenFooterSeparator = 'border' | 'shadow';
16
+
5
17
  export type ScreenRef = {
6
18
  /**
7
19
  * Applies navigation options to the screen's header.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.17",
3
+ "version": "0.169.18-beta.2",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},