@momo-kits/foundation 0.169.17-beta.3 → 0.169.17-beta.5
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.
|
@@ -120,9 +120,9 @@ type SheetStyleParams = {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
* Sheet container style. On foldables the sheet
|
|
124
|
-
*
|
|
125
|
-
*
|
|
123
|
+
* Sheet container style. On foldables the sheet is centered in the placement
|
|
124
|
+
* area, clear of the iPhone Duo control column and on the right half when half
|
|
125
|
+
* 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:
|
|
141
|
+
marginLeft: placement.x + (placement.width - width) / 2,
|
|
142
142
|
maxHeight: maxHeight - keyboardLift,
|
|
143
143
|
minHeight: sheet.minHeight,
|
|
144
144
|
};
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
Pressable,
|
|
8
8
|
StyleSheet,
|
|
9
9
|
View,
|
|
10
|
-
ViewStyle,
|
|
11
10
|
} from 'react-native';
|
|
12
11
|
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
13
12
|
import { BottomSheetParams } from './types';
|
|
@@ -191,10 +190,22 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
191
190
|
/>
|
|
192
191
|
);
|
|
193
192
|
|
|
194
|
-
|
|
195
|
-
let contentStyle: ViewStyle | undefined;
|
|
193
|
+
let content: React.ReactNode;
|
|
196
194
|
if (isFoldable) {
|
|
197
|
-
|
|
195
|
+
// Content shrinks so a tall sheet keeps its header and footer.
|
|
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
|
+
);
|
|
198
209
|
}
|
|
199
210
|
|
|
200
211
|
return (
|
|
@@ -242,8 +253,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
242
253
|
}),
|
|
243
254
|
]}
|
|
244
255
|
>
|
|
245
|
-
{
|
|
246
|
-
<View style={contentStyle}>{screen}</View>
|
|
256
|
+
{content}
|
|
247
257
|
{renderSheetFooter({ footerComponent, theme })}
|
|
248
258
|
{useBottomInset && (
|
|
249
259
|
<View
|
|
@@ -6,14 +6,12 @@ import {
|
|
|
6
6
|
ViewStyle,
|
|
7
7
|
} from 'react-native';
|
|
8
8
|
import { ApplicationContext } from '../Context';
|
|
9
|
-
import {
|
|
9
|
+
import { Radius, Spacing } from '../Consts';
|
|
10
10
|
import { Icon } from '../Icon';
|
|
11
|
-
import { HeaderBarMetrics } from './headerLayout';
|
|
12
11
|
|
|
13
|
-
//
|
|
14
|
-
const MODAL_ICON_BUTTON_SIZE =
|
|
15
|
-
const MODAL_ICON_SIZE =
|
|
16
|
-
const MODAL_ICON_BUTTON_BORDER_WIDTH = 0.2;
|
|
12
|
+
// modal spec: icon button 32, icon 20, shared with the Compose / SwiftUI kits
|
|
13
|
+
const MODAL_ICON_BUTTON_SIZE = Spacing.XXL;
|
|
14
|
+
const MODAL_ICON_SIZE = 20;
|
|
17
15
|
|
|
18
16
|
type ModalIconButtonProps = {
|
|
19
17
|
icon: string;
|
|
@@ -23,8 +21,7 @@ type ModalIconButtonProps = {
|
|
|
23
21
|
};
|
|
24
22
|
|
|
25
23
|
/**
|
|
26
|
-
* Close / back button of popups and bottom sheet headers
|
|
27
|
-
* Top nav icon button so modals and headers share one look.
|
|
24
|
+
* Close / back button of popups and bottom sheet headers
|
|
28
25
|
*/
|
|
29
26
|
const ModalIconButton: React.FC<ModalIconButtonProps> = ({
|
|
30
27
|
icon,
|
|
@@ -37,7 +34,14 @@ const ModalIconButton: React.FC<ModalIconButtonProps> = ({
|
|
|
37
34
|
<TouchableOpacity
|
|
38
35
|
accessibilityLabel={accessibilityLabel}
|
|
39
36
|
onPress={onPress}
|
|
40
|
-
style={[
|
|
37
|
+
style={[
|
|
38
|
+
styles.button,
|
|
39
|
+
{
|
|
40
|
+
backgroundColor: theme.colors.background.surface,
|
|
41
|
+
borderColor: theme.colors.border.default,
|
|
42
|
+
},
|
|
43
|
+
style,
|
|
44
|
+
]}
|
|
41
45
|
>
|
|
42
46
|
<Icon
|
|
43
47
|
source={icon}
|
|
@@ -52,12 +56,10 @@ const styles = StyleSheet.create({
|
|
|
52
56
|
button: {
|
|
53
57
|
width: MODAL_ICON_BUTTON_SIZE,
|
|
54
58
|
height: MODAL_ICON_BUTTON_SIZE,
|
|
55
|
-
borderRadius:
|
|
56
|
-
borderWidth:
|
|
59
|
+
borderRadius: Radius.L,
|
|
60
|
+
borderWidth: 1,
|
|
57
61
|
alignItems: 'center',
|
|
58
62
|
justifyContent: 'center',
|
|
59
|
-
backgroundColor: Colors.black_01 + '99',
|
|
60
|
-
borderColor: Colors.black_20 + '33',
|
|
61
63
|
},
|
|
62
64
|
});
|
|
63
65
|
|
|
@@ -41,13 +41,50 @@ const ModalScreen: React.FC<any> = props => {
|
|
|
41
41
|
if (props.route?.params?.isBottomSheet) {
|
|
42
42
|
return <BottomSheet {...props} />;
|
|
43
43
|
}
|
|
44
|
+
if (props.route?.params?.fullScreen) {
|
|
45
|
+
return <FullScreenModal {...props} />;
|
|
46
|
+
}
|
|
44
47
|
return <Modal {...props} />;
|
|
45
48
|
};
|
|
46
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Edge to edge layer for overlays that draw their own scrim (e.g. Coachmark):
|
|
52
|
+
* no scrim, no animation, Android back is swallowed; the screen closes itself.
|
|
53
|
+
*/
|
|
54
|
+
const FullScreenModal: React.FC<ModalParams> = props => {
|
|
55
|
+
const { screen, onDismiss } = props.route.params;
|
|
56
|
+
const Component = useRef(screen).current;
|
|
57
|
+
const params = { ...props.route.params };
|
|
58
|
+
delete params.screen;
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
return () => {
|
|
62
|
+
onDismiss?.();
|
|
63
|
+
};
|
|
64
|
+
}, [onDismiss]);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const backHandler = BackHandler.addEventListener(
|
|
68
|
+
'hardwareBackPress',
|
|
69
|
+
() => true,
|
|
70
|
+
);
|
|
71
|
+
return () => backHandler.remove();
|
|
72
|
+
}, []);
|
|
73
|
+
|
|
74
|
+
const handleClose = useCallback(() => {
|
|
75
|
+
props.navigation.goBack();
|
|
76
|
+
}, [props.navigation]);
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<View style={StyleSheet.absoluteFillObject}>
|
|
80
|
+
<Component {...params} onRequestClose={handleClose} />
|
|
81
|
+
</View>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
47
85
|
/**
|
|
48
86
|
* Centered popup that fades and scales in over a scrim. On foldables it is
|
|
49
|
-
* centered
|
|
50
|
-
* at most a popup wide.
|
|
87
|
+
* centered in the modal placement area, at most a popup wide.
|
|
51
88
|
*/
|
|
52
89
|
const Modal: React.FC<ModalParams> = props => {
|
|
53
90
|
const { navigator } = useContext(ApplicationContext);
|
|
@@ -157,14 +194,6 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
157
194
|
return () => backHandler.remove();
|
|
158
195
|
}, [barrierDismissible, handleDismiss]);
|
|
159
196
|
|
|
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
|
-
|
|
168
197
|
return (
|
|
169
198
|
<Container
|
|
170
199
|
transparent
|
|
@@ -190,13 +219,13 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
190
219
|
opacity,
|
|
191
220
|
transform: [{ scale }],
|
|
192
221
|
},
|
|
193
|
-
// centered
|
|
222
|
+
// centered in the placement area, at most a popup wide
|
|
194
223
|
isFoldable && styles.shrink,
|
|
195
224
|
isFoldable && {
|
|
196
225
|
marginTop: placement.y,
|
|
197
226
|
marginBottom: height - placement.y - placement.height,
|
|
198
|
-
marginLeft:
|
|
199
|
-
marginRight:
|
|
227
|
+
marginLeft: placement.x,
|
|
228
|
+
marginRight: width - placement.x - placement.width,
|
|
200
229
|
maxWidth: popup.width,
|
|
201
230
|
maxHeight: popup.maxHeight,
|
|
202
231
|
},
|
|
@@ -8,7 +8,7 @@ import { isIPhoneDuo } from './utils';
|
|
|
8
8
|
const POPUP_MAX_WIDTH = 450;
|
|
9
9
|
const POPUP_MIN_WIDTH = 280;
|
|
10
10
|
const POPUP_MAX_HEIGHT = 600;
|
|
11
|
-
const SHEET_MAX_WIDTH =
|
|
11
|
+
const SHEET_MAX_WIDTH = 653;
|
|
12
12
|
const SHEET_MIN_WIDTH = 296;
|
|
13
13
|
const SHEET_MIN_HEIGHT = 230;
|
|
14
14
|
const FOLDABLE_MIN_WIDTH = 600;
|
|
@@ -46,12 +46,6 @@ export type ModalLayout = {
|
|
|
46
46
|
maxHeight?: number;
|
|
47
47
|
margin: number;
|
|
48
48
|
radius: number;
|
|
49
|
-
/**
|
|
50
|
-
* Window x of the left edge of a `width` wide popup, `undefined` on phones.
|
|
51
|
-
* Centered on the window, but a margin clear of the iPhone Duo control
|
|
52
|
-
* column / system insets; half folded it is centered in the right half.
|
|
53
|
-
*/
|
|
54
|
-
x?: number;
|
|
55
49
|
};
|
|
56
50
|
|
|
57
51
|
sheet: {
|
|
@@ -59,12 +53,6 @@ export type ModalLayout = {
|
|
|
59
53
|
* `undefined` on phones, the sheet spans the window.
|
|
60
54
|
*/
|
|
61
55
|
width?: number;
|
|
62
|
-
/**
|
|
63
|
-
* Window x of the sheet's left edge, `undefined` on phones. Centered on the
|
|
64
|
-
* window, but kept a margin clear of the iPhone Duo control column / system
|
|
65
|
-
* insets; half folded it is centered in the right half.
|
|
66
|
-
*/
|
|
67
|
-
x?: number;
|
|
68
56
|
maxHeight?: number;
|
|
69
57
|
minHeight?: number;
|
|
70
58
|
margin: number;
|
|
@@ -90,25 +78,6 @@ const clamp = (value: number, min: number, max: number) => {
|
|
|
90
78
|
return Math.min(Math.max(value, min), max);
|
|
91
79
|
};
|
|
92
80
|
|
|
93
|
-
/**
|
|
94
|
-
* Window x of a `boxWidth` wide overlay: centered on `center` (the window, so
|
|
95
|
-
* an inset on one side does not push it off center) but `margin` inside the
|
|
96
|
-
* placement; centered in the placement when it does not fit with the margins.
|
|
97
|
-
*/
|
|
98
|
-
const overlayX = (
|
|
99
|
-
center: number,
|
|
100
|
-
placement: ModalRect,
|
|
101
|
-
boxWidth: number,
|
|
102
|
-
margin: number,
|
|
103
|
-
) => {
|
|
104
|
-
const min = placement.x + margin;
|
|
105
|
-
const max = placement.x + placement.width - margin - boxWidth;
|
|
106
|
-
if (max < min) {
|
|
107
|
-
return placement.x + (placement.width - boxWidth) / 2;
|
|
108
|
-
}
|
|
109
|
-
return clamp(center - boxWidth / 2, min, max);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
81
|
/**
|
|
113
82
|
* Modal geometry for a window, pure so it can be tested without a device.
|
|
114
83
|
*/
|
|
@@ -161,20 +130,12 @@ const getModalLayout = ({
|
|
|
161
130
|
const sheetSpace = placement.width - sheetMargin * 2;
|
|
162
131
|
const sheetMinWidth = Math.min(SHEET_MIN_WIDTH, sheetSpace);
|
|
163
132
|
const sheetMaxHeight = height - insets.top - Spacing.M;
|
|
164
|
-
const sheetWidth = clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH);
|
|
165
|
-
const popupWidth = clamp(popupSpace, popupMinWidth, POPUP_MAX_WIDTH);
|
|
166
|
-
// the window center; half folded, the right half's
|
|
167
|
-
let overlayCenter = width / 2;
|
|
168
|
-
if (isHalfFolded) {
|
|
169
|
-
overlayCenter = placement.x + placement.width / 2;
|
|
170
|
-
}
|
|
171
133
|
|
|
172
134
|
return {
|
|
173
135
|
isFoldable,
|
|
174
136
|
placement,
|
|
175
137
|
popup: {
|
|
176
|
-
width:
|
|
177
|
-
x: overlayX(overlayCenter, placement, popupWidth, popupMargin),
|
|
138
|
+
width: clamp(popupSpace, popupMinWidth, POPUP_MAX_WIDTH),
|
|
178
139
|
minWidth: popupMinWidth,
|
|
179
140
|
maxWidth: POPUP_MAX_WIDTH,
|
|
180
141
|
maxHeight: Math.min(POPUP_MAX_HEIGHT, placement.height - Spacing.XL * 2),
|
|
@@ -182,8 +143,7 @@ const getModalLayout = ({
|
|
|
182
143
|
radius: Radius.XL,
|
|
183
144
|
},
|
|
184
145
|
sheet: {
|
|
185
|
-
width:
|
|
186
|
-
x: overlayX(overlayCenter, placement, sheetWidth, sheetMargin),
|
|
146
|
+
width: clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH),
|
|
187
147
|
maxHeight: sheetMaxHeight,
|
|
188
148
|
minHeight: Math.min(SHEET_MIN_HEIGHT, sheetMaxHeight),
|
|
189
149
|
margin: sheetMargin,
|
package/Application/types.ts
CHANGED
|
@@ -96,6 +96,8 @@ export type ModalParams = {
|
|
|
96
96
|
barrierDismissible?: boolean;
|
|
97
97
|
modalStyle?: ViewStyle;
|
|
98
98
|
useNativeModal?: boolean;
|
|
99
|
+
/** Edge to edge screen with no scrim or animation; it closes itself. */
|
|
100
|
+
fullScreen?: boolean;
|
|
99
101
|
};
|
|
100
102
|
|
|
101
103
|
export type BottomSheetParams = {
|