@momo-kits/foundation 0.169.17-beta.9 → 0.169.18-beta.1

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.
package/Layout/Screen.tsx CHANGED
@@ -58,6 +58,7 @@ const Screen = forwardRef(
58
58
  footerComponent: Footer,
59
59
  marginFooter = true,
60
60
  footerStyle,
61
+ footerSeparator,
61
62
  footerHasImageBackground: hasImageFooter,
62
63
  layoutOffset = -56,
63
64
  headerRightWidth,
@@ -315,10 +316,10 @@ const Screen = forwardRef(
315
316
  footer={Footer}
316
317
  marginFooter={marginFooter}
317
318
  layout={footerLayout}
319
+ separator={footerSeparator}
318
320
  isTab={isTab}
319
321
  duoTabInset={duoTabInset}
320
322
  bottomInset={bottomInset}
321
- surfaceColor={theme.colors.background.surface}
322
323
  />
323
324
  )}
324
325
  </KeyboardAvoidingView>
@@ -1,12 +1,36 @@
1
- import { getFooterGeometry, getFooterStyle } from '../screenFooter';
1
+ import {
2
+ getFooterGeometry,
3
+ getFooterRowWidth,
4
+ getFooterSeparator,
5
+ getFooterStyle,
6
+ } from '../screenFooter';
2
7
 
3
8
  // the grid row pulls in every foundation component; geometry does not render
4
9
  jest.mock('../Section', () => ({ __esModule: true, default: () => null }));
5
10
 
