@momo-kits/foundation 0.169.17-beta.9 → 0.169.17
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/BottomSheet.parts.tsx +4 -4
- package/Application/BottomSheet.tsx +6 -16
- package/Application/Components/HeaderAnimated.tsx +33 -9
- package/Application/Components/HeaderExtendHeader.tsx +28 -18
- package/Application/Components/SearchHeader.tsx +7 -5
- package/Application/ModalIconButton.tsx +13 -15
- package/Application/ModalScreen.tsx +13 -4
- package/Application/__tests__/headerLayout.test.ts +113 -0
- package/Application/headerLayout.ts +114 -30
- package/Application/modalLayout.ts +43 -11
- package/Application/types.header.ts +7 -1
- package/Input/ErrorView.tsx +1 -1
- package/Input/InputMoneyView.tsx +6 -14
- package/Layout/Screen.tsx +12 -14
- package/Layout/Section.tsx +3 -14
- package/Layout/layoutMetrics.ts +2 -2
- package/Layout/screenContent.tsx +4 -10
- package/Layout/screenFooter.tsx +20 -175
- package/Layout/screenHeader.tsx +26 -31
- package/Layout/screenTypes.ts +4 -19
- package/Layout/styles.ts +0 -10
- package/Layout/types.ts +0 -6
- package/Layout/useHeaderBarOptions.ts +54 -0
- package/package.json +1 -1
- package/Layout/__tests__/screenFooter.test.ts +0 -56
|
@@ -120,9 +120,9 @@ type SheetStyleParams = {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
* Sheet container style. On foldables the sheet
|
|
124
|
-
*
|
|
125
|
-
* folded; the keyboard lift comes off its max height.
|
|
123
|
+
* Sheet container style. On foldables the sheet sits at `sheet.x`: centered on
|
|
124
|
+
* the window, clear of the iPhone Duo control column, and on the right half when
|
|
125
|
+
* half folded; the keyboard lift comes off its max height.
|
|
126
126
|
*/
|
|
127
127
|
export const getSheetStyle = ({
|
|
128
128
|
backgroundColor,
|
|
@@ -138,7 +138,7 @@ export const getSheetStyle = ({
|
|
|
138
138
|
if (isFoldable && width !== undefined && maxHeight !== undefined) {
|
|
139
139
|
foldableStyle = {
|
|
140
140
|
width,
|
|
141
|
-
marginLeft: placement.x + (placement.width - width) / 2,
|
|
141
|
+
marginLeft: sheet.x ?? placement.x + (placement.width - width) / 2,
|
|
142
142
|
maxHeight: maxHeight - keyboardLift,
|
|
143
143
|
minHeight: sheet.minHeight,
|
|
144
144
|
};
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
Pressable,
|
|
8
8
|
StyleSheet,
|
|
9
9
|
View,
|
|
10
|
+
ViewStyle,
|
|
10
11
|
} from 'react-native';
|
|
11
12
|
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
12
13
|
import { BottomSheetParams } from './types';
|
|
@@ -190,22 +191,10 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
190
191
|
/>
|
|
191
192
|
);
|
|
192
193
|
|
|
193
|
-
|
|
194
|
+
// same tree on every layout so fold / unfold keeps the screen mounted (state, scroll)
|
|
195
|
+
let contentStyle: ViewStyle | undefined;
|
|
194
196
|
if (isFoldable) {
|
|
195
|
-
|
|
196
|
-
content = (
|
|
197
|
-
<View style={styles.shrink}>
|
|
198
|
-
{renderSheetHeader(headerParams)}
|
|
199
|
-
<View style={styles.shrink}>{screen}</View>
|
|
200
|
-
</View>
|
|
201
|
-
);
|
|
202
|
-
} else {
|
|
203
|
-
content = (
|
|
204
|
-
<>
|
|
205
|
-
{renderSheetHeader(headerParams)}
|
|
206
|
-
{screen}
|
|
207
|
-
</>
|
|
208
|
-
);
|
|
197
|
+
contentStyle = styles.shrink;
|
|
209
198
|
}
|
|
210
199
|
|
|
211
200
|
return (
|
|
@@ -253,7 +242,8 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
253
242
|
}),
|
|
254
243
|
]}
|
|
255
244
|
>
|
|
256
|
-
{
|
|
245
|
+
{renderSheetHeader(headerParams)}
|
|
246
|
+
<View style={contentStyle}>{screen}</View>
|
|
257
247
|
{renderSheetFooter({ footerComponent, theme })}
|
|
258
248
|
{useBottomInset && (
|
|
259
249
|
<View
|
|
@@ -12,6 +12,8 @@ import { Colors } from '../../Consts';
|
|
|
12
12
|
import { useNormalizedSharedValue } from '../hooks';
|
|
13
13
|
import { HeaderBarMetrics, useHeaderLayout } from '../headerLayout';
|
|
14
14
|
|
|
15
|
+
const TRANSPARENT_ALPHA = '00';
|
|
16
|
+
|
|
15
17
|
const ASPECT_RATIOS: Record<
|
|
16
18
|
NonNullable<HeaderAnimatedProps['aspectRatio']>,
|
|
17
19
|
number
|
|
@@ -21,10 +23,30 @@ const ASPECT_RATIOS: Record<
|
|
|
21
23
|
'1/1': 1 / 1,
|
|
22
24
|
};
|
|
23
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Side fill colors behind the centered banner: `gradientColors` (one color fills
|
|
28
|
+
* solid, as LinearGradient needs two), else `backgroundColor` fading to transparent.
|
|
29
|
+
*/
|
|
30
|
+
const getBannerGradientColors = (
|
|
31
|
+
gradientColors?: string[],
|
|
32
|
+
backgroundColor?: string,
|
|
33
|
+
) => {
|
|
34
|
+
if (gradientColors?.length === 1) {
|
|
35
|
+
return [gradientColors[0], gradientColors[0]];
|
|
36
|
+
}
|
|
37
|
+
if (gradientColors?.length) {
|
|
38
|
+
return gradientColors;
|
|
39
|
+
}
|
|
40
|
+
if (backgroundColor) {
|
|
41
|
+
return [backgroundColor, backgroundColor + TRANSPARENT_ALPHA];
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
24
46
|
/**
|
|
25
47
|
* Parallax header image (or `children`): stretches when pulled down and fades out
|
|
26
|
-
* as the content scrolls up. Wide windows and the iPhone Duo inner display
|
|
27
|
-
* it at phone size
|
|
48
|
+
* as the content scrolls up. Wide windows and the iPhone Duo inner display center
|
|
49
|
+
* it at phone size × 1.2 over the side gradient.
|
|
28
50
|
*/
|
|
29
51
|
const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
30
52
|
animatedValue,
|
|
@@ -32,11 +54,16 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
|
32
54
|
useScale = true,
|
|
33
55
|
aspectRatio = '16/9',
|
|
34
56
|
bannerBackgroundColor,
|
|
57
|
+
bannerGradientColors,
|
|
35
58
|
children,
|
|
36
59
|
}) => {
|
|
37
60
|
const sharedValue = useNormalizedSharedValue(animatedValue);
|
|
38
61
|
const { isBannerCentered, bannerWidth } = useHeaderLayout();
|
|
39
62
|
const ratio = ASPECT_RATIOS[aspectRatio];
|
|
63
|
+
const sideColors = getBannerGradientColors(
|
|
64
|
+
bannerGradientColors,
|
|
65
|
+
bannerBackgroundColor,
|
|
66
|
+
);
|
|
40
67
|
const animatedStyle = useAnimatedStyle(() => {
|
|
41
68
|
let scale = 1;
|
|
42
69
|
if (useScale) {
|
|
@@ -88,13 +115,10 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
|
88
115
|
<Animated.View
|
|
89
116
|
style={[styles.container, { height: bannerWidth / ratio }, animatedStyle]}
|
|
90
117
|
>
|
|
91
|
-
{
|
|
92
|
-
<LinearGradient
|
|
93
|
-
colors={[bannerBackgroundColor, bannerBackgroundColor + '00']}
|
|
94
|
-
style={StyleSheet.absoluteFill}
|
|
95
|
-
/>
|
|
118
|
+
{sideColors && (
|
|
119
|
+
<LinearGradient colors={sideColors} style={StyleSheet.absoluteFill} />
|
|
96
120
|
)}
|
|
97
|
-
<View style={styles.
|
|
121
|
+
<View style={styles.centeredBanner}>{content}</View>
|
|
98
122
|
</Animated.View>
|
|
99
123
|
);
|
|
100
124
|
};
|
|
@@ -110,7 +134,7 @@ const styles = StyleSheet.create({
|
|
|
110
134
|
alignSelf: 'center',
|
|
111
135
|
},
|
|
112
136
|
full: { width: '100%', height: '100%' },
|
|
113
|
-
|
|
137
|
+
centeredBanner: {
|
|
114
138
|
width: HeaderBarMetrics.bannerWidth,
|
|
115
139
|
height: '100%',
|
|
116
140
|
alignSelf: 'center',
|
|
@@ -17,7 +17,7 @@ import BackgroundImageView from './BackgroundImageView';
|
|
|
17
17
|
import { type AnimatedCompatValue } from '../utils';
|
|
18
18
|
import { useNormalizedSharedValue } from '../hooks';
|
|
19
19
|
import { useScreenLayout } from '../../Layout';
|
|
20
|
-
import {
|
|
20
|
+
import { getHeaderMargin } from '../../Layout/utils';
|
|
21
21
|
import {
|
|
22
22
|
HeaderBarMetrics,
|
|
23
23
|
type HeaderContentLayout,
|
|
@@ -28,10 +28,12 @@ import { useHeaderRightWidth } from './useHeaderRightWidth';
|
|
|
28
28
|
const { buttonSize, pillWidth, sidePadding, titleGap } = HeaderBarMetrics;
|
|
29
29
|
const SCREEN_PADDING = sidePadding;
|
|
30
30
|
const TOOLKIT_WIDTH = pillWidth + sidePadding;
|
|
31
|
+
// the extended header without search grows this much past the bar until scrolled
|
|
32
|
+
const EXTENDED_HEIGHT_EXTRA = 52;
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* Extended header background: a gradient that collapses on scroll and, with
|
|
34
|
-
* `inputSearchProps`, a
|
|
36
|
+
* `inputSearchProps`, a window-wide search that slides into the bar beside back/toolkit.
|
|
35
37
|
*/
|
|
36
38
|
const HeaderExtendHeader: React.FC<{
|
|
37
39
|
headerType?: HeaderType;
|
|
@@ -44,6 +46,10 @@ const HeaderExtendHeader: React.FC<{
|
|
|
44
46
|
useShadowHeader?: boolean;
|
|
45
47
|
gradientColor?: string;
|
|
46
48
|
headerBackground?: string;
|
|
49
|
+
/**
|
|
50
|
+
* `stretch` keeps the collapsed search beside back and the right cluster in the
|
|
51
|
+
* 600pt frame; the expanded search row spans the window with either layout.
|
|
52
|
+
*/
|
|
47
53
|
contentLayout?: HeaderContentLayout;
|
|
48
54
|
}> = ({
|
|
49
55
|
headerType = 'default',
|
|
@@ -64,8 +70,12 @@ const HeaderExtendHeader: React.FC<{
|
|
|
64
70
|
const headerBackground = customBackground ?? theme.assets?.headerBackground;
|
|
65
71
|
const layout = useScreenLayout();
|
|
66
72
|
const headerLayout = useHeaderLayout(contentLayout);
|
|
67
|
-
//
|
|
68
|
-
|
|
73
|
+
// collapsed into the bar, the search follows back and the right cluster into the
|
|
74
|
+
// frame, or the side margin React Navigation adds on large iOS windows (the larger)
|
|
75
|
+
let frameShift = headerLayout.frameInset - sidePadding;
|
|
76
|
+
if (!layout.sideBar) {
|
|
77
|
+
frameShift = Math.max(frameShift, getHeaderMargin(layout.width));
|
|
78
|
+
}
|
|
69
79
|
|
|
70
80
|
const backLeft = buttonSize + sidePadding + titleGap;
|
|
71
81
|
const defaultLeft = layout.sideBar ? SCREEN_PADDING : backLeft;
|
|
@@ -73,22 +83,22 @@ const HeaderExtendHeader: React.FC<{
|
|
|
73
83
|
const measuredRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
|
|
74
84
|
const defaultRightWidth = layout.sideBar ? 0 : measuredRightWidth;
|
|
75
85
|
const headerRightWidth = customHeaderRightWidth ?? defaultRightWidth;
|
|
76
|
-
const contentLeft = layout.insetLeft + SCREEN_PADDING
|
|
77
|
-
const contentRight = layout.insetLeft + layout.contentWidth
|
|
86
|
+
const contentLeft = layout.insetLeft + SCREEN_PADDING;
|
|
87
|
+
const contentRight = layout.insetLeft + layout.contentWidth;
|
|
78
88
|
// collapsed on the status bar row, the search stays between its clusters
|
|
79
89
|
const clearanceLeft = layout.statusBarClearance?.left ?? 0;
|
|
80
90
|
const clearanceRight = layout.statusBarClearance?.right ?? 0;
|
|
81
|
-
const searchLeft = leftPosition + clearanceLeft
|
|
82
|
-
const collapsedLeft = layout.insetLeft + searchLeft;
|
|
83
|
-
const
|
|
91
|
+
const searchLeft = leftPosition + clearanceLeft;
|
|
92
|
+
const collapsedLeft = layout.insetLeft + searchLeft + frameShift;
|
|
93
|
+
const barRight = contentRight - clearanceRight - frameShift;
|
|
94
|
+
const collapsedRight = barRight - headerRightWidth;
|
|
84
95
|
const searchWidth = contentRight - contentLeft - SCREEN_PADDING;
|
|
85
96
|
const collapsedSearchWidth = collapsedRight - collapsedLeft - SCREEN_PADDING;
|
|
86
|
-
//
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const searchSize = layout.sideBar ? 'default' : 'header';
|
|
97
|
+
// expanded search row under the bar: the search plus its vertical margins
|
|
98
|
+
const searchRowHeight = HeaderBarMetrics.searchBarHeight;
|
|
99
|
+
// a row taller than the search row (iPhone Duo) centers the collapsed search on the title
|
|
100
|
+
const titleRowHeight = heightHeader - layout.headerStatusBarHeight;
|
|
101
|
+
const collapsedRaise = (titleRowHeight - searchRowHeight) / 2;
|
|
92
102
|
|
|
93
103
|
let useShadowHeader = useShadowHeaderProp;
|
|
94
104
|
if (inputSearchProps && Platform.OS === 'android') {
|
|
@@ -101,7 +111,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
101
111
|
height: interpolate(
|
|
102
112
|
sharedValue.value,
|
|
103
113
|
[0, 100],
|
|
104
|
-
[heightHeader +
|
|
114
|
+
[heightHeader + searchRowHeight, heightHeader],
|
|
105
115
|
Extrapolation.CLAMP,
|
|
106
116
|
),
|
|
107
117
|
}));
|
|
@@ -154,7 +164,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
154
164
|
height: interpolate(
|
|
155
165
|
sharedValue.value,
|
|
156
166
|
[0, 100],
|
|
157
|
-
[heightHeader +
|
|
167
|
+
[heightHeader + EXTENDED_HEIGHT_EXTRA, heightHeader],
|
|
158
168
|
Extrapolation.CLAMP,
|
|
159
169
|
),
|
|
160
170
|
}));
|
|
@@ -215,7 +225,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
215
225
|
<InputSearch
|
|
216
226
|
{...inputSearchProps}
|
|
217
227
|
ref={inputSearchRef}
|
|
218
|
-
size={
|
|
228
|
+
size={'header'}
|
|
219
229
|
backgroundColor={'transparent'}
|
|
220
230
|
showButtonText={false}
|
|
221
231
|
/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Colors, Radius, Spacing, Styles } from '../../Consts';
|
|
2
|
-
import { InputRef, InputSearch
|
|
2
|
+
import { InputRef, InputSearch } from '../../Input';
|
|
3
3
|
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
4
4
|
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
5
5
|
import React, { useContext } from 'react';
|
|
@@ -8,6 +8,7 @@ import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
|
8
8
|
import { Text } from '../../Text';
|
|
9
9
|
import { useNormalizedSharedValue } from '../hooks';
|
|
10
10
|
import { useScreenLayout } from '../../Layout';
|
|
11
|
+
import { getHeaderMargin } from '../../Layout/utils';
|
|
11
12
|
import { HeaderBarMetrics } from '../headerLayout';
|
|
12
13
|
import { useHeaderRightWidth } from './useHeaderRightWidth';
|
|
13
14
|
|
|
@@ -36,10 +37,8 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
36
37
|
const context = useContext<any>(MiniAppContext);
|
|
37
38
|
const layout = useScreenLayout();
|
|
38
39
|
let defaultRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
|
|
39
|
-
let searchSize: InputSearchProps['size'] = 'header';
|
|
40
40
|
if (layout.sideBar) {
|
|
41
41
|
defaultRightWidth = DUO_TOOLKIT_WIDTH;
|
|
42
|
-
searchSize = 'default';
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
const sharedValue = useNormalizedSharedValue(animatedValue);
|
|
@@ -48,7 +47,10 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
48
47
|
const headerRightWidth = props?.headerRightWidth ?? defaultRightWidth;
|
|
49
48
|
|
|
50
49
|
// iPhone Duo side bar holds back: the search shares the content width with the buttons only
|
|
51
|
-
|
|
50
|
+
// large iOS windows: React Navigation narrows the header row by a margin each side
|
|
51
|
+
const headerMargin = getHeaderMargin(layout.width);
|
|
52
|
+
const rowWidth =
|
|
53
|
+
layout.width - leftPosition - sidePadding - headerMargin * 2;
|
|
52
54
|
let searchMaxWidth = rowWidth - headerRightWidth;
|
|
53
55
|
if (layout.sideBar) {
|
|
54
56
|
searchMaxWidth = layout.contentWidth - Spacing.M * 2 - headerRightWidth;
|
|
@@ -118,7 +120,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
118
120
|
<InputSearch
|
|
119
121
|
ref={ref}
|
|
120
122
|
{...props}
|
|
121
|
-
size={
|
|
123
|
+
size={'header'}
|
|
122
124
|
backgroundColor={'transparent'}
|
|
123
125
|
showButtonText={false}
|
|
124
126
|
/>
|
|
@@ -6,12 +6,14 @@ import {
|
|
|
6
6
|
ViewStyle,
|
|
7
7
|
} from 'react-native';
|
|
8
8
|
import { ApplicationContext } from '../Context';
|
|
9
|
-
import {
|
|
9
|
+
import { Colors } from '../Consts';
|
|
10
10
|
import { Icon } from '../Icon';
|
|
11
|
+
import { HeaderBarMetrics } from './headerLayout';
|
|
11
12
|
|
|
12
|
-
//
|
|
13
|
-
const MODAL_ICON_BUTTON_SIZE =
|
|
14
|
-
const MODAL_ICON_SIZE =
|
|
13
|
+
// same round button as the Top nav (NavigationButton), shared with the Compose / SwiftUI kits
|
|
14
|
+
const MODAL_ICON_BUTTON_SIZE = HeaderBarMetrics.buttonSize;
|
|
15
|
+
const MODAL_ICON_SIZE = HeaderBarMetrics.iconSize;
|
|
16
|
+
const MODAL_ICON_BUTTON_BORDER_WIDTH = 0.2;
|
|
15
17
|
|
|
16
18
|
type ModalIconButtonProps = {
|
|
17
19
|
icon: string;
|
|
@@ -21,7 +23,8 @@ type ModalIconButtonProps = {
|
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
|
-
* Close / back button of popups and bottom sheet headers
|
|
26
|
+
* Close / back button of popups and bottom sheet headers, drawn like the round
|
|
27
|
+
* Top nav icon button so modals and headers share one look.
|
|
25
28
|
*/
|
|
26
29
|
const ModalIconButton: React.FC<ModalIconButtonProps> = ({
|
|
27
30
|
icon,
|
|
@@ -34,14 +37,7 @@ const ModalIconButton: React.FC<ModalIconButtonProps> = ({
|
|
|
34
37
|
<TouchableOpacity
|
|
35
38
|
accessibilityLabel={accessibilityLabel}
|
|
36
39
|
onPress={onPress}
|
|
37
|
-
style={[
|
|
38
|
-
styles.button,
|
|
39
|
-
{
|
|
40
|
-
backgroundColor: theme.colors.background.surface,
|
|
41
|
-
borderColor: theme.colors.border.default,
|
|
42
|
-
},
|
|
43
|
-
style,
|
|
44
|
-
]}
|
|
40
|
+
style={[styles.button, style]}
|
|
45
41
|
>
|
|
46
42
|
<Icon
|
|
47
43
|
source={icon}
|
|
@@ -56,10 +52,12 @@ const styles = StyleSheet.create({
|
|
|
56
52
|
button: {
|
|
57
53
|
width: MODAL_ICON_BUTTON_SIZE,
|
|
58
54
|
height: MODAL_ICON_BUTTON_SIZE,
|
|
59
|
-
borderRadius:
|
|
60
|
-
borderWidth:
|
|
55
|
+
borderRadius: MODAL_ICON_BUTTON_SIZE / 2,
|
|
56
|
+
borderWidth: MODAL_ICON_BUTTON_BORDER_WIDTH,
|
|
61
57
|
alignItems: 'center',
|
|
62
58
|
justifyContent: 'center',
|
|
59
|
+
backgroundColor: Colors.black_01 + '99',
|
|
60
|
+
borderColor: Colors.black_20 + '33',
|
|
63
61
|
},
|
|
64
62
|
});
|
|
65
63
|
|
|
@@ -46,7 +46,8 @@ const ModalScreen: React.FC<any> = props => {
|
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Centered popup that fades and scales in over a scrim. On foldables it is
|
|
49
|
-
* centered
|
|
49
|
+
* centered on the window (`popup.x`), clear of the iPhone Duo control column,
|
|
50
|
+
* at most a popup wide.
|
|
50
51
|
*/
|
|
51
52
|
const Modal: React.FC<ModalParams> = props => {
|
|
52
53
|
const { navigator } = useContext(ApplicationContext);
|
|
@@ -156,6 +157,14 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
156
157
|
return () => backHandler.remove();
|
|
157
158
|
}, [barrierDismissible, handleDismiss]);
|
|
158
159
|
|
|
160
|
+
// popup.x centers it on the window; without it, centered in the placement
|
|
161
|
+
let popupLeft = placement.x;
|
|
162
|
+
let popupRight = width - placement.x - placement.width;
|
|
163
|
+
if (popup.x !== undefined) {
|
|
164
|
+
popupLeft = popup.x;
|
|
165
|
+
popupRight = Math.max(width - popup.x - popup.width, 0);
|
|
166
|
+
}
|
|
167
|
+
|
|
159
168
|
return (
|
|
160
169
|
<Container
|
|
161
170
|
transparent
|
|
@@ -181,13 +190,13 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
181
190
|
opacity,
|
|
182
191
|
transform: [{ scale }],
|
|
183
192
|
},
|
|
184
|
-
// centered
|
|
193
|
+
// centered on the window at popup.x, clear of the control column, at most a popup wide
|
|
185
194
|
isFoldable && styles.shrink,
|
|
186
195
|
isFoldable && {
|
|
187
196
|
marginTop: placement.y,
|
|
188
197
|
marginBottom: height - placement.y - placement.height,
|
|
189
|
-
marginLeft:
|
|
190
|
-
marginRight:
|
|
198
|
+
marginLeft: popupLeft,
|
|
199
|
+
marginRight: popupRight,
|
|
191
200
|
maxWidth: popup.width,
|
|
192
201
|
maxHeight: popup.maxHeight,
|
|
193
202
|
},
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getHeaderFrameOptions,
|
|
3
|
+
getHeaderLayout,
|
|
4
|
+
getSearchHeaderHeight,
|
|
5
|
+
HeaderBarMetrics,
|
|
6
|
+
} from '../headerLayout';
|
|
7
|
+
|
|
8
|
+
const PHONE = { width: 375, height: 812 };
|
|
9
|
+
const FOLD_INNER = { width: 760, height: 840 };
|
|
10
|
+
const DUO_INNER = { width: 932, height: 678 };
|
|
11
|
+
|
|
12
|
+
describe('getHeaderLayout', () => {
|
|
13
|
+
it('keeps the phone row at the bar edges with a full-width banner', () => {
|
|
14
|
+
const layout = getHeaderLayout({ ...PHONE, isDuo: false });
|
|
15
|
+
expect(layout.isWide).toBe(false);
|
|
16
|
+
expect(layout.isBannerCentered).toBe(false);
|
|
17
|
+
expect(layout.bannerScale).toBe(1);
|
|
18
|
+
expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
|
|
19
|
+
expect(layout.frameWidth).toBe(351);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('keeps the grid row at the bar edges on a 760 window', () => {
|
|
23
|
+
const layout = getHeaderLayout({ ...FOLD_INNER, isDuo: false });
|
|
24
|
+
expect(layout.isWide).toBe(true);
|
|
25
|
+
expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
|
|
26
|
+
expect(layout.frameWidth).toBe(736);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('centers the stretch row in the 600 frame on a 760 window', () => {
|
|
30
|
+
const input = { ...FOLD_INNER, isDuo: false };
|
|
31
|
+
const layout = getHeaderLayout({ ...input, contentLayout: 'stretch' });
|
|
32
|
+
expect(layout.frameInset).toBe(80);
|
|
33
|
+
expect(layout.frameWidth).toBe(600);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('scales the centered banner to 450 on a 760 window', () => {
|
|
37
|
+
const layout = getHeaderLayout({ ...FOLD_INNER, isDuo: false });
|
|
38
|
+
expect(layout.isBannerCentered).toBe(true);
|
|
39
|
+
expect(layout.bannerScale).toBe(1.2);
|
|
40
|
+
expect(layout.bannerWidth).toBe(450);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('centers the banner on the iPhone Duo inner display, without the frame', () => {
|
|
44
|
+
const input = { ...DUO_INNER, isDuo: true };
|
|
45
|
+
const layout = getHeaderLayout({ ...input, contentLayout: 'stretch' });
|
|
46
|
+
expect(layout.isWide).toBe(false);
|
|
47
|
+
expect(layout.isBannerCentered).toBe(true);
|
|
48
|
+
expect(layout.bannerScale).toBe(1.2);
|
|
49
|
+
expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('getSearchHeaderHeight', () => {
|
|
54
|
+
it('grows a 48 bar row to the 56 search row', () => {
|
|
55
|
+
expect(getSearchHeaderHeight(48 + 47, 47)).toBe(56 + 47);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('keeps a row taller than the search row', () => {
|
|
59
|
+
expect(getSearchHeaderHeight(72, 0)).toBe(72);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('getHeaderFrameOptions', () => {
|
|
64
|
+
const NO_EDGE = { left: 0, right: 0 };
|
|
65
|
+
const DUO_EDGE = { left: 60, right: 90 };
|
|
66
|
+
const frameInput = (contentLayout?: 'grid' | 'stretch') => {
|
|
67
|
+
const layout = getHeaderLayout({
|
|
68
|
+
...FOLD_INNER,
|
|
69
|
+
isDuo: false,
|
|
70
|
+
contentLayout,
|
|
71
|
+
});
|
|
72
|
+
return { layout, isDuo: false, headerMargin: 0, edgePadding: NO_EDGE };
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
it('leaves the options alone when contentLayout is unset', () => {
|
|
76
|
+
expect(getHeaderFrameOptions(frameInput())).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('pulls the stretch row into the 600 frame on a 760 window', () => {
|
|
80
|
+
const options = getHeaderFrameOptions({
|
|
81
|
+
...frameInput('stretch'),
|
|
82
|
+
contentLayout: 'stretch',
|
|
83
|
+
});
|
|
84
|
+
expect(options?.headerLeftContainerStyle).toEqual({ paddingLeft: 68 });
|
|
85
|
+
expect(options?.headerRightContainerStyle).toEqual({ paddingRight: 68 });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('resets grid to the bar edges, so a former stretch frame does not stay', () => {
|
|
89
|
+
const options = getHeaderFrameOptions({
|
|
90
|
+
...frameInput('grid'),
|
|
91
|
+
contentLayout: 'grid',
|
|
92
|
+
});
|
|
93
|
+
expect(options?.headerLeftContainerStyle).toEqual({ paddingLeft: 0 });
|
|
94
|
+
expect(options?.headerRightContainerStyle).toEqual({ paddingRight: 0 });
|
|
95
|
+
expect(options?.headerTitleContainerStyle).toMatchObject({
|
|
96
|
+
left: HeaderBarMetrics.titleGap,
|
|
97
|
+
});
|
|
98
|
+
expect(options?.headerTitleContainerStyle).not.toHaveProperty('maxWidth');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('keeps the iPhone Duo status bar clearance with stretch', () => {
|
|
102
|
+
const layout = getHeaderLayout({ ...DUO_INNER, isDuo: true });
|
|
103
|
+
const options = getHeaderFrameOptions({
|
|
104
|
+
layout,
|
|
105
|
+
isDuo: true,
|
|
106
|
+
headerMargin: 0,
|
|
107
|
+
edgePadding: DUO_EDGE,
|
|
108
|
+
contentLayout: 'stretch',
|
|
109
|
+
});
|
|
110
|
+
expect(options?.headerLeftContainerStyle).toEqual({ paddingLeft: 60 });
|
|
111
|
+
expect(options?.headerRightContainerStyle).toEqual({ paddingRight: 90 });
|
|
112
|
+
});
|
|
113
|
+
});
|