@momo-kits/foundation 0.162.2-beta.1 → 0.162.2-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.
- package/Application/BottomSheet.tsx +3 -2
- package/Application/BottomTab/index.tsx +1 -1
- package/Application/Components/HeaderLeft.tsx +1 -1
- package/Application/NavigationContainer.tsx +21 -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 +5 -4
- package/Text/utils.ts +10 -5
- package/package.json +1 -1
|
@@ -37,7 +37,8 @@ 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
|
|
40
|
+
const bottomInset = Platform.OS === 'ios' ? Math.min(insets.bottom, 21) : insets.bottom;
|
|
41
|
+
const keyboardOffset = heightHeader - bottomInset;
|
|
41
42
|
|
|
42
43
|
const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
|
|
43
44
|
|
|
@@ -311,7 +312,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
311
312
|
{useBottomInset && (
|
|
312
313
|
<View
|
|
313
314
|
style={{
|
|
314
|
-
height:
|
|
315
|
+
height: bottomInset,
|
|
315
316
|
backgroundColor: backgroundColor,
|
|
316
317
|
}}
|
|
317
318
|
/>
|
|
@@ -296,7 +296,7 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
296
296
|
activeTintColor={theme.colors.primary}
|
|
297
297
|
style={[
|
|
298
298
|
{
|
|
299
|
-
height: 64 + Math.min(insets.bottom, 21),
|
|
299
|
+
height: 64 + (Platform.OS === 'ios' ? Math.min(insets.bottom, 21) : insets.bottom),
|
|
300
300
|
},
|
|
301
301
|
]}
|
|
302
302
|
/>
|
|
@@ -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,8 @@ import { HeaderBackground } from './Components/HeaderBackground';
|
|
|
29
29
|
|
|
30
30
|
const Stack = createStackNavigator();
|
|
31
31
|
|
|
32
|
+
const FONT_SCALE_OBSERVER_KEY = 'font_scale_config';
|
|
33
|
+
|
|
32
34
|
const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
33
35
|
screen,
|
|
34
36
|
theme = defaultTheme,
|
|
@@ -45,6 +47,9 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
45
47
|
}) => {
|
|
46
48
|
const context = useContext<any>(MiniAppContext);
|
|
47
49
|
const [currentContext, setCurrentContext] = useState<any>({});
|
|
50
|
+
const [observerFontScaleConfig, setObserverFontScaleConfig] = useState<
|
|
51
|
+
FontScaleConfig | undefined
|
|
52
|
+
>(context?.fontScaleConfig);
|
|
48
53
|
|
|
49
54
|
const mergedContext = {
|
|
50
55
|
...context,
|
|
@@ -55,10 +60,24 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
|
|
|
55
60
|
},
|
|
56
61
|
};
|
|
57
62
|
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const sub = maxApi?.observer?.(
|
|
65
|
+
FONT_SCALE_OBSERVER_KEY,
|
|
66
|
+
(data: FontScaleConfig) => {
|
|
67
|
+
setObserverFontScaleConfig(data ?? undefined);
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
return () => {
|
|
71
|
+
sub?.remove?.();
|
|
72
|
+
};
|
|
73
|
+
}, [maxApi]);
|
|
74
|
+
|
|
58
75
|
return (
|
|
59
76
|
<SafeAreaProvider>
|
|
60
77
|
<MiniAppContext.Provider value={mergedContext}>
|
|
61
|
-
<ScaleSizeProvider
|
|
78
|
+
<ScaleSizeProvider
|
|
79
|
+
fontScaleConfig={observerFontScaleConfig}
|
|
80
|
+
>
|
|
62
81
|
<Navigation
|
|
63
82
|
screen={screen}
|
|
64
83
|
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
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import type { SharedValue } from 'react-native-reanimated';
|
|
11
11
|
import { PopupNotifyProps } from '../Popup/types';
|
|
12
12
|
import { InputRef, InputSearchProps } from '../Input';
|
|
13
|
+
import { FontScaleConfig } from '../Context';
|
|
13
14
|
import Navigation from './Navigation';
|
|
14
15
|
|
|
15
16
|
export type NavigationProps = {
|
|
@@ -109,7 +110,7 @@ export type Theme = {
|
|
|
109
110
|
};
|
|
110
111
|
|
|
111
112
|
export type ScaleSizeProviderProps = {
|
|
112
|
-
|
|
113
|
+
fontScaleConfig?: FontScaleConfig;
|
|
113
114
|
children: ViewProps['children'];
|
|
114
115
|
};
|
|
115
116
|
|
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
|
@@ -240,9 +240,10 @@ const Screen = forwardRef(
|
|
|
240
240
|
let handleScroll;
|
|
241
241
|
let Component: any = View;
|
|
242
242
|
|
|
243
|
-
|
|
243
|
+
const bottomInset = Platform.OS === 'ios' ? Math.min(insets.bottom, 21) : insets.bottom;
|
|
244
|
+
let keyboardOffset = heightHeader - bottomInset;
|
|
244
245
|
if (headerType === 'extended' || animatedHeader || inputSearchProps) {
|
|
245
|
-
keyboardOffset = -
|
|
246
|
+
keyboardOffset = -bottomInset;
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
/**
|
|
@@ -662,7 +663,7 @@ const Screen = forwardRef(
|
|
|
662
663
|
{...floatingButtonProps}
|
|
663
664
|
animatedValue={sharedValue}
|
|
664
665
|
bottom={
|
|
665
|
-
Footer || isTab ? 12 :
|
|
666
|
+
Footer || isTab ? 12 : bottomInset + Spacing.S
|
|
666
667
|
}
|
|
667
668
|
/>
|
|
668
669
|
</View>
|
|
@@ -673,7 +674,7 @@ const Screen = forwardRef(
|
|
|
673
674
|
style={[
|
|
674
675
|
styles.shadow,
|
|
675
676
|
{
|
|
676
|
-
paddingBottom:
|
|
677
|
+
paddingBottom: bottomInset + Spacing.S,
|
|
677
678
|
backgroundColor: theme.colors.background.surface,
|
|
678
679
|
},
|
|
679
680
|
]}
|
package/Text/utils.ts
CHANGED
|
@@ -7,13 +7,18 @@ 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
|
-
const
|
|
17
|
+
const customRate = userScaleRate ?? ctxRate ?? 1;
|
|
18
|
+
|
|
19
|
+
if (!useOSFontScale) {
|
|
20
|
+
return customRate > 1 ? customRate * size : size;
|
|
21
|
+
}
|
|
17
22
|
|
|
18
23
|
let fontSizeDeviceScale = size;
|
|
19
24
|
let fontSizeOSScale = size;
|
|
@@ -27,8 +32,8 @@ const useScaleSize = (size: number, scaleRate?: number) => {
|
|
|
27
32
|
|
|
28
33
|
if (fontScale > 1) {
|
|
29
34
|
fontSizeOSScale = Math.min(
|
|
30
|
-
|
|
31
|
-
fontSizeOSScale *
|
|
35
|
+
fontScale * fontSizeOSScale,
|
|
36
|
+
fontSizeOSScale * MAX_FONT_SCALE,
|
|
32
37
|
);
|
|
33
38
|
}
|
|
34
39
|
|