6
- const PHONE = { width: 390, height: 844, contentWidth: 390 };
7
- const FOLD_PORTRAIT = { width: 760, height: 900, contentWidth: 760 };
8
- const FOLD_LANDSCAPE = { width: 860, height: 700, contentWidth: 860 };
9
- const TABLET = { width: 1194, height: 834, contentWidth: 1194 };
11
+ const NO_INSETS = { insetLeft: 0, insetRight: 0 };
12
+ const PHONE = { width: 390, height: 844, contentWidth: 390, ...NO_INSETS };
13
+ const FOLD_PORTRAIT = {
14
+ width: 760,
15
+ height: 900,
16
+ contentWidth: 760,
17
+ ...NO_INSETS,
18
+ };
19
+ const FOLD_LANDSCAPE = {
20
+ width: 860,
21
+ height: 700,
22
+ contentWidth: 860,
23
+ ...NO_INSETS,
24
+ };
25
+ const TABLET = { width: 1194, height: 834, contentWidth: 1194, ...NO_INSETS };
26
+ // iPhone Duo inner landscape: side column on the left, home indicator inset on the right
27
+ const DUO_INNER = {
28
+ width: 900,
29
+ height: 669,
30
+ contentWidth: 782,
31
+ insetLeft: 84,
32
+ insetRight: 34,
33
+ };
10
34
  const ANCHORED = {
11
35
  footerStyle: 'anchored' as const,
12
36
  hasImageBackground: false,
@@ -16,16 +40,21 @@ const SHEET = { footerStyle: 'sheet' as const, hasImageBackground: false };
16
40
  describe('getFooterGeometry', () => {
17
41
  it('keeps the phone footer below 600pt, landscape included', () => {
18
42
  expect(getFooterGeometry({ ...PHONE, ...SHEET }).kind).toBe('phone');
19
- const landscape = { width: 844, height: 390, contentWidth: 844 };
43
+ const landscape = {
44
+ ...NO_INSETS,
45
+ width: 844,
46
+ height: 390,
47
+ contentWidth: 844,
48
+ };
20
49
  expect(getFooterGeometry({ ...landscape, ...SHEET }).kind).toBe('phone');
21
50
  });
22
51
 
23
52
  it('caps the width at 600pt below an 800pt window, 800pt from it', () => {
24
- expect(getFooterGeometry({ ...FOLD_PORTRAIT, ...ANCHORED })).toEqual({
53
+ expect(getFooterGeometry({ ...FOLD_PORTRAIT, ...ANCHORED })).toMatchObject({
25
54
  kind: 'anchored',
26
55
  width: 600,
27
56
  });
28
- expect(getFooterGeometry({ ...FOLD_LANDSCAPE, ...SHEET })).toEqual({
57
+ expect(getFooterGeometry({ ...FOLD_LANDSCAPE, ...SHEET })).toMatchObject({
29
58
  kind: 'sheet',
30
59
  width: 800,
31
60
  });
@@ -33,14 +62,62 @@ describe('getFooterGeometry', () => {
33
62
  });
34
63
 
35
64
  it('keeps the width inside the content area minus its margins', () => {
36
- const duoInner = { width: 669, height: 900, contentWidth: 585 };
37
- expect(getFooterGeometry({ ...duoInner, ...ANCHORED }).width).toBe(561);
65
+ const duoPortrait = {
66
+ ...NO_INSETS,
67
+ width: 669,
68
+ height: 900,
69
+ contentWidth: 585,
70
+ };
71
+ expect(getFooterGeometry({ ...duoPortrait, ...ANCHORED }).width).toBe(561);
38
72
  });
39
73
 
40
74
  it('drops the sheet for an image background', () => {
41
75
  const input = { ...FOLD_LANDSCAPE, ...SHEET, hasImageBackground: true };
42
76
  expect(getFooterGeometry(input).kind).toBe('anchored');
43
77
  });
78
+
79
+ it('keeps the phone bar clear of the iPhone Duo side column', () => {
80
+ const duoOuter = { width: 390, height: 844, contentWidth: 306 };
81
+ const input = { ...duoOuter, insetLeft: 84, insetRight: 0, ...ANCHORED };
82
+ expect(getFooterGeometry(input)).toMatchObject({
83
+ barMargin: { left: 84, right: 0 },
84
+ contentPadding: { left: 0, right: 0 },
85
+ });
86
+ });
87
+
88
+ it('spans the anchored bar over the window, its content inside the insets', () => {
89
+ expect(getFooterGeometry({ ...DUO_INNER, ...ANCHORED })).toEqual({
90
+ kind: 'anchored',
91
+ width: 758,
92
+ barMargin: { left: 0, right: 0 },
93
+ contentPadding: { left: 84, right: 34 },
94
+ });
95
+ });
96
+
97
+ it('centers the sheet on the window, its width kept from the content area', () => {
98
+ expect(getFooterGeometry({ ...DUO_INNER, ...SHEET })).toEqual({
99
+ kind: 'sheet',
100
+ width: 758,
101
+ barMargin: { left: 0, right: 0 },
102
+ contentPadding: { left: 0, right: 0 },
103
+ });
104
+ });
105
+ });
106
+
107
+ describe('getFooterRowWidth', () => {
108
+ it('keeps the 12pt margins inside the foldable content area', () => {
109
+ const portrait = getFooterGeometry({ ...FOLD_PORTRAIT, ...ANCHORED });
110
+ const landscape = getFooterGeometry({ ...FOLD_LANDSCAPE, ...ANCHORED });
111
+ expect(getFooterRowWidth(portrait, true)).toBe(576);
112
+ expect(getFooterRowWidth(landscape, true)).toBe(776);
113
+ });
114
+
115
+ it('fills the area without margins and leaves the phone row uncapped', () => {
116
+ const landscape = getFooterGeometry({ ...FOLD_LANDSCAPE, ...ANCHORED });
117
+ expect(getFooterRowWidth(landscape, false)).toBe(800);
118
+ const phone = getFooterGeometry({ ...PHONE, ...ANCHORED });
119
+ expect(getFooterRowWidth(phone, true)).toBeUndefined();
120
+ });
44
121
  });
45
122
 
46
123
  describe('getFooterStyle', () => {
@@ -54,3 +131,15 @@ describe('getFooterStyle', () => {
54
131
  expect(getFooterStyle(undefined, 'floating')).toBe('anchored');
55
132
  });
56
133
  });
134
+
135
+ describe('getFooterSeparator', () => {
136
+ it('lets the screen prop win over the host config', () => {
137
+ expect(getFooterSeparator('border', 'shadow')).toBe('border');
138
+ expect(getFooterSeparator(undefined, 'shadow')).toBe('shadow');
139
+ });
140
+
141
+ it('falls back to border for a missing or unknown value', () => {
142
+ expect(getFooterSeparator()).toBe('border');
143
+ expect(getFooterSeparator(undefined, 'line')).toBe('border');
144
+ });
145
+ });
@@ -4,7 +4,7 @@ import { isFoldableWindow } from '../Application/modalLayout';
4
4
  import { ApplicationContext, MiniAppContext } from '../Context';
5
5
  import { Spacing } from '../Consts';
6
6
  import { ScreenLayout } from './layoutTypes';
7
- import { ScreenFooterStyle } from './types';
7
+ import { ScreenFooterSeparator, ScreenFooterStyle } from './types';
8
8
  import Section from './Section';
9
9
  import styles from './styles';
10
10
 
@@ -16,24 +16,50 @@ const FOOTER_BORDER_WIDTH = 1;
16
16
 
17
17
  type FooterKind = 'phone' | 'anchored' | 'sheet';
18
18
 
19
- type FooterGeometry = { kind: FooterKind; width: number };
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
+ * Padding inside the anchored bar that keeps its content clear of the side column.
34
+ */
35
+ contentPadding: HorizontalInsets;
36
+ };
20
37
 
21
38
  type DesignSystemContext = {
22
- designSystemConfig?: { config?: { footerStyle?: unknown } };
39
+ designSystemConfig?: {
40
+ config?: { footerStyle?: unknown; footerSeparator?: unknown };
41
+ };
23
42
  };
24
43
 
25
44
  type FooterGeometryInput = {
26
45
  width: number;
27
46
  height: number;
28
47
  contentWidth: number;
48
+ insetLeft: number;
49
+ insetRight: number;
29
50
  footerStyle: ScreenFooterStyle;
30
51
  hasImageBackground: boolean;
31
52
  };
32
53
 
33
54
  type FooterLayout = FooterGeometry & {
34
- hasBorder: boolean;
35
- insetLeft: number;
36
- insetRight: number;
55
+ /**
56
+ * `true` for the anchored bar without an image background, which draws a separator.
57
+ */
58
+ hasSeparator: boolean;
59
+ /**
60
+ * `false` on a foldable with an image background, so the screen's image shows through.
61
+ */
62
+ hasSurface: boolean;
37
63
  /**
38
64
  * Height the sheet overlaps the body by; 0 while the footer sits below the body.
39
65
  */
@@ -45,12 +71,14 @@ type ScreenFooterProps = {
45
71
  footer: ReactNode;
46
72
  marginFooter: boolean;
47
73
  layout: FooterLayout;
74
+ separator?: ScreenFooterSeparator;
48
75
  isTab: boolean;
49
76
  duoTabInset: number;
50
77
  bottomInset: number;
51
- surfaceColor: string;
52
78
  };
53
79
 
80
+ const NO_INSETS: HorizontalInsets = { left: 0, right: 0 };
81
+
54
82
  /**
55
83
  * The screen prop wins over the host's design system config; anything else is `anchored`.
56
84
  */
@@ -65,18 +93,39 @@ const getFooterStyle = (
65
93
  };
66
94
 
67
95
  /**
68
- * Footer kind and width (anchored content or sheet) for a window, pure so it can be
69
- * tested without a device. Phones, iPhone Duo outer included, keep the shadowed bar.
96
+ * The screen prop wins over the host's design system config; anything else is `border`.
97
+ */
98
+ const getFooterSeparator = (
99
+ separator?: ScreenFooterSeparator,
100
+ configured?: unknown,
101
+ ): ScreenFooterSeparator => {
102
+ if ((separator ?? configured) === 'shadow') {
103
+ return 'shadow';
104
+ }
105
+ return 'border';
106
+ };
107
+
108
+ /**
109
+ * Footer kind, width and side insets for a window, pure so it can be tested without a
110
+ * device. Phones, iPhone Duo outer included, keep the shadowed bar.
70
111
  */
71
112
  const getFooterGeometry = ({
72
113
  width,
73
114
  height,
74
115
  contentWidth,
116
+ insetLeft,
117
+ insetRight,
75
118
  footerStyle,
76
119
  hasImageBackground,
77
120
  }: FooterGeometryInput): FooterGeometry => {
121
+ const contentInsets = { left: insetLeft, right: insetRight };
78
122
  if (!isFoldableWindow(width, height)) {
79
- return { kind: 'phone', width: contentWidth };
123
+ return {
124
+ kind: 'phone',
125
+ width: contentWidth,
126
+ barMargin: contentInsets,
127
+ contentPadding: NO_INSETS,
128
+ };
80
129
  }
81
130
 
82
131
  let maxWidth = FOOTER_MAX_WIDTH;
@@ -85,8 +134,52 @@ const getFooterGeometry = ({
85
134
  }
86
135
  const footerWidth = Math.min(contentWidth - Spacing.M * 2, maxWidth);
87
136
  // an image background spans the window, so it never sits in a sheet
88
- const isSheet = footerStyle === 'sheet' && !hasImageBackground;
89
- return { kind: isSheet ? 'sheet' : 'anchored', width: footerWidth };
137
+ if (footerStyle === 'sheet' && !hasImageBackground) {
138
+ // Figma centers the sheet on the window, side column included
139
+ return {
140
+ kind: 'sheet',
141
+ width: footerWidth,
142
+ barMargin: NO_INSETS,
143
+ contentPadding: NO_INSETS,
144
+ };
145
+ }
146
+ return {
147
+ kind: 'anchored',
148
+ width: footerWidth,
149
+ barMargin: NO_INSETS,
150
+ contentPadding: contentInsets,
151
+ };
152
+ };
153
+
154
+ /**
155
+ * Cap of the footer grid row: the foldable area minus the 12pt margins it keeps
156
+ * inside; `undefined` on a phone, where the row spans the content.
157
+ */
158
+ const getFooterRowWidth = (
159
+ geometry: FooterGeometry,
160
+ hasMargin: boolean,
161
+ ): number | undefined => {
162
+ if (geometry.kind === 'phone') {
163
+ return undefined;
164
+ }
165
+ let margin = 0;
166
+ if (hasMargin) {
167
+ margin = Spacing.M;
168
+ }
169
+ return geometry.width - margin * 2;
170
+ };
171
+
172
+ /**
173
+ * Top edge of the anchored bar: a 1pt border line or the phone footer shadow.
174
+ */
175
+ const getSeparatorStyle = (
176
+ separator: ScreenFooterSeparator,
177
+ borderColor: string,
178
+ ): StyleProp<ViewStyle> => {
179
+ if (separator === 'shadow') {
180
+ return styles.shadow;
181
+ }
182
+ return { borderTopWidth: FOOTER_BORDER_WIDTH, borderTopColor: borderColor };
90
183
  };
91
184
 
92
185
  /**
@@ -109,6 +202,8 @@ const useFooterLayout = (
109
202
  width: layout.width,
110
203
  height: layout.height,
111
204
  contentWidth: layout.contentWidth,
205
+ insetLeft: layout.insetLeft,
206
+ insetRight: layout.insetRight,
112
207
  footerStyle: getFooterStyle(footerStyle, configured),
113
208
  hasImageBackground,
114
209
  });
@@ -119,9 +214,8 @@ const useFooterLayout = (
119
214
  }
120
215
  return {
121
216
  ...geometry,
122
- hasBorder: geometry.kind === 'anchored' && !hasImageBackground,
123
- insetLeft: layout.insetLeft,
124
- insetRight: layout.insetRight,
217
+ hasSeparator: geometry.kind === 'anchored' && !hasImageBackground,
218
+ hasSurface: geometry.kind === 'phone' || !hasImageBackground,
125
219
  overlap,
126
220
  handleLayout,
127
221
  };
@@ -139,49 +233,50 @@ const renderFooterSpacer = (overlap: number) => {
139
233
 
140
234
  /**
141
235
  * Screen footer on the surface color above the home indicator or the floating tab bar.
142
- * Phones keep the top shadow; foldables cap the content under a full-width bar with a
143
- * top border (`anchored`) or in a centered sheet over the body (`sheet`).
236
+ * Phones keep the top shadow; foldables cap the content under a window-wide bar with a
237
+ * top border or shadow (`anchored`) or in a sheet centered over the body (`sheet`).
144
238
  */
145
239
  const ScreenFooter = ({
146
240
  footer,
147
241
  marginFooter,
148
242
  layout,
243
+ separator,
149
244
  isTab,
150
245
  duoTabInset,
151
246
  bottomInset,
152
- surfaceColor,
153
247
  }: ScreenFooterProps) => {
154
248
  const { theme } = useContext(ApplicationContext);
249
+ const context: DesignSystemContext | undefined = useContext(MiniAppContext);
155
250
  let bottomSpace = bottomInset;
156
251
  if (isTab && duoTabInset) {
157
252
  bottomSpace = duoTabInset;
158
253
  }
159
254
 
160
- const { kind, insetLeft, insetRight } = layout;
161
- const hasContentInset = insetLeft > 0 || insetRight > 0;
162
- const margin = marginFooter ? Spacing.M : 0;
255
+ const { kind, barMargin, contentPadding } = layout;
256
+ const hasBarMargin = barMargin.left > 0 || barMargin.right > 0;
163
257
 
164
258
  // one view tree for every kind, so folding keeps the footer content's state
165
259
  let containerStyle: StyleProp<ViewStyle> = [
166
- kind === 'phone' && hasContentInset && styles.footerClip,
167
- { marginLeft: insetLeft, marginRight: insetRight },
260
+ hasBarMargin && styles.footerClip,
261
+ { marginLeft: barMargin.left, marginRight: barMargin.right },
168
262
  ];
169
263
  let surfaceStyle: StyleProp<ViewStyle> = styles.shadow;
170
- let sectionMaxWidth: number | undefined;
171
264
  if (kind === 'anchored') {
172
- surfaceStyle = [
173
- styles.footerBar,
174
- layout.hasBorder && {
175
- borderTopWidth: FOOTER_BORDER_WIDTH,
176
- borderTopColor: theme.colors.border.default,
177
- },
178
- ];
179
- sectionMaxWidth = layout.width;
265
+ const configured = context?.designSystemConfig?.config?.footerSeparator;
266
+ const resolved = getFooterSeparator(separator, configured);
267
+ const separatorStyle = getSeparatorStyle(
268
+ resolved,
269
+ theme.colors.border.default,
270
+ );
271
+ surfaceStyle = [styles.footerBar, layout.hasSeparator && separatorStyle];
180
272
  }
181
273
  if (kind === 'sheet') {
182
274
  containerStyle = [containerStyle, { marginTop: -layout.overlap }];
183
275
  surfaceStyle = [styles.footerSheet, { width: layout.width }];
184
- sectionMaxWidth = layout.width - margin * 2;
276
+ }
277
+ let surfaceColor: string | undefined;
278
+ if (layout.hasSurface) {
279
+ surfaceColor = theme.colors.background.surface;
185
280
  }
186
281
 
187
282
  return (
@@ -194,12 +289,17 @@ const ScreenFooter = ({
194
289
  style={[
195
290
  surfaceStyle,
196
291
  {
292
+ paddingLeft: contentPadding.left,
293
+ paddingRight: contentPadding.right,
197
294
  paddingBottom: bottomSpace + Spacing.S,
198
295
  backgroundColor: surfaceColor,
199
296
  },
200
297
  ]}
201
298
  >
202
- <Section useMargin={marginFooter} maxWidth={sectionMaxWidth}>
299
+ <Section
300
+ useMargin={marginFooter}
301
+ maxWidth={getFooterRowWidth(layout, marginFooter)}
302
+ >
203
303
  {footer}
204
304
  </Section>
205
305
  </View>
@@ -212,6 +312,8 @@ export type { FooterLayout };
212
312
  export {
213
313
  ScreenFooter,
214
314
  getFooterGeometry,
315
+ getFooterRowWidth,
316
+ getFooterSeparator,
215
317
  getFooterStyle,
216
318
  renderFooterSpacer,
217
319
  useFooterLayout,
@@ -7,7 +7,7 @@ import {
7
7
  SearchHeaderProps,
8
8
  } from '../Application/types';
9
9
  import { FloatingButtonProps } from './FloatingButton';
10
- import { HeaderType, ScreenFooterStyle } 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
 
@@ -67,15 +67,23 @@ export interface ScreenProps extends ViewProps {
67
67
 
68
68
  /**
69
69
  * Optional. Footer look on foldable inner displays and wide windows: `anchored`, a
70
- * full-width bar with a top border, or `sheet`, a centered sheet over the body. Content
70
+ * full-width bar with a top separator, or `sheet`, a centered sheet over the body. Content
71
71
  * is capped at 600pt (800pt on windows from 800pt). Defaults to the host's design
72
72
  * system config (`footerStyle`), else `anchored`. Phones keep the current footer.
73
73
  */
74
74
  footerStyle?: ScreenFooterStyle;
75
75
 
76
76
  /**
77
- * Optional. If `true`, the footer draws its own full-width image background, so a
78
- * `sheet` footer falls back to the `anchored` layout, without the top border.
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.
79
87
  * Defaults to `false`.
80
88
  */
81
89
  footerHasImageBackground?: boolean;
package/Layout/types.ts CHANGED
@@ -4,10 +4,16 @@ export type HeaderType = 'default' | 'extended' | 'none';
4
4
 
5
5
  /**
6
6
  * Screen footer look on foldable inner displays and wide windows: `anchored` is a
7
- * full-width bar with a top border, `sheet` a centered sheet over the body.
7
+ * full-width bar with a top separator, `sheet` a centered sheet over the body.
8
8
  */
9
9
  export type ScreenFooterStyle = 'anchored' | 'sheet';
10
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
+
11
17
  export type ScreenRef = {
12
18
  /**
13
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-beta.9",
3
+ "version": "0.169.18-beta.1",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},