@momo-kits/foundation 0.169.17-beta.2 → 0.169.17-beta.3
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/ModalScreen.tsx +13 -4
- package/Application/modalLayout.ts +32 -12
- package/package.json +1 -1
|
@@ -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
|
},
|
|
@@ -46,6 +46,12 @@ 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;
|
|
49
55
|
};
|
|
50
56
|
|
|
51
57
|
sheet: {
|
|
@@ -84,6 +90,25 @@ const clamp = (value: number, min: number, max: number) => {
|
|
|
84
90
|
return Math.min(Math.max(value, min), max);
|
|
85
91
|
};
|
|
86
92
|
|
|
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
|
+
|
|
87
112
|
/**
|
|
88
113
|
* Modal geometry for a window, pure so it can be tested without a device.
|
|
89
114
|
*/
|
|
@@ -137,24 +162,19 @@ const getModalLayout = ({
|
|
|
137
162
|
const sheetMinWidth = Math.min(SHEET_MIN_WIDTH, sheetSpace);
|
|
138
163
|
const sheetMaxHeight = height - insets.top - Spacing.M;
|
|
139
164
|
const sheetWidth = clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH);
|
|
140
|
-
|
|
141
|
-
|
|
165
|
+
const popupWidth = clamp(popupSpace, popupMinWidth, POPUP_MAX_WIDTH);
|
|
166
|
+
// the window center; half folded, the right half's
|
|
167
|
+
let overlayCenter = width / 2;
|
|
142
168
|
if (isHalfFolded) {
|
|
143
|
-
|
|
169
|
+
overlayCenter = placement.x + placement.width / 2;
|
|
144
170
|
}
|
|
145
|
-
const sheetX = Math.max(
|
|
146
|
-
placement.x + sheetMargin,
|
|
147
|
-
Math.min(
|
|
148
|
-
sheetCenter - sheetWidth / 2,
|
|
149
|
-
placement.x + placement.width - sheetMargin - sheetWidth,
|
|
150
|
-
),
|
|
151
|
-
);
|
|
152
171
|
|
|
153
172
|
return {
|
|
154
173
|
isFoldable,
|
|
155
174
|
placement,
|
|
156
175
|
popup: {
|
|
157
|
-
width:
|
|
176
|
+
width: popupWidth,
|
|
177
|
+
x: overlayX(overlayCenter, placement, popupWidth, popupMargin),
|
|
158
178
|
minWidth: popupMinWidth,
|
|
159
179
|
maxWidth: POPUP_MAX_WIDTH,
|
|
160
180
|
maxHeight: Math.min(POPUP_MAX_HEIGHT, placement.height - Spacing.XL * 2),
|
|
@@ -163,7 +183,7 @@ const getModalLayout = ({
|
|
|
163
183
|
},
|
|
164
184
|
sheet: {
|
|
165
185
|
width: sheetWidth,
|
|
166
|
-
x:
|
|
186
|
+
x: overlayX(overlayCenter, placement, sheetWidth, sheetMargin),
|
|
167
187
|
maxHeight: sheetMaxHeight,
|
|
168
188
|
minHeight: Math.min(SHEET_MIN_HEIGHT, sheetMaxHeight),
|
|
169
189
|
margin: sheetMargin,
|