@momo-kits/foundation 0.169.11-beta.2 → 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.
|
@@ -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 };
|