@momo-kits/foundation 0.162.2-test.1 → 0.162.2-test.10
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.tsx +2 -3
- package/Application/BottomTab/index.tsx +1 -1
- package/Application/Components/HeaderLeft.tsx +1 -1
- package/Application/NavigationContainer.tsx +27 -2
- package/Application/ScaleSizeProvider.tsx +5 -3
- package/Application/WidgetContainer.tsx +1 -1
- package/Application/types.ts +2 -1
- package/Context/index.ts +6 -3
- package/Layout/Screen.tsx +4 -5
- package/Text/utils.ts +15 -5
- package/package.json +1 -1
|
@@ -37,8 +37,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
37
37
|
const action = useRef<undefined | string>(undefined);
|
|
38
38
|
const insets = useSafeAreaInsets();
|
|
39
39
|
const heightHeader = useHeaderHeight();
|
|
40
|
-
const
|
|
41
|
-
const keyboardOffset = heightHeader - bottomInset;
|
|
40
|
+
const keyboardOffset = heightHeader - Math.min(insets.bottom, 21);
|
|
42
41
|
|
|
43
42
|
const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
|
|
44
43
|
|
|
@@ -312,7 +311,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
312
311
|
{useBottomInset && (
|
|
313
312
|
<View
|
|
314
313
|
style={{
|
|
315
|
-
height:
|
|
314
|
+
height: Math.min(insets.bottom, 21),
|
|
316
315
|
backgroundColor: backgroundColor,
|
|
317
316
|
}}
|
|
318
317
|
/>
|
|
@@ -320,7 +320,7 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
320
320
|
activeTintColor={theme.colors.primary}
|
|
321
321
|
style={[
|
|
322
322
|
{
|
|
323
|
-
height: 64 +
|
|
323
|
+
height: 64 + Math.min(insets.bottom, 21),
|
|
324
324
|
},
|
|
325
325
|
]}
|
|
326
326
|
/>
|
|
@@ -19,7 +19,7 @@ import Navigator from './Navigator';
|
|
|
19
19
|
import ScaleSizeProvider from './ScaleSizeProvider';
|
|
20
20
|
import { getModalOptions, getStackOptions } from './utils';
|
|
21
21
|
import { NavigationContainerProps } from './types';
|
|
22
|
-
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
22
|
+
import { ApplicationContext, FontScaleConfig, MiniAppContext } from '../Context';
|
|
23
23
|
import Localize from './Localize';
|
|
24
24
|
import { Colors, defaultTheme } from '../Consts';
|
|
25
25
|
import { HeaderLeft } from './Components/HeaderLeft';
|
|
@@ -29,6 +29,9 @@ import { HeaderBackground } from './Components/HeaderBackground';
|
|
|
29
29
|
|
|
30
30
|
const Stack = createStackNavigator();
|
|
31
31
|
|
|
32
|
+
// Observer storage key the host app writes FontScaleConfig to. Lowercased natively.
|
|
33
|
+
const FONT_SCALE_OBSERVER_KEY = 'font_scale_config';
|
|
34
|
+
|
|
32
35
|
const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
33
36
|
screen,
|
|
34
37
|
theme = defaultTheme,
|
|
@@ -45,6 +48,11 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
45
48
|
}) => {
|
|
46
49
|
const context = useContext<any>(MiniAppContext);
|
|
47
50
|
const [currentContext, setCurrentContext] = useState<any>({});
|
|
51
|
+
// Default = the host-seeded fontScaleConfig from MiniAppContext, so the first frame is already
|
|
52
|
+
// scaled (no flash). The observer below overwrites it on later host writes (live rate changes).
|
|
53
|
+
const [observerFontScaleConfig, setObserverFontScaleConfig] = useState<
|
|
54
|
+
FontScaleConfig | undefined
|
|
55
|
+
>(context?.fontScaleConfig);
|
|
48
56
|
|
|
49
57
|
const mergedContext = {
|
|
50
58
|
...context,
|
|
@@ -55,10 +63,27 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
55
63
|
},
|
|
56
64
|
};
|
|
57
65
|
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
// The initial value is seeded by the host into MiniAppContext and used as this state's default
|
|
68
|
+
// above, so the first frame is already scaled (no flash). Here we only subscribe to later host
|
|
69
|
+
// writes so a rate change applies live while the miniapp is open.
|
|
70
|
+
const sub = maxApi?.observer?.(
|
|
71
|
+
FONT_SCALE_OBSERVER_KEY,
|
|
72
|
+
(data: FontScaleConfig) => {
|
|
73
|
+
setObserverFontScaleConfig(data ?? undefined);
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
return () => {
|
|
77
|
+
sub?.remove?.();
|
|
78
|
+
};
|
|
79
|
+
}, [maxApi]);
|
|
80
|
+
|
|
58
81
|
return (
|
|
59
82
|
<SafeAreaProvider>
|
|
60
83
|
<MiniAppContext.Provider value={mergedContext}>
|
|
61
|
-
<ScaleSizeProvider
|
|
84
|
+
<ScaleSizeProvider
|
|
85
|
+
fontScaleConfig={observerFontScaleConfig}
|
|
86
|
+
>
|
|
62
87
|
<Navigation
|
|
63
88
|
screen={screen}
|
|
64
89
|
theme={theme}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
1
|
+
import React, { FC, useContext } from 'react';
|
|
2
2
|
import { ScaleSizeContext } from '../Context';
|
|
3
3
|
import { ScaleSizeProviderProps } from './types';
|
|
4
4
|
|
|
5
5
|
const ScaleSizeProvider: FC<ScaleSizeProviderProps> = ({
|
|
6
|
-
|
|
6
|
+
fontScaleConfig,
|
|
7
7
|
children,
|
|
8
8
|
}) => {
|
|
9
|
+
// Inherit the config from an upper layer (e.g. app root) when the host doesn't set it via MiniAppContext.
|
|
10
|
+
const parent = useContext(ScaleSizeContext);
|
|
9
11
|
return (
|
|
10
|
-
<ScaleSizeContext.Provider value={
|
|
12
|
+
<ScaleSizeContext.Provider value={fontScaleConfig ?? parent}>
|
|
11
13
|
{children}
|
|
12
14
|
</ScaleSizeContext.Provider>
|
|
13
15
|
);
|
|
@@ -78,7 +78,7 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
|
78
78
|
<SafeAreaProvider>
|
|
79
79
|
<MiniAppContext.Provider value={mergedContext}>
|
|
80
80
|
<ScaleSizeProvider
|
|
81
|
-
|
|
81
|
+
fontScaleConfig={mergedContext?.fontScaleConfig}
|
|
82
82
|
>
|
|
83
83
|
<ApplicationContext.Provider
|
|
84
84
|
value={{
|
package/Application/types.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from 'react-native';
|
|
10
10
|
import { PopupNotifyProps } from '../Popup/types';
|
|
11
11
|
import { InputRef, InputSearchProps } from '../Input';
|
|
12
|
+
import { FontScaleConfig } from '../Context';
|
|
12
13
|
import Navigation from './Navigation';
|
|
13
14
|
|
|
14
15
|
export type NavigationProps = {
|
|
@@ -108,7 +109,7 @@ export type Theme = {
|
|
|
108
109
|
};
|
|
109
110
|
|
|
110
111
|
export type ScaleSizeProviderProps = {
|
|
111
|
-
|
|
112
|
+
fontScaleConfig?: FontScaleConfig;
|
|
112
113
|
children: ViewProps['children'];
|
|
113
114
|
};
|
|
114
115
|
|
package/Context/index.ts
CHANGED
|
@@ -9,9 +9,12 @@ const MiniAppContext = (Platform as any).MiniAppContext ?? Context;
|
|
|
9
9
|
const ScreenContext = (Platform as any).ScreenContext ?? Context;
|
|
10
10
|
const ComponentContext = (Platform as any).ComponentContext ?? Context;
|
|
11
11
|
const SkeletonContext = createContext({ loading: false });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// Single source of truth: holds both the OS flag and the user-adjusted rate.
|
|
13
|
+
export type FontScaleConfig = {
|
|
14
|
+
useOSFontScale?: boolean;
|
|
15
|
+
userScaleRate?: number;
|
|
16
|
+
};
|
|
17
|
+
const ScaleSizeContext = createContext<FontScaleConfig>({});
|
|
15
18
|
const TrackingScopeContext = createContext<{ scopeName?: string }>({
|
|
16
19
|
scopeName: undefined,
|
|
17
20
|
});
|
package/Layout/Screen.tsx
CHANGED
|
@@ -204,10 +204,9 @@ const Screen = forwardRef(
|
|
|
204
204
|
let handleScroll;
|
|
205
205
|
let Component: any = View;
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
let keyboardOffset = heightHeader - bottomInset;
|
|
207
|
+
let keyboardOffset = heightHeader - Math.min(insets.bottom, 21);
|
|
209
208
|
if (headerType === 'extended' || animatedHeader || inputSearchProps) {
|
|
210
|
-
keyboardOffset = -
|
|
209
|
+
keyboardOffset = -Math.min(insets.bottom, 21);
|
|
211
210
|
}
|
|
212
211
|
|
|
213
212
|
/**
|
|
@@ -617,7 +616,7 @@ const Screen = forwardRef(
|
|
|
617
616
|
{...floatingButtonProps}
|
|
618
617
|
animatedValue={animatedValue.current}
|
|
619
618
|
bottom={
|
|
620
|
-
Footer || isTab ? 12 :
|
|
619
|
+
Footer || isTab ? 12 : Math.min(insets.bottom, 21) + Spacing.S
|
|
621
620
|
}
|
|
622
621
|
/>
|
|
623
622
|
</View>
|
|
@@ -628,7 +627,7 @@ const Screen = forwardRef(
|
|
|
628
627
|
style={[
|
|
629
628
|
styles.shadow,
|
|
630
629
|
{
|
|
631
|
-
paddingBottom:
|
|
630
|
+
paddingBottom: Math.min(insets.bottom, 21) + Spacing.S,
|
|
632
631
|
backgroundColor: theme.colors.background.surface,
|
|
633
632
|
},
|
|
634
633
|
]}
|
package/Text/utils.ts
CHANGED
|
@@ -7,14 +7,24 @@ const DEFAULT_SCREEN_SIZE = 375;
|
|
|
7
7
|
const MAX_FONT_SCALE = 1.5;
|
|
8
8
|
const MAX_DEVICE_SCALE = 5;
|
|
9
9
|
|
|
10
|
-
const useScaleSize = (size: number,
|
|
11
|
-
const {
|
|
10
|
+
const useScaleSize = (size: number, userScaleRate?: number) => {
|
|
11
|
+
const { useOSFontScale = true, userScaleRate: ctxRate } =
|
|
12
|
+
useContext(ScaleSizeContext);
|
|
12
13
|
const fontScale = PixelRatio.getFontScale();
|
|
13
14
|
const { width } = useWindowDimensions();
|
|
14
15
|
const deviceScale = width / DEFAULT_SCREEN_SIZE;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
// rate precedence: per-call param override > host config (ctxRate) > 1 (no scaling)
|
|
18
|
+
const customRate = userScaleRate ?? ctxRate ?? 1;
|
|
17
19
|
|
|
20
|
+
// useOSFontScale off -> the user has full control via customRate; skip device-width scaling
|
|
21
|
+
// entirely and apply only the custom rate (capped at MAX_FONT_SCALE).
|
|
22
|
+
if (!useOSFontScale) {
|
|
23
|
+
// custom rate is uncapped (full user control); only the OS-follow path below caps at MAX_FONT_SCALE.
|
|
24
|
+
return customRate > 1 ? customRate * size : size;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// useOSFontScale on -> device-width scale + OS font scale, take the larger.
|
|
18
28
|
let fontSizeDeviceScale = size;
|
|
19
29
|
let fontSizeOSScale = size;
|
|
20
30
|
|
|
@@ -27,8 +37,8 @@ const useScaleSize = (size: number, scaleRate?: number) => {
|
|
|
27
37
|
|
|
28
38
|
if (fontScale > 1) {
|
|
29
39
|
fontSizeOSScale = Math.min(
|
|
30
|
-
|
|
31
|
-
fontSizeOSScale *
|
|
40
|
+
fontScale * fontSizeOSScale,
|
|
41
|
+
fontSizeOSScale * MAX_FONT_SCALE,
|
|
32
42
|
);
|
|
33
43
|
}
|
|
34
44
|
|