@momo-kits/foundation 0.169.17-beta.8 → 0.169.17-beta.9
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/Application/Components/HeaderAnimated.tsx +9 -33
- package/Application/Components/HeaderExtendHeader.tsx +18 -28
- package/Application/Components/SearchHeader.tsx +5 -7
- package/Application/headerLayout.ts +30 -114
- package/Application/modalLayout.ts +12 -4
- package/Application/types.header.ts +1 -7
- package/Input/CountryCodeView.tsx +93 -0
- package/Input/InputPhoneNumber.tsx +20 -38
- package/Input/index.tsx +14 -1
- package/Layout/Screen.tsx +14 -12
- package/Layout/Section.tsx +14 -3
- package/Layout/__tests__/screenFooter.test.ts +56 -0
- package/Layout/layoutMetrics.ts +2 -2
- package/Layout/screenContent.tsx +10 -4
- package/Layout/screenFooter.tsx +175 -20
- package/Layout/screenHeader.tsx +31 -26
- package/Layout/screenTypes.ts +19 -4
- package/Layout/styles.ts +10 -0
- package/Layout/types.ts +6 -0
- package/package.json +1 -1
- package/Application/__tests__/headerLayout.test.ts +0 -113
- package/Layout/useHeaderBarOptions.ts +0 -54
|
@@ -6,7 +6,6 @@ import React, {
|
|
|
6
6
|
useState,
|
|
7
7
|
} from 'react';
|
|
8
8
|
import {
|
|
9
|
-
StyleSheet,
|
|
10
9
|
TextInput,
|
|
11
10
|
TextInputFocusEvent,
|
|
12
11
|
TouchableOpacity,
|
|
@@ -18,12 +17,11 @@ import {
|
|
|
18
17
|
ComponentContext,
|
|
19
18
|
MiniAppContext,
|
|
20
19
|
} from '../Context';
|
|
21
|
-
import { Colors, Spacing, Styles } from '../Consts';
|
|
22
20
|
import { Icon } from '../Icon';
|
|
23
|
-
import {
|
|
24
|
-
import { useScaleSize, Text, exportFontFamily } from '../Text';
|
|
21
|
+
import { useScaleSize, exportFontFamily } from '../Text';
|
|
25
22
|
import { Typography } from '../Text/types';
|
|
26
23
|
import { CLEAR_ICON_SIZE } from './constants';
|
|
24
|
+
import { CountryCodeView } from './CountryCodeView';
|
|
27
25
|
import { ErrorView } from './ErrorView';
|
|
28
26
|
import { InputPhoneNumberProps } from './index';
|
|
29
27
|
import { RenderTrailing } from './RenderTrailing';
|
|
@@ -36,11 +34,13 @@ const LARGE_FONT_SIZE = 18;
|
|
|
36
34
|
const SMALL_DIVIDER_HEIGHT = 24;
|
|
37
35
|
const LARGE_DIVIDER_HEIGHT = 32;
|
|
38
36
|
const FOCUSED_BORDER_WIDTH = 1.5;
|
|
39
|
-
const
|
|
37
|
+
const DEFAULT_COUNTRY_CODE = '+84';
|
|
38
|
+
const DEFAULT_COUNTRY_FLAG =
|
|
39
|
+
'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png';
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
* by default, plus clear and trailing icons.
|
|
42
|
+
* Phone number input behind a country flag and dial code (Vietnam `+84` by
|
|
43
|
+
* default), number pad by default, plus clear and trailing icons.
|
|
44
44
|
*/
|
|
45
45
|
const InputPhoneNumber = forwardRef(
|
|
46
46
|
(
|
|
@@ -66,6 +66,9 @@ const InputPhoneNumber = forwardRef(
|
|
|
66
66
|
editable = true,
|
|
67
67
|
showClearIcon = true,
|
|
68
68
|
defaultValue,
|
|
69
|
+
countryCode = DEFAULT_COUNTRY_CODE,
|
|
70
|
+
countryFlag = DEFAULT_COUNTRY_FLAG,
|
|
71
|
+
onPressLeadingIcon,
|
|
69
72
|
...props
|
|
70
73
|
}: InputPhoneNumberProps,
|
|
71
74
|
ref,
|
|
@@ -182,29 +185,16 @@ const InputPhoneNumber = forwardRef(
|
|
|
182
185
|
]}
|
|
183
186
|
>
|
|
184
187
|
<View style={styles.inputView}>
|
|
185
|
-
<
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
<Text typography={typography} color={textColor}>
|
|
196
|
-
{'+84'}
|
|
197
|
-
</Text>
|
|
198
|
-
<View
|
|
199
|
-
style={[
|
|
200
|
-
styles.phoneNumberDivider,
|
|
201
|
-
{
|
|
202
|
-
height: dividerHeight,
|
|
203
|
-
backgroundColor: Colors.black_04,
|
|
204
|
-
},
|
|
205
|
-
]}
|
|
206
|
-
/>
|
|
207
|
-
</View>
|
|
188
|
+
<CountryCodeView
|
|
189
|
+
countryCode={countryCode}
|
|
190
|
+
countryFlag={countryFlag}
|
|
191
|
+
typography={typography}
|
|
192
|
+
textColor={textColor}
|
|
193
|
+
dividerHeight={dividerHeight}
|
|
194
|
+
componentId={componentId}
|
|
195
|
+
isDisabled={disabled || !editable}
|
|
196
|
+
onPress={onPressLeadingIcon}
|
|
197
|
+
/>
|
|
208
198
|
<SystemTextInput
|
|
209
199
|
{...props}
|
|
210
200
|
accessibilityLabel={`${componentId}`}
|
|
@@ -302,12 +292,4 @@ const InputPhoneNumber = forwardRef(
|
|
|
302
292
|
},
|
|
303
293
|
);
|
|
304
294
|
|
|
305
|
-
const innerStyle = StyleSheet.create({
|
|
306
|
-
iconFlag: {
|
|
307
|
-
width: FLAG_SIZE,
|
|
308
|
-
height: FLAG_SIZE,
|
|
309
|
-
marginHorizontal: Spacing.XXS,
|
|
310
|
-
},
|
|
311
|
-
});
|
|
312
|
-
|
|
313
295
|
export default InputPhoneNumber;
|
package/Input/index.tsx
CHANGED
|
@@ -351,9 +351,22 @@ export interface InputDropDownProps extends TouchableOpacityProps {
|
|
|
351
351
|
|
|
352
352
|
export interface InputPhoneNumberProps extends InputProps {
|
|
353
353
|
/**
|
|
354
|
-
* Optional.
|
|
354
|
+
* Optional. Dial code shown verbatim before the number.
|
|
355
|
+
* Defaults to `+84` if not provided.
|
|
355
356
|
*/
|
|
356
357
|
countryCode?: string;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Optional. URL of the flag image shown before the dial code.
|
|
361
|
+
* Defaults to the Vietnam flag if not provided.
|
|
362
|
+
*/
|
|
363
|
+
countryFlag?: string;
|
|
364
|
+
|
|
365
|
+
/**
|
|
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}`.
|
|
368
|
+
*/
|
|
369
|
+
onPressLeadingIcon?: () => void;
|
|
357
370
|
}
|
|
358
371
|
|
|
359
372
|
export type InputRef = {
|
package/Layout/Screen.tsx
CHANGED
|
@@ -28,11 +28,14 @@ import { useScreenLayout } from './utils';
|
|
|
28
28
|
import { HeaderExtendHeader } from '../Application';
|
|
29
29
|
import { DuoScrollGradient } from '../Application/Components/DuoGlassBackground';
|
|
30
30
|
import { BottomTabInsetContext } from '../Application/BottomTab/BottomTabInset';
|
|
31
|
-
import {
|
|
32
|
-
import { ANIMATED_BANNER_HEIGHT, ScreenProps } from './screenTypes';
|
|
31
|
+
import { ScreenProps } from './screenTypes';
|
|
33
32
|
import { renderAnimatedHeader, renderContent } from './screenContent';
|
|
34
33
|
import { createScrollHandlers } from './screenScroll';
|
|
35
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
renderFooterSpacer,
|
|
36
|
+
ScreenFooter,
|
|
37
|
+
useFooterLayout,
|
|
38
|
+
} from './screenFooter';
|
|
36
39
|
import { useScreenHeader } from './screenHeader';
|
|
37
40
|
import { useScreenQuickReturn } from './screenQuickReturn';
|
|
38
41
|
|
|
@@ -54,6 +57,8 @@ const Screen = forwardRef(
|
|
|
54
57
|
headerComponent: Header,
|
|
55
58
|
footerComponent: Footer,
|
|
56
59
|
marginFooter = true,
|
|
60
|
+
footerStyle,
|
|
61
|
+
footerHasImageBackground: hasImageFooter,
|
|
57
62
|
layoutOffset = -56,
|
|
58
63
|
headerRightWidth,
|
|
59
64
|
backgroundColor,
|
|
@@ -79,9 +84,7 @@ const Screen = forwardRef(
|
|
|
79
84
|
const insets = useSafeAreaInsets();
|
|
80
85
|
const frame = useSafeAreaFrame();
|
|
81
86
|
const heightHeader = useHeaderHeight();
|
|
82
|
-
const
|
|
83
|
-
// the banner grows with its image on wide windows, the content keeps its overlap
|
|
84
|
-
const bannerBottom = ANIMATED_BANNER_HEIGHT * bannerScale + layoutOffset;
|
|
87
|
+
const footerLayout = useFooterLayout(layout, footerStyle, hasImageFooter);
|
|
85
88
|
|
|
86
89
|
const animatedValue = useRef<Animated.Value>(
|
|
87
90
|
customAnimatedValue ?? new Animated.Value(0),
|
|
@@ -148,7 +151,7 @@ const Screen = forwardRef(
|
|
|
148
151
|
useShadowHeader,
|
|
149
152
|
gradientColor,
|
|
150
153
|
headerBackground,
|
|
151
|
-
|
|
154
|
+
layoutOffset,
|
|
152
155
|
contentLayout,
|
|
153
156
|
});
|
|
154
157
|
|
|
@@ -199,7 +202,7 @@ const Screen = forwardRef(
|
|
|
199
202
|
|
|
200
203
|
let floatingButtonBottom = bottomInset + Spacing.S;
|
|
201
204
|
if (Footer) {
|
|
202
|
-
floatingButtonBottom = 12;
|
|
205
|
+
floatingButtonBottom = 12 + footerLayout.overlap;
|
|
203
206
|
} else if (isTab) {
|
|
204
207
|
floatingButtonBottom = 12 + duoTabInset;
|
|
205
208
|
}
|
|
@@ -283,12 +286,13 @@ const Screen = forwardRef(
|
|
|
283
286
|
>
|
|
284
287
|
{renderAnimatedHeader(
|
|
285
288
|
animatedHeader,
|
|
286
|
-
|
|
289
|
+
layoutOffset,
|
|
287
290
|
animatedValue.current,
|
|
288
291
|
sharedValue,
|
|
289
292
|
)}
|
|
290
293
|
|
|
291
294
|
{useGridLayout ? renderContent(children, layout) : children}
|
|
295
|
+
{renderFooterSpacer(footerLayout.overlap)}
|
|
292
296
|
</Component>
|
|
293
297
|
|
|
294
298
|
{floatingButtonProps && (
|
|
@@ -310,9 +314,7 @@ const Screen = forwardRef(
|
|
|
310
314
|
<ScreenFooter
|
|
311
315
|
footer={Footer}
|
|
312
316
|
marginFooter={marginFooter}
|
|
313
|
-
|
|
314
|
-
insetRight={layout.insetRight}
|
|
315
|
-
hasContentInset={hasContentInset}
|
|
317
|
+
layout={footerLayout}
|
|
316
318
|
isTab={isTab}
|
|
317
319
|
duoTabInset={duoTabInset}
|
|
318
320
|
bottomInset={bottomInset}
|
package/Layout/Section.tsx
CHANGED
|
@@ -24,16 +24,22 @@ export interface SectionProps extends ViewProps {
|
|
|
24
24
|
* Optional. Background image for the Section component.
|
|
25
25
|
*/
|
|
26
26
|
backgroundImage?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Optional. Caps the row width, side margins excluded; a capped row is centered.
|
|
30
|
+
*/
|
|
31
|
+
maxWidth?: number;
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
/**
|
|
30
|
-
* Content-wide grid row (12 or 24 columns) with optional side margins
|
|
31
|
-
* themselves from its GridContext.
|
|
35
|
+
* Content-wide grid row (12 or 24 columns) with optional side margins, capped by
|
|
36
|
+
* `maxWidth`; child Items size themselves from its GridContext.
|
|
32
37
|
*/
|
|
33
38
|
const Section: React.FC<SectionProps> = ({
|
|
34
39
|
children,
|
|
35
40
|
useMargin = true,
|
|
36
41
|
backgroundImage,
|
|
42
|
+
maxWidth,
|
|
37
43
|
style,
|
|
38
44
|
...props
|
|
39
45
|
}) => {
|
|
@@ -45,7 +51,11 @@ const Section: React.FC<SectionProps> = ({
|
|
|
45
51
|
if (useMargin) {
|
|
46
52
|
margin = 12;
|
|
47
53
|
}
|
|
48
|
-
const
|
|
54
|
+
const isCapped = maxWidth !== undefined;
|
|
55
|
+
let widthSection = contentWidth - margin * 2;
|
|
56
|
+
if (isCapped) {
|
|
57
|
+
widthSection = Math.min(widthSection, maxWidth);
|
|
58
|
+
}
|
|
49
59
|
|
|
50
60
|
const columnsWidth = widthSection - gutterSize * (numberOfColumns - 1);
|
|
51
61
|
const sizePerSpan = columnsWidth / numberOfColumns - 1 / numberOfColumns;
|
|
@@ -68,6 +78,7 @@ const Section: React.FC<SectionProps> = ({
|
|
|
68
78
|
style,
|
|
69
79
|
styles.protectedStyle,
|
|
70
80
|
styles.rowWrap,
|
|
81
|
+
isCapped && styles.centered,
|
|
71
82
|
{
|
|
72
83
|
width: widthSection,
|
|
73
84
|
marginHorizontal: margin,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getFooterGeometry, getFooterStyle } from '../screenFooter';
|
|
2
|
+
|
|
3
|
+
// the grid row pulls in every foundation component; geometry does not render
|
|
4
|
+
jest.mock('../Section', () => ({ __esModule: true, default: () => null }));
|
|
5
|
+
|
|
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 };
|
|
10
|
+
const ANCHORED = {
|
|
11
|
+
footerStyle: 'anchored' as const,
|
|
12
|
+
hasImageBackground: false,
|
|
13
|
+
};
|
|
14
|
+
const SHEET = { footerStyle: 'sheet' as const, hasImageBackground: false };
|
|
15
|
+
|
|
16
|
+
describe('getFooterGeometry', () => {
|
|
17
|
+
it('keeps the phone footer below 600pt, landscape included', () => {
|
|
18
|
+
expect(getFooterGeometry({ ...PHONE, ...SHEET }).kind).toBe('phone');
|
|
19
|
+
const landscape = { width: 844, height: 390, contentWidth: 844 };
|
|
20
|
+
expect(getFooterGeometry({ ...landscape, ...SHEET }).kind).toBe('phone');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('caps the width at 600pt below an 800pt window, 800pt from it', () => {
|
|
24
|
+
expect(getFooterGeometry({ ...FOLD_PORTRAIT, ...ANCHORED })).toEqual({
|
|
25
|
+
kind: 'anchored',
|
|
26
|
+
width: 600,
|
|
27
|
+
});
|
|
28
|
+
expect(getFooterGeometry({ ...FOLD_LANDSCAPE, ...SHEET })).toEqual({
|
|
29
|
+
kind: 'sheet',
|
|
30
|
+
width: 800,
|
|
31
|
+
});
|
|
32
|
+
expect(getFooterGeometry({ ...TABLET, ...SHEET }).width).toBe(800);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
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);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('drops the sheet for an image background', () => {
|
|
41
|
+
const input = { ...FOLD_LANDSCAPE, ...SHEET, hasImageBackground: true };
|
|
42
|
+
expect(getFooterGeometry(input).kind).toBe('anchored');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('getFooterStyle', () => {
|
|
47
|
+
it('lets the screen prop win over the host config', () => {
|
|
48
|
+
expect(getFooterStyle('anchored', 'sheet')).toBe('anchored');
|
|
49
|
+
expect(getFooterStyle(undefined, 'sheet')).toBe('sheet');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('falls back to anchored for a missing or unknown value', () => {
|
|
53
|
+
expect(getFooterStyle()).toBe('anchored');
|
|
54
|
+
expect(getFooterStyle(undefined, 'floating')).toBe('anchored');
|
|
55
|
+
});
|
|
56
|
+
});
|
package/Layout/layoutMetrics.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Header geometry. */
|
|
2
2
|
export const HeaderMetrics = {
|
|
3
|
-
/** Navigation bar row below the status bar
|
|
4
|
-
barHeight:
|
|
3
|
+
/** Navigation bar row below the status bar. */
|
|
4
|
+
barHeight: 52,
|
|
5
5
|
/** Header never shorter than this on iPhone (landscape, iPhone Duo). */
|
|
6
6
|
iPhoneMinHeight: 72,
|
|
7
7
|
/** A smaller top inset means the status bar is not on the top edge. */
|
package/Layout/screenContent.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { Animated, View } from 'react-native';
|
|
|
3
3
|
import { Spacing } from '../Consts';
|
|
4
4
|
import styles from './styles';
|
|
5
5
|
import { validateChildren } from './utils';
|
|
6
|
+
import { ANIMATED_BANNER_HEIGHT } from './screenTypes';
|
|
6
7
|
import { AnimatedHeader } from '../Application/types';
|
|
7
8
|
|
|
8
9
|
type ContentInset = { insetLeft: number; insetRight: number };
|
|
@@ -64,18 +65,23 @@ export const renderContent = (content: any, layout: ContentInset): any => {
|
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
|
-
* Animated banner from `animatedHeader.component`, clipped
|
|
68
|
-
*
|
|
68
|
+
* Animated banner from `animatedHeader.component`, clipped to the banner height plus
|
|
69
|
+
* `layoutOffset`. Nothing without a component.
|
|
69
70
|
*/
|
|
70
71
|
export const renderAnimatedHeader = (
|
|
71
72
|
animatedHeader: AnimatedHeader | undefined,
|
|
72
|
-
|
|
73
|
+
layoutOffset: number,
|
|
73
74
|
animatedValue: Animated.Value,
|
|
74
75
|
sharedValue: any,
|
|
75
76
|
) => {
|
|
76
77
|
if (typeof animatedHeader?.component === 'function') {
|
|
77
78
|
return (
|
|
78
|
-
<View
|
|
79
|
+
<View
|
|
80
|
+
style={[
|
|
81
|
+
styles.screenBanner,
|
|
82
|
+
{ maxHeight: ANIMATED_BANNER_HEIGHT + layoutOffset },
|
|
83
|
+
]}
|
|
84
|
+
>
|
|
79
85
|
{animatedHeader?.component({
|
|
80
86
|
animatedValue,
|
|
81
87
|
sharedValue,
|
package/Layout/screenFooter.tsx
CHANGED
|
@@ -1,15 +1,50 @@
|
|
|
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 { 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 FooterGeometry = { kind: FooterKind; width: number };
|
|
20
|
+
|
|
21
|
+
type DesignSystemContext = {
|
|
22
|
+
designSystemConfig?: { config?: { footerStyle?: unknown } };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type FooterGeometryInput = {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
contentWidth: number;
|
|
29
|
+
footerStyle: ScreenFooterStyle;
|
|
30
|
+
hasImageBackground: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type FooterLayout = FooterGeometry & {
|
|
34
|
+
hasBorder: boolean;
|
|
35
|
+
insetLeft: number;
|
|
36
|
+
insetRight: number;
|
|
37
|
+
/**
|
|
38
|
+
* Height the sheet overlaps the body by; 0 while the footer sits below the body.
|
|
39
|
+
*/
|
|
40
|
+
overlap: number;
|
|
41
|
+
handleLayout: (event: LayoutChangeEvent) => void;
|
|
42
|
+
};
|
|
43
|
+
|
|
7
44
|
type ScreenFooterProps = {
|
|
8
45
|
footer: ReactNode;
|
|
9
46
|
marginFooter: boolean;
|
|
10
|
-
|
|
11
|
-
insetRight: number;
|
|
12
|
-
hasContentInset: boolean;
|
|
47
|
+
layout: FooterLayout;
|
|
13
48
|
isTab: boolean;
|
|
14
49
|
duoTabInset: number;
|
|
15
50
|
bottomInset: number;
|
|
@@ -17,47 +52,167 @@ type ScreenFooterProps = {
|
|
|
17
52
|
};
|
|
18
53
|
|
|
19
54
|
/**
|
|
20
|
-
*
|
|
21
|
-
|
|
55
|
+
* The screen prop wins over the host's design system config; anything else is `anchored`.
|
|
56
|
+
*/
|
|
57
|
+
const getFooterStyle = (
|
|
58
|
+
footerStyle?: ScreenFooterStyle,
|
|
59
|
+
configured?: unknown,
|
|
60
|
+
): ScreenFooterStyle => {
|
|
61
|
+
if ((footerStyle ?? configured) === 'sheet') {
|
|
62
|
+
return 'sheet';
|
|
63
|
+
}
|
|
64
|
+
return 'anchored';
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
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.
|
|
70
|
+
*/
|
|
71
|
+
const getFooterGeometry = ({
|
|
72
|
+
width,
|
|
73
|
+
height,
|
|
74
|
+
contentWidth,
|
|
75
|
+
footerStyle,
|
|
76
|
+
hasImageBackground,
|
|
77
|
+
}: FooterGeometryInput): FooterGeometry => {
|
|
78
|
+
if (!isFoldableWindow(width, height)) {
|
|
79
|
+
return { kind: 'phone', width: contentWidth };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let maxWidth = FOOTER_MAX_WIDTH;
|
|
83
|
+
if (width >= FOOTER_WIDE_WINDOW_MIN_WIDTH) {
|
|
84
|
+
maxWidth = FOOTER_WIDE_MAX_WIDTH;
|
|
85
|
+
}
|
|
86
|
+
const footerWidth = Math.min(contentWidth - Spacing.M * 2, maxWidth);
|
|
87
|
+
// 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 };
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Footer layout for the screen layout. A sheet overlaps the body, so its measured
|
|
94
|
+
* height comes back as `overlap` for the body to pad its end by.
|
|
95
|
+
*/
|
|
96
|
+
const useFooterLayout = (
|
|
97
|
+
layout: ScreenLayout,
|
|
98
|
+
footerStyle?: ScreenFooterStyle,
|
|
99
|
+
hasImageBackground = false,
|
|
100
|
+
): FooterLayout => {
|
|
101
|
+
const context: DesignSystemContext | undefined = useContext(MiniAppContext);
|
|
102
|
+
const [height, setHeight] = useState(0);
|
|
103
|
+
const handleLayout = useCallback((event: LayoutChangeEvent) => {
|
|
104
|
+
setHeight(event.nativeEvent.layout.height);
|
|
105
|
+
}, []);
|
|
106
|
+
|
|
107
|
+
const configured = context?.designSystemConfig?.config?.footerStyle;
|
|
108
|
+
const geometry = getFooterGeometry({
|
|
109
|
+
width: layout.width,
|
|
110
|
+
height: layout.height,
|
|
111
|
+
contentWidth: layout.contentWidth,
|
|
112
|
+
footerStyle: getFooterStyle(footerStyle, configured),
|
|
113
|
+
hasImageBackground,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
let overlap = 0;
|
|
117
|
+
if (geometry.kind === 'sheet') {
|
|
118
|
+
overlap = height;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
...geometry,
|
|
122
|
+
hasBorder: geometry.kind === 'anchored' && !hasImageBackground,
|
|
123
|
+
insetLeft: layout.insetLeft,
|
|
124
|
+
insetRight: layout.insetRight,
|
|
125
|
+
overlap,
|
|
126
|
+
handleLayout,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Spacer at the end of the body so a sheet footer does not cover its last element.
|
|
132
|
+
*/
|
|
133
|
+
const renderFooterSpacer = (overlap: number) => {
|
|
134
|
+
if (!overlap) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
return <View style={{ height: overlap }} />;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 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`).
|
|
22
144
|
*/
|
|
23
|
-
|
|
145
|
+
const ScreenFooter = ({
|
|
24
146
|
footer,
|
|
25
147
|
marginFooter,
|
|
26
|
-
|
|
27
|
-
insetRight,
|
|
28
|
-
hasContentInset,
|
|
148
|
+
layout,
|
|
29
149
|
isTab,
|
|
30
150
|
duoTabInset,
|
|
31
151
|
bottomInset,
|
|
32
152
|
surfaceColor,
|
|
33
153
|
}: ScreenFooterProps) => {
|
|
154
|
+
const { theme } = useContext(ApplicationContext);
|
|
34
155
|
let bottomSpace = bottomInset;
|
|
35
156
|
if (isTab && duoTabInset) {
|
|
36
157
|
bottomSpace = duoTabInset;
|
|
37
158
|
}
|
|
38
159
|
|
|
160
|
+
const { kind, insetLeft, insetRight } = layout;
|
|
161
|
+
const hasContentInset = insetLeft > 0 || insetRight > 0;
|
|
162
|
+
const margin = marginFooter ? Spacing.M : 0;
|
|
163
|
+
|
|
164
|
+
// one view tree for every kind, so folding keeps the footer content's state
|
|
165
|
+
let containerStyle: StyleProp<ViewStyle> = [
|
|
166
|
+
kind === 'phone' && hasContentInset && styles.footerClip,
|
|
167
|
+
{ marginLeft: insetLeft, marginRight: insetRight },
|
|
168
|
+
];
|
|
169
|
+
let surfaceStyle: StyleProp<ViewStyle> = styles.shadow;
|
|
170
|
+
let sectionMaxWidth: number | undefined;
|
|
171
|
+
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;
|
|
180
|
+
}
|
|
181
|
+
if (kind === 'sheet') {
|
|
182
|
+
containerStyle = [containerStyle, { marginTop: -layout.overlap }];
|
|
183
|
+
surfaceStyle = [styles.footerSheet, { width: layout.width }];
|
|
184
|
+
sectionMaxWidth = layout.width - margin * 2;
|
|
185
|
+
}
|
|
186
|
+
|
|
39
187
|
return (
|
|
40
188
|
<View
|
|
41
189
|
pointerEvents={'box-none'}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
marginLeft: insetLeft,
|
|
46
|
-
marginRight: insetRight,
|
|
47
|
-
},
|
|
48
|
-
]}
|
|
190
|
+
onLayout={layout.handleLayout}
|
|
191
|
+
style={containerStyle}
|
|
49
192
|
>
|
|
50
193
|
<View
|
|
51
194
|
style={[
|
|
52
|
-
|
|
195
|
+
surfaceStyle,
|
|
53
196
|
{
|
|
54
197
|
paddingBottom: bottomSpace + Spacing.S,
|
|
55
198
|
backgroundColor: surfaceColor,
|
|
56
199
|
},
|
|
57
200
|
]}
|
|
58
201
|
>
|
|
59
|
-
<Section useMargin={marginFooter}
|
|
202
|
+
<Section useMargin={marginFooter} maxWidth={sectionMaxWidth}>
|
|
203
|
+
{footer}
|
|
204
|
+
</Section>
|
|
60
205
|
</View>
|
|
61
206
|
</View>
|
|
62
207
|
);
|
|
63
208
|
};
|
|
209
|
+
|
|
210
|
+
export type { FooterLayout };
|
|
211
|
+
|
|
212
|
+
export {
|
|
213
|
+
ScreenFooter,
|
|
214
|
+
getFooterGeometry,
|
|
215
|
+
getFooterStyle,
|
|
216
|
+
renderFooterSpacer,
|
|
217
|
+
useFooterLayout,
|
|
218
|
+
};
|