@momo-kits/foundation 0.169.11-beta.3 → 0.169.11-beta.4
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/BottomTab/TabBarIcon.tsx +2 -7
- package/Application/Components/HeaderExtendHeader.tsx +3 -1
- package/Application/Components/HeaderRight.tsx +24 -3
- package/Application/Components/SearchHeader.tsx +3 -2
- package/Application/Components/useHeaderRightWidth.ts +46 -0
- package/Application/headerLayout.ts +7 -3
- package/package.json +1 -1
|
@@ -13,9 +13,6 @@ import { Text } from '../../Text';
|
|
|
13
13
|
import ScaleSizeProvider from '../ScaleSizeProvider';
|
|
14
14
|
import { TabBarMetrics, TabBarMotion } from './metrics';
|
|
15
15
|
|
|
16
|
-
// text badges keep 5 characters, then "..." ("Khám phá" -> "Khám...")
|
|
17
|
-
const BADGE_MAX_CHARS = 5;
|
|
18
|
-
|
|
19
16
|
type Props = {
|
|
20
17
|
focused: boolean;
|
|
21
18
|
// '' shows a dot, anything else a label badge
|
|
@@ -33,7 +30,7 @@ type Props = {
|
|
|
33
30
|
|
|
34
31
|
/**
|
|
35
32
|
* Badge value of a tab: undefined hides it, '' is a dot (also 0 when `showDot`), numbers
|
|
36
|
-
* cap at 99
|
|
33
|
+
* cap at 99+.
|
|
37
34
|
*/
|
|
38
35
|
export const getTabBadge = (
|
|
39
36
|
badgeLabel?: string | number,
|
|
@@ -53,9 +50,7 @@ export const getTabBadge = (
|
|
|
53
50
|
}
|
|
54
51
|
return value > 99 ? '99+' : text;
|
|
55
52
|
}
|
|
56
|
-
return text
|
|
57
|
-
? `${text.slice(0, BADGE_MAX_CHARS).trimEnd()}...`
|
|
58
|
-
: text;
|
|
53
|
+
return text;
|
|
59
54
|
};
|
|
60
55
|
|
|
61
56
|
/**
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
type HeaderContentLayout,
|
|
24
24
|
useHeaderLayout,
|
|
25
25
|
} from '../headerLayout';
|
|
26
|
+
import { useHeaderRightWidth } from './useHeaderRightWidth';
|
|
26
27
|
|
|
27
28
|
const { buttonSize, pillWidth, sidePadding, titleGap } = HeaderBarMetrics;
|
|
28
29
|
const SCREEN_PADDING = sidePadding;
|
|
@@ -69,7 +70,8 @@ const HeaderExtendHeader: React.FC<{
|
|
|
69
70
|
const backLeft = buttonSize + sidePadding + titleGap;
|
|
70
71
|
const defaultLeft = layout.sideBar ? SCREEN_PADDING : backLeft;
|
|
71
72
|
const leftPosition = inputSearchProps?.leftPosition || defaultLeft;
|
|
72
|
-
const
|
|
73
|
+
const measuredRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
|
|
74
|
+
const defaultRightWidth = layout.sideBar ? 0 : measuredRightWidth;
|
|
73
75
|
const headerRightWidth = customHeaderRightWidth ?? defaultRightWidth;
|
|
74
76
|
const contentLeft = layout.insetLeft + SCREEN_PADDING + frameShift;
|
|
75
77
|
const contentRight = layout.insetLeft + layout.contentWidth - frameShift;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { TouchableOpacity, View } from 'react-native';
|
|
1
|
+
import React, { useCallback, useContext, useEffect } from 'react';
|
|
2
|
+
import { type LayoutChangeEvent, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import { NavigationRouteContext } from '@react-navigation/native';
|
|
3
4
|
import { ApplicationContext } from '../../Context';
|
|
4
5
|
import { Text } from '../../Text';
|
|
5
6
|
import Animated from 'react-native-reanimated';
|
|
@@ -7,10 +8,12 @@ import { useSideBarItemStyle } from '../../Layout/utils';
|
|
|
7
8
|
import { useSideBarCounterStyle } from './DuoQuickReturnHeader';
|
|
8
9
|
import { HeaderToolkitAction } from './HeaderToolkitAction';
|
|
9
10
|
import { styles } from './HeaderRight.styles';
|
|
11
|
+
import { setHeaderRightWidth } from './useHeaderRightWidth';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Header right slot: a custom `headerRight` render function, the onboarding skip
|
|
13
15
|
* button, or the toolkit (stacked vertically in the floating iPhone Duo side bar).
|
|
16
|
+
* The bar toolkit reports its width so header searches stop short of it.
|
|
14
17
|
*/
|
|
15
18
|
const HeaderRight: React.FC<any> = props => {
|
|
16
19
|
const { translate } = useContext(ApplicationContext);
|
|
@@ -18,6 +21,24 @@ const HeaderRight: React.FC<any> = props => {
|
|
|
18
21
|
const { useOnBoarding = false, buttonOnBoarding, onPress } = headerRight;
|
|
19
22
|
const sideBarStyle = useSideBarItemStyle('right', 1);
|
|
20
23
|
const counterStyle = useSideBarCounterStyle();
|
|
24
|
+
const routeKey = useContext(NavigationRouteContext)?.key;
|
|
25
|
+
|
|
26
|
+
const handleToolkitLayout = useCallback(
|
|
27
|
+
(event: LayoutChangeEvent) => {
|
|
28
|
+
if (routeKey) {
|
|
29
|
+
setHeaderRightWidth(routeKey, event.nativeEvent.layout.width);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
[routeKey],
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
return () => {
|
|
37
|
+
if (routeKey) {
|
|
38
|
+
setHeaderRightWidth(routeKey, undefined);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}, [routeKey]);
|
|
21
42
|
|
|
22
43
|
if (typeof props.headerRight === 'function') {
|
|
23
44
|
return props.headerRight(props);
|
|
@@ -49,7 +70,7 @@ const HeaderRight: React.FC<any> = props => {
|
|
|
49
70
|
}
|
|
50
71
|
|
|
51
72
|
return (
|
|
52
|
-
<View style={styles.headerRightButton}>
|
|
73
|
+
<View style={styles.headerRightButton} onLayout={handleToolkitLayout}>
|
|
53
74
|
<HeaderToolkitAction {...props.headerRight} tintColor={props.tintColor} />
|
|
54
75
|
</View>
|
|
55
76
|
);
|
|
@@ -9,9 +9,10 @@ import { Text } from '../../Text';
|
|
|
9
9
|
import { useNormalizedSharedValue } from '../hooks';
|
|
10
10
|
import { useScreenLayout } from '../../Layout';
|
|
11
11
|
import { HeaderBarMetrics } from '../headerLayout';
|
|
12
|
+
import { useHeaderRightWidth } from './useHeaderRightWidth';
|
|
12
13
|
|
|
13
14
|
const { buttonSize, pillWidth, sidePadding, titleGap } = HeaderBarMetrics;
|
|
14
|
-
// help center | home pill and the bar padding right of it
|
|
15
|
+
// help center | home pill and the bar padding right of it, until the toolkit lays out
|
|
15
16
|
const TOOLKIT_WIDTH = pillWidth + sidePadding;
|
|
16
17
|
// the iPhone Duo side bar keeps its right header width
|
|
17
18
|
const DUO_TOOLKIT_WIDTH = 73;
|
|
@@ -34,7 +35,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
34
35
|
const { theme, navigator } = useContext(ApplicationContext);
|
|
35
36
|
const context = useContext<any>(MiniAppContext);
|
|
36
37
|
const layout = useScreenLayout();
|
|
37
|
-
let defaultRightWidth = TOOLKIT_WIDTH;
|
|
38
|
+
let defaultRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
|
|
38
39
|
let searchSize: InputSearchProps['size'] = 'header';
|
|
39
40
|
if (layout.sideBar) {
|
|
40
41
|
defaultRightWidth = DUO_TOOLKIT_WIDTH;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback, useContext, useSyncExternalStore } from 'react';
|
|
2
|
+
import { NavigationRouteContext } from '@react-navigation/native';
|
|
3
|
+
|
|
4
|
+
const widths = new Map<string, number>();
|
|
5
|
+
const listeners = new Set<() => void>();
|
|
6
|
+
|
|
7
|
+
const notify = () => {
|
|
8
|
+
listeners.forEach(listener => listener());
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const subscribe = (listener: () => void) => {
|
|
12
|
+
listeners.add(listener);
|
|
13
|
+
return () => {
|
|
14
|
+
listeners.delete(listener);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Records the laid out width of a route's header right, side padding included;
|
|
20
|
+
* `undefined` clears it when the header right unmounts.
|
|
21
|
+
*/
|
|
22
|
+
const setHeaderRightWidth = (routeKey: string, width?: number) => {
|
|
23
|
+
if (widths.get(routeKey) === width) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (width === undefined) {
|
|
27
|
+
widths.delete(routeKey);
|
|
28
|
+
} else {
|
|
29
|
+
widths.set(routeKey, width);
|
|
30
|
+
}
|
|
31
|
+
notify();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Measured header right width of the current route, so searches stop short of
|
|
36
|
+
* the shortcut and toolkit. `undefined` until the header right lays out.
|
|
37
|
+
*/
|
|
38
|
+
const useHeaderRightWidth = (): number | undefined => {
|
|
39
|
+
const routeKey = useContext(NavigationRouteContext)?.key;
|
|
40
|
+
const getSnapshot = useCallback(() => {
|
|
41
|
+
return routeKey ? widths.get(routeKey) : undefined;
|
|
42
|
+
}, [routeKey]);
|
|
43
|
+
return useSyncExternalStore(subscribe, getSnapshot);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { setHeaderRightWidth, useHeaderRightWidth };
|
|
@@ -8,6 +8,8 @@ import { isIPhoneDuo } from './utils';
|
|
|
8
8
|
|
|
9
9
|
// Top navigation spec, shared with the Compose / SwiftUI kits
|
|
10
10
|
const HEADER_FRAME_MAX_WIDTH = 600;
|
|
11
|
+
// stretch frame on hold until design confirms it: `stretch` lays out like `grid`
|
|
12
|
+
const IS_STRETCH_FRAME_ENABLED = false;
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Top navigation geometry on every device
|
|
@@ -35,7 +37,8 @@ const HeaderBarMetrics = {
|
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
39
|
* `grid` keeps the header row at the bar edges, `stretch` centers it in a 600pt
|
|
38
|
-
* frame on wide windows
|
|
40
|
+
* frame on wide windows (on hold: same as `grid` for now). Background and status
|
|
41
|
+
* bar always span the window.
|
|
39
42
|
*/
|
|
40
43
|
type HeaderContentLayout = 'grid' | 'stretch';
|
|
41
44
|
|
|
@@ -81,7 +84,8 @@ const getHeaderLayout = ({
|
|
|
81
84
|
const isLargeWindow = Math.min(width, height) >= FOLDABLE_MIN_WIDTH;
|
|
82
85
|
const isWide = !isDuo && isLargeWindow;
|
|
83
86
|
let frameInset = sidePadding;
|
|
84
|
-
|
|
87
|
+
const isStretch = IS_STRETCH_FRAME_ENABLED && contentLayout === 'stretch';
|
|
88
|
+
if (isWide && isStretch) {
|
|
85
89
|
const centered = (width - HEADER_FRAME_MAX_WIDTH) / 2;
|
|
86
90
|
frameInset = Math.max(sidePadding, centered);
|
|
87
91
|
}
|
|
@@ -134,7 +138,7 @@ const useHeaderFrameOptions = (
|
|
|
134
138
|
const { width } = useWindowDimensions();
|
|
135
139
|
const isDuo = isIPhoneDuo();
|
|
136
140
|
return useMemo(() => {
|
|
137
|
-
if (contentLayout !== 'stretch' || isDuo) {
|
|
141
|
+
if (!IS_STRETCH_FRAME_ENABLED || contentLayout !== 'stretch' || isDuo) {
|
|
138
142
|
return undefined;
|
|
139
143
|
}
|
|
140
144
|
// the header content row already sits this far in on large iOS windows
|