@momo-kits/foundation 0.169.17-beta.1 → 0.169.17-beta.2

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 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.
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
- let content: React.ReactNode;
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
- // 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
- );
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
- {content}
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, appScaleRate: 1 },
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 { Radius, Spacing } from '../Consts';
9
+ import { Colors } from '../Consts';
10
10
  import { Icon } from '../Icon';
11
+ import { HeaderBarMetrics } from './headerLayout';
11
12
 
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;
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: Radius.L,
60
- borderWidth: 1,
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
 
@@ -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 = 653;
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;
@@ -53,6 +53,12 @@ export type ModalLayout = {
53
53
  * `undefined` on phones, the sheet spans the window.
54
54
  */
55
55
  width?: number;
56
+ /**
57
+ * Window x of the sheet's left edge, `undefined` on phones. Centered on the
58
+ * window, but kept a margin clear of the iPhone Duo control column / system
59
+ * insets; half folded it is centered in the right half.
60
+ */
61
+ x?: number;
56
62
  maxHeight?: number;
57
63
  minHeight?: number;
58
64
  margin: number;
@@ -130,6 +136,19 @@ const getModalLayout = ({
130
136
  const sheetSpace = placement.width - sheetMargin * 2;
131
137
  const sheetMinWidth = Math.min(SHEET_MIN_WIDTH, sheetSpace);
132
138
  const sheetMaxHeight = height - insets.top - Spacing.M;
139
+ const sheetWidth = clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH);
140
+ // the window center, not the placement's, so an inset on one side (control column) does not push it off center
141
+ let sheetCenter = width / 2;
142
+ if (isHalfFolded) {
143
+ sheetCenter = placement.x + placement.width / 2;
144
+ }
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
+ );
133
152
 
134
153
  return {
135
154
  isFoldable,
@@ -143,7 +162,8 @@ const getModalLayout = ({
143
162
  radius: Radius.XL,
144
163
  },
145
164
  sheet: {
146
- width: clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH),
165
+ width: sheetWidth,
166
+ x: sheetX,
147
167
  maxHeight: sheetMaxHeight,
148
168
  minHeight: Math.min(SHEET_MIN_HEIGHT, sheetMaxHeight),
149
169
  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.appScaleRate`; a provider rate caps both at `size × rate`.
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
- const appScale = context?.fontScale;
47
- if (appScale?.useOSScaleRate === false) {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.17-beta.1",
3
+ "version": "0.169.17-beta.2",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},