@momo-kits/foundation 0.169.17-beta.1 → 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/BottomSheet.parts.tsx +4 -4
- package/Application/BottomSheet.tsx +6 -16
- package/Application/BottomTab/Legacy/DuoTabBar.parts.tsx +1 -1
- package/Application/ModalIconButton.tsx +13 -15
- package/Application/ModalScreen.tsx +13 -4
- package/Application/modalLayout.ts +43 -3
- package/Text/utils.ts +4 -30
- package/package.json +1 -1
|
@@ -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
|
|
@@ -78,7 +78,7 @@ export const TabLabel: React.FC<{
|
|
|
78
78
|
<MiniAppContext.Provider
|
|
79
79
|
value={{
|
|
80
80
|
...context,
|
|
81
|
-
fontScale: { useOSScaleRate: false,
|
|
81
|
+
fontScale: { useOSScaleRate: false, userScaleRate: 1 },
|
|
82
82
|
}}
|
|
83
83
|
>
|
|
84
84
|
<Text numberOfLines={1} typography={typography} color={color}>
|
|
@@ -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
|
},
|
|
@@ -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 = 600;
|
|
12
12
|
const SHEET_MIN_WIDTH = 296;
|
|
13
13
|
const SHEET_MIN_HEIGHT = 230;
|
|
14
14
|
const FOLDABLE_MIN_WIDTH = 600;
|
|
@@ -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: {
|
|
@@ -53,6 +59,12 @@ export type ModalLayout = {
|
|
|
53
59
|
* `undefined` on phones, the sheet spans the window.
|
|
54
60
|
*/
|
|
55
61
|
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;
|
|
56
68
|
maxHeight?: number;
|
|
57
69
|
minHeight?: number;
|
|
58
70
|
margin: number;
|
|
@@ -78,6 +90,25 @@ const clamp = (value: number, min: number, max: number) => {
|
|
|
78
90
|
return Math.min(Math.max(value, min), max);
|
|
79
91
|
};
|
|
80
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
|
+
|
|
81
112
|
/**
|
|
82
113
|
* Modal geometry for a window, pure so it can be tested without a device.
|
|
83
114
|
*/
|
|
@@ -130,12 +161,20 @@ const getModalLayout = ({
|
|
|
130
161
|
const sheetSpace = placement.width - sheetMargin * 2;
|
|
131
162
|
const sheetMinWidth = Math.min(SHEET_MIN_WIDTH, sheetSpace);
|
|
132
163
|
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
|
+
}
|
|
133
171
|
|
|
134
172
|
return {
|
|
135
173
|
isFoldable,
|
|
136
174
|
placement,
|
|
137
175
|
popup: {
|
|
138
|
-
width:
|
|
176
|
+
width: popupWidth,
|
|
177
|
+
x: overlayX(overlayCenter, placement, popupWidth, popupMargin),
|
|
139
178
|
minWidth: popupMinWidth,
|
|
140
179
|
maxWidth: POPUP_MAX_WIDTH,
|
|
141
180
|
maxHeight: Math.min(POPUP_MAX_HEIGHT, placement.height - Spacing.XL * 2),
|
|
@@ -143,7 +182,8 @@ const getModalLayout = ({
|
|
|
143
182
|
radius: Radius.XL,
|
|
144
183
|
},
|
|
145
184
|
sheet: {
|
|
146
|
-
width:
|
|
185
|
+
width: sheetWidth,
|
|
186
|
+
x: overlayX(overlayCenter, placement, sheetWidth, sheetMargin),
|
|
147
187
|
maxHeight: sheetMaxHeight,
|
|
148
188
|
minHeight: Math.min(SHEET_MIN_HEIGHT, sheetMaxHeight),
|
|
149
189
|
margin: sheetMargin,
|
package/Text/utils.ts
CHANGED
|
@@ -5,50 +5,24 @@ import { MiniAppContext } from '../Context';
|
|
|
5
5
|
const DEFAULT_SCREEN_SIZE = 375;
|
|
6
6
|
const MAX_FONT_SCALE = 1.5;
|
|
7
7
|
const MAX_DEVICE_SCALE = 5;
|
|
8
|
-
const APP_SCALE_LEVELS = [1, 1.2, 1.3, 1.4];
|
|
9
8
|
|
|
10
9
|
type MiniAppScale = {
|
|
11
10
|
scaleSizeMaxRate?: number;
|
|
12
|
-
fontScale?: {
|
|
13
|
-
useOSScaleRate?: boolean;
|
|
14
|
-
appScaleRate?: number;
|
|
15
|
-
/** @deprecated Use `appScaleRate`. Still sent by the host. */
|
|
16
|
-
userScaleRate?: number;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Snaps a host scale rate to the nearest app scale level (1, 1.2, 1.3, 1.4),
|
|
22
|
-
* ties going lower, so legacy rates (1.1, 1.6) resolve like the host does.
|
|
23
|
-
*/
|
|
24
|
-
const toAppScaleRate = (rate?: number) => {
|
|
25
|
-
if (!rate) {
|
|
26
|
-
return APP_SCALE_LEVELS[0];
|
|
27
|
-
}
|
|
28
|
-
const percent = Math.round(rate * 100);
|
|
29
|
-
const distance = (level: number) =>
|
|
30
|
-
Math.abs(Math.round(level * 100) - percent);
|
|
31
|
-
return APP_SCALE_LEVELS.reduce((best, level) =>
|
|
32
|
-
distance(level) < distance(best) ? level : best,
|
|
33
|
-
);
|
|
11
|
+
fontScale?: { useOSScaleRate?: boolean; userScaleRate?: number };
|
|
34
12
|
};
|
|
35
13
|
|
|
36
14
|
/**
|
|
37
15
|
* Scales `size` by screen width (+5 max) and OS font scale (max `scaleRate`,
|
|
38
16
|
* else the ScaleSizeProvider rate, else 1.5), taking the larger, or by the mini
|
|
39
|
-
* app `fontScale.
|
|
17
|
+
* app `fontScale.userScaleRate`; a provider rate caps both at `size × rate`.
|
|
40
18
|
*/
|
|
41
19
|
const useScaleSize = (size: number, scaleRate?: number) => {
|
|
42
20
|
const { width } = useWindowDimensions();
|
|
43
21
|
const context = useContext<MiniAppScale | undefined>(MiniAppContext);
|
|
44
22
|
const scaleSizeMaxRate = context?.scaleSizeMaxRate;
|
|
45
23
|
const maxSize = scaleSizeMaxRate ? size * scaleSizeMaxRate : Infinity;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const rate = toAppScaleRate(
|
|
49
|
-
appScale.appScaleRate ?? appScale.userScaleRate,
|
|
50
|
-
);
|
|
51
|
-
return Math.min(size * rate, maxSize);
|
|
24
|
+
if (context?.fontScale?.useOSScaleRate === false) {
|
|
25
|
+
return Math.min(size * (context.fontScale.userScaleRate ?? 1), maxSize);
|
|
52
26
|
}
|
|
53
27
|
const fontScale = PixelRatio.getFontScale();
|
|
54
28
|
const deviceScale = width / DEFAULT_SCREEN_SIZE;
|