@momo-kits/foundation 0.169.17-beta.7 → 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/modalLayout.ts +12 -4
- package/Input/CountryCodeView.tsx +93 -0
- package/Input/InputPhoneNumber.tsx +20 -38
- package/Input/InputSearch.tsx +3 -10
- package/Input/index.tsx +14 -1
- package/Layout/FloatingButton.tsx +1 -8
- package/Layout/Screen.tsx +11 -5
- package/Layout/Section.tsx +14 -3
- package/Layout/__tests__/screenFooter.test.ts +56 -0
- package/Layout/screenFooter.tsx +175 -20
- package/Layout/screenTypes.ts +16 -1
- package/Layout/styles.ts +10 -0
- package/Layout/types.ts +6 -0
- package/package.json +1 -1
|
@@ -78,6 +78,14 @@ const clamp = (value: number, min: number, max: number) => {
|
|
|
78
78
|
return Math.min(Math.max(value, min), max);
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* True when the window's short side reaches a foldable inner display (Galaxy Z Fold,
|
|
83
|
+
* Pixel Fold, iPhone Duo inner); short side, so a phone in landscape stays a phone.
|
|
84
|
+
*/
|
|
85
|
+
const isFoldableWindow = (width: number, height: number) => {
|
|
86
|
+
return Math.min(width, height) >= FOLDABLE_MIN_WIDTH;
|
|
87
|
+
};
|
|
88
|
+
|
|
81
89
|
/**
|
|
82
90
|
* Modal geometry for a window, pure so it can be tested without a device.
|
|
83
91
|
*/
|
|
@@ -88,10 +96,9 @@ const getModalLayout = ({
|
|
|
88
96
|
isDuo,
|
|
89
97
|
hinge,
|
|
90
98
|
}: ModalLayoutInput): ModalLayout => {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
const isDuoOuter = isDuo && shortSide < FOLDABLE_MIN_WIDTH;
|
|
99
|
+
const isWideWindow = isFoldableWindow(width, height);
|
|
100
|
+
const isFoldable = isDuo || isWideWindow;
|
|
101
|
+
const isDuoOuter = isDuo && !isWideWindow;
|
|
95
102
|
const hingeRight = hinge ? hinge.x + hinge.width : 0;
|
|
96
103
|
const hasHinge = !!hinge && hinge.x > 0;
|
|
97
104
|
const isHingeInWindow = hingeRight < width - insets.right;
|
|
@@ -166,6 +173,7 @@ const useModalLayout = (): ModalLayout => {
|
|
|
166
173
|
|
|
167
174
|
export {
|
|
168
175
|
getModalLayout,
|
|
176
|
+
isFoldableWindow,
|
|
169
177
|
useModalLayout,
|
|
170
178
|
POPUP_MAX_WIDTH,
|
|
171
179
|
POPUP_MIN_WIDTH,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import { Colors, Spacing, Styles } from '../Consts';
|
|
4
|
+
import { Image } from '../Image';
|
|
5
|
+
import { Text } from '../Text';
|
|
6
|
+
import { Typography } from '../Text/types';
|
|
7
|
+
import styles from './styles';
|
|
8
|
+
|
|
9
|
+
const FLAG_SIZE = 24;
|
|
10
|
+
|
|
11
|
+
type CountryCodeViewProps = {
|
|
12
|
+
countryCode: string;
|
|
13
|
+
countryFlag: string;
|
|
14
|
+
typography: Typography;
|
|
15
|
+
textColor: string;
|
|
16
|
+
dividerHeight: number;
|
|
17
|
+
componentId: string;
|
|
18
|
+
isDisabled: boolean;
|
|
19
|
+
onPress?: () => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Flag, dial code and divider ahead of a phone number. Only becomes a button
|
|
24
|
+
* when `onPress` is given, so the default render stays a plain view.
|
|
25
|
+
*/
|
|
26
|
+
const CountryCodeView: React.FC<CountryCodeViewProps> = ({
|
|
27
|
+
countryCode,
|
|
28
|
+
countryFlag,
|
|
29
|
+
typography,
|
|
30
|
+
textColor,
|
|
31
|
+
dividerHeight,
|
|
32
|
+
componentId,
|
|
33
|
+
isDisabled,
|
|
34
|
+
onPress,
|
|
35
|
+
}) => {
|
|
36
|
+
const content = (
|
|
37
|
+
<>
|
|
38
|
+
<Image
|
|
39
|
+
source={{ uri: countryFlag }}
|
|
40
|
+
style={innerStyle.iconFlag}
|
|
41
|
+
resizeMode="contain"
|
|
42
|
+
accessibilityLabel={`${componentId}|leading-icon`}
|
|
43
|
+
/>
|
|
44
|
+
<View style={{ width: Spacing.XS }} />
|
|
45
|
+
<Text typography={typography} color={textColor}>
|
|
46
|
+
{countryCode}
|
|
47
|
+
</Text>
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const renderContent = () => {
|
|
52
|
+
if (!onPress) {
|
|
53
|
+
return content;
|
|
54
|
+
}
|
|
55
|
+
return (
|
|
56
|
+
<TouchableOpacity
|
|
57
|
+
style={Styles.row}
|
|
58
|
+
onPress={onPress}
|
|
59
|
+
disabled={isDisabled}
|
|
60
|
+
accessibilityRole="button"
|
|
61
|
+
accessibilityLabel={`${componentId}|leading-icon-touch|${countryCode}`}
|
|
62
|
+
accessibilityState={{ disabled: isDisabled }}
|
|
63
|
+
>
|
|
64
|
+
{content}
|
|
65
|
+
</TouchableOpacity>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<View style={[styles.leadingIconContainer, Styles.row]}>
|
|
71
|
+
{renderContent()}
|
|
72
|
+
<View
|
|
73
|
+
style={[
|
|
74
|
+
styles.phoneNumberDivider,
|
|
75
|
+
{
|
|
76
|
+
height: dividerHeight,
|
|
77
|
+
backgroundColor: Colors.black_04,
|
|
78
|
+
},
|
|
79
|
+
]}
|
|
80
|
+
/>
|
|
81
|
+
</View>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const innerStyle = StyleSheet.create({
|
|
86
|
+
iconFlag: {
|
|
87
|
+
width: FLAG_SIZE,
|
|
88
|
+
height: FLAG_SIZE,
|
|
89
|
+
marginHorizontal: Spacing.XXS,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export { CountryCodeView };
|
|
@@ -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/InputSearch.tsx
CHANGED
|
@@ -33,7 +33,6 @@ const SEARCH_ICON_SIZE = 24;
|
|
|
33
33
|
/**
|
|
34
34
|
* Search field with search icon, clear icon, optional trailing icon and a
|
|
35
35
|
* cancel button; with `typingData` it shows an animated placeholder instead.
|
|
36
|
-
* Deprecated `icon*` props fall back into the `trailing*` ones.
|
|
37
36
|
*/
|
|
38
37
|
const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
39
38
|
{
|
|
@@ -41,12 +40,9 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
|
41
40
|
onFocus,
|
|
42
41
|
onBlur,
|
|
43
42
|
value,
|
|
44
|
-
trailing
|
|
45
|
-
trailingColor
|
|
46
|
-
onPressTrailing
|
|
47
|
-
icon,
|
|
48
|
-
iconColor,
|
|
49
|
-
onPressIcon,
|
|
43
|
+
trailing,
|
|
44
|
+
trailingColor,
|
|
45
|
+
onPressTrailing,
|
|
50
46
|
onChangeText,
|
|
51
47
|
buttonText = 'Hủy',
|
|
52
48
|
showButtonText = true,
|
|
@@ -63,9 +59,6 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
|
63
59
|
ref,
|
|
64
60
|
) => {
|
|
65
61
|
const { theme } = useContext(ApplicationContext);
|
|
66
|
-
const trailing = trailingProp ?? icon;
|
|
67
|
-
const trailingColor = trailingColorProp ?? iconColor;
|
|
68
|
-
const onPressTrailing = onPressTrailingProp ?? onPressIcon;
|
|
69
62
|
const context = useContext<any>(MiniAppContext);
|
|
70
63
|
const scaledFontSize = useScaleSize(INPUT_FONT_SIZE);
|
|
71
64
|
const searchFontFamily = exportFontFamily('regular');
|
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 = {
|
|
@@ -75,12 +75,6 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
75
75
|
opacityAnimated.value = withTiming(1, { duration: ANIMATION_DURATION });
|
|
76
76
|
}, [label, opacityAnimated]);
|
|
77
77
|
|
|
78
|
-
// Re-measure the expanded width when the label or its scaled size changes.
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
if (lastDirection.value === 'down') return;
|
|
81
|
-
widthAnimated.value = null;
|
|
82
|
-
}, [label, scaledFontSize, lastDirection, widthAnimated]);
|
|
83
|
-
|
|
84
78
|
useAnimatedReaction(
|
|
85
79
|
() => sharedValue.value,
|
|
86
80
|
value => {
|
|
@@ -121,8 +115,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
121
115
|
);
|
|
122
116
|
|
|
123
117
|
const containerStyle = useAnimatedStyle(() => ({
|
|
124
|
-
|
|
125
|
-
width: widthAnimated.value ?? 'auto',
|
|
118
|
+
width: widthAnimated.value ?? undefined,
|
|
126
119
|
}));
|
|
127
120
|
|
|
128
121
|
const labelStyle = useAnimatedStyle(() => ({
|
package/Layout/Screen.tsx
CHANGED
|
@@ -31,7 +31,11 @@ import { BottomTabInsetContext } from '../Application/BottomTab/BottomTabInset';
|
|
|
31
31
|
import { ScreenProps } from './screenTypes';
|
|
32
32
|
import { renderAnimatedHeader, renderContent } from './screenContent';
|
|
33
33
|
import { createScrollHandlers } from './screenScroll';
|
|
34
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
renderFooterSpacer,
|
|
36
|
+
ScreenFooter,
|
|
37
|
+
useFooterLayout,
|
|
38
|
+
} from './screenFooter';
|
|
35
39
|
import { useScreenHeader } from './screenHeader';
|
|
36
40
|
import { useScreenQuickReturn } from './screenQuickReturn';
|
|
37
41
|
|
|
@@ -53,6 +57,8 @@ const Screen = forwardRef(
|
|
|
53
57
|
headerComponent: Header,
|
|
54
58
|
footerComponent: Footer,
|
|
55
59
|
marginFooter = true,
|
|
60
|
+
footerStyle,
|
|
61
|
+
footerHasImageBackground: hasImageFooter,
|
|
56
62
|
layoutOffset = -56,
|
|
57
63
|
headerRightWidth,
|
|
58
64
|
backgroundColor,
|
|
@@ -78,6 +84,7 @@ const Screen = forwardRef(
|
|
|
78
84
|
const insets = useSafeAreaInsets();
|
|
79
85
|
const frame = useSafeAreaFrame();
|
|
80
86
|
const heightHeader = useHeaderHeight();
|
|
87
|
+
const footerLayout = useFooterLayout(layout, footerStyle, hasImageFooter);
|
|
81
88
|
|
|
82
89
|
const animatedValue = useRef<Animated.Value>(
|
|
83
90
|
customAnimatedValue ?? new Animated.Value(0),
|
|
@@ -195,7 +202,7 @@ const Screen = forwardRef(
|
|
|
195
202
|
|
|
196
203
|
let floatingButtonBottom = bottomInset + Spacing.S;
|
|
197
204
|
if (Footer) {
|
|
198
|
-
floatingButtonBottom = 12;
|
|
205
|
+
floatingButtonBottom = 12 + footerLayout.overlap;
|
|
199
206
|
} else if (isTab) {
|
|
200
207
|
floatingButtonBottom = 12 + duoTabInset;
|
|
201
208
|
}
|
|
@@ -285,6 +292,7 @@ const Screen = forwardRef(
|
|
|
285
292
|
)}
|
|
286
293
|
|
|
287
294
|
{useGridLayout ? renderContent(children, layout) : children}
|
|
295
|
+
{renderFooterSpacer(footerLayout.overlap)}
|
|
288
296
|
</Component>
|
|
289
297
|
|
|
290
298
|
{floatingButtonProps && (
|
|
@@ -306,9 +314,7 @@ const Screen = forwardRef(
|
|
|
306
314
|
<ScreenFooter
|
|
307
315
|
footer={Footer}
|
|
308
316
|
marginFooter={marginFooter}
|
|
309
|
-
|
|
310
|
-
insetRight={layout.insetRight}
|
|
311
|
-
hasContentInset={hasContentInset}
|
|
317
|
+
layout={footerLayout}
|
|
312
318
|
isTab={isTab}
|
|
313
319
|
duoTabInset={duoTabInset}
|
|
314
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/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
|
+
};
|
package/Layout/screenTypes.ts
CHANGED
|
@@ -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, ScreenFooterStyle } from './types';
|
|
11
11
|
import { InputRef } from '../Input';
|
|
12
12
|
import type { HeaderContentLayout } from '../Application/headerLayout';
|
|
13
13
|
|
|
@@ -65,6 +65,21 @@ 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 border, 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. 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.
|
|
79
|
+
* Defaults to `false`.
|
|
80
|
+
*/
|
|
81
|
+
footerHasImageBackground?: boolean;
|
|
82
|
+
|
|
68
83
|
/**
|
|
69
84
|
* Optional. Background color of the screen.
|
|
70
85
|
*/
|
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,12 @@ 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 border, `sheet` a centered sheet over the body.
|
|
8
|
+
*/
|
|
9
|
+
export type ScreenFooterStyle = 'anchored' | 'sheet';
|
|
10
|
+
|
|
5
11
|
export type ScreenRef = {
|
|
6
12
|
/**
|
|
7
13
|
* Applies navigation options to the screen's header.
|