@mpxjs/webpack-plugin 2.10.14-beta.5 → 2.10.14-beta.6
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/lib/runtime/components/react/context.ts +0 -1
- package/lib/runtime/components/react/dist/context.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts +0 -7
- package/lib/runtime/components/react/dist/mpx-input.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +9 -7
- package/lib/runtime/components/react/dist/nav.d.ts +2 -5
- package/lib/runtime/components/react/dist/nav.jsx +54 -58
- package/lib/runtime/components/react/mpx-input.tsx +1 -9
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +15 -13
- package/lib/runtime/components/react/nav.tsx +67 -76
- package/package.json +1 -1
|
@@ -32,13 +32,6 @@ export interface InputProps {
|
|
|
32
32
|
'parent-width'?: number;
|
|
33
33
|
'parent-height'?: number;
|
|
34
34
|
'adjust-position': boolean;
|
|
35
|
-
/**
|
|
36
|
-
* @default true
|
|
37
|
-
* @platform android
|
|
38
|
-
*
|
|
39
|
-
* adnroid 是否开启原生键盘遮挡
|
|
40
|
-
*/
|
|
41
|
-
'enable-native-keyboard-avoiding'?: boolean;
|
|
42
35
|
bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void;
|
|
43
36
|
bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
|
|
44
37
|
bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
|
|
@@ -52,7 +52,7 @@ const keyboardTypeMap = {
|
|
|
52
52
|
digit: isIOS ? 'decimal-pad' : 'numeric'
|
|
53
53
|
};
|
|
54
54
|
const Input = forwardRef((props, ref) => {
|
|
55
|
-
const { style = {}, allowFontScaling = false, type = 'text', value, password, 'placeholder-style': placeholderStyle = {}, disabled, maxlength = 140, 'cursor-spacing': cursorSpacing = 0, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'adjust-position': adjustPosition = true,
|
|
55
|
+
const { style = {}, allowFontScaling = false, type = 'text', value, password, 'placeholder-style': placeholderStyle = {}, disabled, maxlength = 140, 'cursor-spacing': cursorSpacing = 0, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'adjust-position': adjustPosition = true, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
|
|
56
56
|
// private
|
|
57
57
|
multiline, 'auto-height': autoHeight, bindlinechange } = props;
|
|
58
58
|
const formContext = useContext(FormContext);
|
|
@@ -145,7 +145,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
145
145
|
};
|
|
146
146
|
const setKeyboardAvoidContext = () => {
|
|
147
147
|
if (keyboardAvoid) {
|
|
148
|
-
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition
|
|
148
|
+
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition };
|
|
149
149
|
}
|
|
150
150
|
};
|
|
151
151
|
const onTouchStart = () => {
|
|
@@ -15,7 +15,7 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
|
15
15
|
const isShow = useRef(false);
|
|
16
16
|
const timerRef = useRef(null);
|
|
17
17
|
const animatedStyle = useAnimatedStyle(() => ({
|
|
18
|
-
// translate/position top
|
|
18
|
+
// translate/position top可能会导致底部渲染区域缺失
|
|
19
19
|
marginTop: -offset.value,
|
|
20
20
|
flexBasis: basic.value
|
|
21
21
|
}));
|
|
@@ -53,19 +53,20 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
|
53
53
|
timerRef.current && clearTimeout(timerRef.current);
|
|
54
54
|
}
|
|
55
55
|
const { endCoordinates } = evt;
|
|
56
|
-
const { ref, cursorSpacing = 0, adjustPosition, onKeyboardShow
|
|
56
|
+
const { ref, cursorSpacing = 0, adjustPosition, onKeyboardShow } = keyboardAvoid.current;
|
|
57
57
|
keyboardAvoid.current.keyboardHeight = endCoordinates.height;
|
|
58
58
|
onKeyboardShow?.();
|
|
59
59
|
if (adjustPosition) {
|
|
60
|
-
|
|
60
|
+
// 默认沿用旧版本逻辑,在 android 原生关闭键盘避让的情况下应该将该配置设置为 false,走 mpx 的键盘避让逻辑,否则bundle内的所有input都会无法避让键盘
|
|
61
|
+
const enableNativeKeyboardAvoiding = mpxGlobal?.__mpx?.config?.rnConfig?.enableNativeKeyboardAvoiding ?? true;
|
|
62
|
+
const callback = () => {
|
|
61
63
|
ref?.current?.measure((x, y, width, height, pageX, pageY) => {
|
|
62
64
|
function calculateOffset() {
|
|
63
65
|
// enableNativeKeyboardAvoding 默认开启
|
|
64
66
|
if (enableNativeKeyboardAvoiding && isAndroid) {
|
|
65
|
-
const aboveOffset = pageY + height - endCoordinates.screenY;
|
|
66
|
-
const belowOffset = endCoordinates.height - aboveOffset;
|
|
67
|
+
const aboveOffset = offset.value + pageY + height - endCoordinates.screenY;
|
|
67
68
|
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing;
|
|
68
|
-
const belowValue = Math.min(
|
|
69
|
+
const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing);
|
|
69
70
|
return aboveOffset > 0 ? belowValue : aboveValue;
|
|
70
71
|
}
|
|
71
72
|
const aboveOffset = offset.value + pageY + height - endCoordinates.screenY;
|
|
@@ -81,7 +82,8 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
|
81
82
|
}
|
|
82
83
|
});
|
|
83
84
|
});
|
|
84
|
-
}
|
|
85
|
+
};
|
|
86
|
+
(isIOS ? () => (timerRef.current = setTimeout(callback)) : callback)();
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
if (isIOS) {
|
|
@@ -4,8 +4,5 @@ export interface MpxNavProps {
|
|
|
4
4
|
pageConfig: PageConfig;
|
|
5
5
|
navigation: any;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
declare function createMpxNav(options: MpxNavFactorOptions): import("react").MemoExoticComponent<({ pageConfig, navigation }: MpxNavProps) => import("react").JSX.Element>;
|
|
11
|
-
export default createMpxNav;
|
|
7
|
+
declare const MpxNav: import("react").MemoExoticComponent<({ pageConfig, navigation }: MpxNavProps) => import("react").JSX.Element>;
|
|
8
|
+
export default MpxNav;
|
|
@@ -79,63 +79,59 @@ const validBarTextStyle = (textStyle) => {
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
const BACK_ICON = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg==';
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (isCustom)
|
|
96
|
-
return (<>
|
|
97
|
-
{statusBarElement}
|
|
98
|
-
{customNav}
|
|
99
|
-
</>);
|
|
100
|
-
// 假设是栈导航,获取栈的长度
|
|
101
|
-
const stackLength = navigation.getState()?.routes?.length;
|
|
102
|
-
const onStackTopBack = Mpx.config?.rnConfig?.onStackTopBack;
|
|
103
|
-
const isHandleStackTopBack = typeof onStackTopBack === 'function';
|
|
104
|
-
// 回退按钮与图标
|
|
105
|
-
// prettier-ignore
|
|
106
|
-
const backElement = stackLength > 1 || isHandleStackTopBack
|
|
107
|
-
? (<TouchableWithoutFeedback onPress={() => {
|
|
108
|
-
if (stackLength <= 1 && isHandleStackTopBack) {
|
|
109
|
-
onStackTopBack();
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
navigation.goBack();
|
|
113
|
-
}}>
|
|
114
|
-
<View style={[styles.backButton]}>
|
|
115
|
-
<Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
|
|
116
|
-
</View>
|
|
117
|
-
</TouchableWithoutFeedback>)
|
|
118
|
-
: null;
|
|
119
|
-
return (<View style={[
|
|
120
|
-
styles.header,
|
|
121
|
-
{
|
|
122
|
-
paddingTop: safeAreaTop,
|
|
123
|
-
backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
|
|
124
|
-
}
|
|
125
|
-
]}>
|
|
82
|
+
const MpxNav = memo(({ pageConfig, navigation }) => {
|
|
83
|
+
const [innerPageConfig, setPageConfig] = useState(pageConfig || {});
|
|
84
|
+
const [customNav] = useNavShared();
|
|
85
|
+
const safeAreaTop = useSafeAreaInsets()?.top || 0;
|
|
86
|
+
navigation.setPageConfig = (config) => {
|
|
87
|
+
setPageConfig(Object.assign({}, innerPageConfig, config));
|
|
88
|
+
};
|
|
89
|
+
const isCustom = innerPageConfig.navigationStyle === 'custom';
|
|
90
|
+
const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle]);
|
|
91
|
+
// 状态栏的颜色
|
|
92
|
+
const statusBarElement = (<StatusBar translucent backgroundColor='transparent' barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>);
|
|
93
|
+
if (isCustom)
|
|
94
|
+
return (<>
|
|
126
95
|
{statusBarElement}
|
|
127
|
-
{
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
96
|
+
{customNav}
|
|
97
|
+
</>);
|
|
98
|
+
// 假设是栈导航,获取栈的长度
|
|
99
|
+
const stackLength = navigation.getState()?.routes?.length;
|
|
100
|
+
const onStackTopBack = mpxGlobal?.__mpx?.config?.rnConfig?.onStackTopBack;
|
|
101
|
+
const isHandleStackTopBack = typeof onStackTopBack === 'function';
|
|
102
|
+
// 回退按钮与图标
|
|
103
|
+
// prettier-ignore
|
|
104
|
+
const backElement = stackLength > 1 || isHandleStackTopBack
|
|
105
|
+
? (<TouchableWithoutFeedback onPress={() => {
|
|
106
|
+
if (stackLength <= 1 && isHandleStackTopBack) {
|
|
107
|
+
onStackTopBack();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
navigation.goBack();
|
|
111
|
+
}}>
|
|
112
|
+
<View style={[styles.backButton]}>
|
|
113
|
+
<Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
|
|
135
114
|
</View>
|
|
136
|
-
</
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
115
|
+
</TouchableWithoutFeedback>)
|
|
116
|
+
: null;
|
|
117
|
+
return (<View style={[
|
|
118
|
+
styles.header,
|
|
119
|
+
{
|
|
120
|
+
paddingTop: safeAreaTop,
|
|
121
|
+
backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
|
|
122
|
+
}
|
|
123
|
+
]}>
|
|
124
|
+
{statusBarElement}
|
|
125
|
+
{/* TODO: 确定 height 的有效性 */}
|
|
126
|
+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
|
|
127
|
+
{/* @ts-expect-error */}
|
|
128
|
+
<View style={styles.headerContent} height={titleHeight}>
|
|
129
|
+
{backElement}
|
|
130
|
+
<Text style={[styles.title, { color: navigationBarTextStyle }]} numberOfLines={1}>
|
|
131
|
+
{innerPageConfig.navigationBarTitleText?.trim() || ''}
|
|
132
|
+
</Text>
|
|
133
|
+
</View>
|
|
134
|
+
</View>);
|
|
135
|
+
});
|
|
136
|
+
MpxNav.displayName = 'MpxNav';
|
|
137
|
+
export default MpxNav;
|
|
@@ -102,13 +102,6 @@ export interface InputProps {
|
|
|
102
102
|
'parent-width'?: number
|
|
103
103
|
'parent-height'?: number
|
|
104
104
|
'adjust-position': boolean,
|
|
105
|
-
/**
|
|
106
|
-
* @default true
|
|
107
|
-
* @platform android
|
|
108
|
-
*
|
|
109
|
-
* adnroid 是否开启原生键盘遮挡
|
|
110
|
-
*/
|
|
111
|
-
'enable-native-keyboard-avoiding'?: boolean,
|
|
112
105
|
bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void
|
|
113
106
|
bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
|
|
114
107
|
bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
|
|
@@ -157,7 +150,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
157
150
|
'parent-width': parentWidth,
|
|
158
151
|
'parent-height': parentHeight,
|
|
159
152
|
'adjust-position': adjustPosition = true,
|
|
160
|
-
'enable-native-keyboard-avoiding': enableNativeKeyboardAvoiding = true,
|
|
161
153
|
bindinput,
|
|
162
154
|
bindfocus,
|
|
163
155
|
bindblur,
|
|
@@ -289,7 +281,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
289
281
|
|
|
290
282
|
const setKeyboardAvoidContext = () => {
|
|
291
283
|
if (keyboardAvoid) {
|
|
292
|
-
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition
|
|
284
|
+
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition }
|
|
293
285
|
}
|
|
294
286
|
}
|
|
295
287
|
|
|
@@ -25,7 +25,7 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
25
25
|
const timerRef = useRef<NodeJS.Timeout | null>(null)
|
|
26
26
|
|
|
27
27
|
const animatedStyle = useAnimatedStyle(() => ({
|
|
28
|
-
// translate/position top
|
|
28
|
+
// translate/position top可能会导致底部渲染区域缺失
|
|
29
29
|
marginTop: -offset.value,
|
|
30
30
|
flexBasis: basic.value as DimensionValue
|
|
31
31
|
}))
|
|
@@ -73,26 +73,27 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
const { endCoordinates } = evt
|
|
76
|
-
const { ref, cursorSpacing = 0, adjustPosition, onKeyboardShow
|
|
76
|
+
const { ref, cursorSpacing = 0, adjustPosition, onKeyboardShow } = keyboardAvoid.current
|
|
77
77
|
keyboardAvoid.current.keyboardHeight = endCoordinates.height
|
|
78
78
|
onKeyboardShow?.()
|
|
79
79
|
if (adjustPosition) {
|
|
80
|
-
|
|
80
|
+
// 默认沿用旧版本逻辑,在 android 原生关闭键盘避让的情况下应该将该配置设置为 false,走 mpx 的键盘避让逻辑,否则bundle内的所有input都会无法避让键盘
|
|
81
|
+
const enableNativeKeyboardAvoiding = mpxGlobal?.__mpx?.config?.rnConfig?.enableNativeKeyboardAvoiding ?? true
|
|
82
|
+
const callback = () => {
|
|
81
83
|
ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
|
|
82
84
|
function calculateOffset() {
|
|
83
85
|
// enableNativeKeyboardAvoding 默认开启
|
|
84
86
|
if (enableNativeKeyboardAvoiding && isAndroid) {
|
|
85
|
-
const aboveOffset = pageY + height - endCoordinates.screenY
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
return aboveOffset > 0 ? belowValue : aboveValue
|
|
87
|
+
const aboveOffset = offset.value + pageY + height - endCoordinates.screenY;
|
|
88
|
+
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing;
|
|
89
|
+
const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing);
|
|
90
|
+
return aboveOffset > 0 ? belowValue : aboveValue;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
const aboveOffset = offset.value + pageY + height - endCoordinates.screenY
|
|
93
|
-
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
|
|
94
|
-
const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing)
|
|
95
|
-
return aboveOffset > 0 ? belowValue : aboveValue
|
|
93
|
+
const aboveOffset = offset.value + pageY + height - endCoordinates.screenY;
|
|
94
|
+
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing;
|
|
95
|
+
const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing);
|
|
96
|
+
return aboveOffset > 0 ? belowValue : aboveValue;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
cancelAnimation(offset)
|
|
@@ -103,7 +104,8 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
103
104
|
}
|
|
104
105
|
})
|
|
105
106
|
})
|
|
106
|
-
}
|
|
107
|
+
};
|
|
108
|
+
(isIOS ? () => (timerRef.current = setTimeout(callback)) : callback)();
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
|
|
@@ -84,89 +84,80 @@ export interface MpxNavProps {
|
|
|
84
84
|
navigation: any
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
export interface MpxNavFactorOptions {
|
|
88
|
-
Mpx: any
|
|
89
|
-
}
|
|
90
|
-
|
|
91
87
|
const BACK_ICON =
|
|
92
88
|
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg=='
|
|
93
89
|
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
const [customNav] = useNavShared()
|
|
99
|
-
const safeAreaTop = useSafeAreaInsets()?.top || 0
|
|
100
|
-
|
|
101
|
-
navigation.setPageConfig = (config: PageConfig) => {
|
|
102
|
-
setPageConfig(Object.assign({}, innerPageConfig, config))
|
|
103
|
-
}
|
|
104
|
-
const isCustom = innerPageConfig.navigationStyle === 'custom'
|
|
105
|
-
const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
|
|
106
|
-
// 状态栏的颜色
|
|
107
|
-
const statusBarElement = (
|
|
108
|
-
<StatusBar
|
|
109
|
-
translucent
|
|
110
|
-
backgroundColor='transparent'
|
|
111
|
-
barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>
|
|
112
|
-
)
|
|
90
|
+
const MpxNav = memo(({ pageConfig, navigation }: MpxNavProps) => {
|
|
91
|
+
const [innerPageConfig, setPageConfig] = useState<PageConfig>(pageConfig || {})
|
|
92
|
+
const [customNav] = useNavShared()
|
|
93
|
+
const safeAreaTop = useSafeAreaInsets()?.top || 0
|
|
113
94
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// 回退按钮与图标
|
|
127
|
-
// prettier-ignore
|
|
128
|
-
const backElement = stackLength > 1 || isHandleStackTopBack
|
|
129
|
-
? (
|
|
130
|
-
<TouchableWithoutFeedback
|
|
131
|
-
onPress={() => {
|
|
132
|
-
if (stackLength <= 1 && isHandleStackTopBack) {
|
|
133
|
-
onStackTopBack()
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
navigation.goBack()
|
|
137
|
-
}}>
|
|
138
|
-
<View style={[styles.backButton]}>
|
|
139
|
-
<Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
|
|
140
|
-
</View>
|
|
141
|
-
</TouchableWithoutFeedback>
|
|
142
|
-
)
|
|
143
|
-
: null
|
|
95
|
+
navigation.setPageConfig = (config: PageConfig) => {
|
|
96
|
+
setPageConfig(Object.assign({}, innerPageConfig, config))
|
|
97
|
+
}
|
|
98
|
+
const isCustom = innerPageConfig.navigationStyle === 'custom'
|
|
99
|
+
const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
|
|
100
|
+
// 状态栏的颜色
|
|
101
|
+
const statusBarElement = (
|
|
102
|
+
<StatusBar
|
|
103
|
+
translucent
|
|
104
|
+
backgroundColor='transparent'
|
|
105
|
+
barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>
|
|
106
|
+
)
|
|
144
107
|
|
|
108
|
+
if (isCustom)
|
|
145
109
|
return (
|
|
146
|
-
|
|
147
|
-
style={[
|
|
148
|
-
styles.header,
|
|
149
|
-
{
|
|
150
|
-
paddingTop: safeAreaTop,
|
|
151
|
-
backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
|
|
152
|
-
}
|
|
153
|
-
]}>
|
|
110
|
+
<>
|
|
154
111
|
{statusBarElement}
|
|
155
|
-
{
|
|
156
|
-
|
|
157
|
-
{/* @ts-expect-error */}
|
|
158
|
-
<View style={styles.headerContent} height={titleHeight}>
|
|
159
|
-
{backElement}
|
|
160
|
-
<Text style={[styles.title, { color: navigationBarTextStyle }]} numberOfLines={1}>
|
|
161
|
-
{innerPageConfig.navigationBarTitleText?.trim() || ''}
|
|
162
|
-
</Text>
|
|
163
|
-
</View>
|
|
164
|
-
</View>
|
|
112
|
+
{customNav}
|
|
113
|
+
</>
|
|
165
114
|
)
|
|
166
|
-
|
|
115
|
+
// 假设是栈导航,获取栈的长度
|
|
116
|
+
const stackLength = navigation.getState()?.routes?.length
|
|
117
|
+
const onStackTopBack = mpxGlobal?.__mpx?.config?.rnConfig?.onStackTopBack
|
|
118
|
+
const isHandleStackTopBack = typeof onStackTopBack === 'function'
|
|
167
119
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
120
|
+
// 回退按钮与图标
|
|
121
|
+
// prettier-ignore
|
|
122
|
+
const backElement = stackLength > 1 || isHandleStackTopBack
|
|
123
|
+
? (
|
|
124
|
+
<TouchableWithoutFeedback
|
|
125
|
+
onPress={() => {
|
|
126
|
+
if (stackLength <= 1 && isHandleStackTopBack) {
|
|
127
|
+
onStackTopBack()
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
navigation.goBack()
|
|
131
|
+
}}>
|
|
132
|
+
<View style={[styles.backButton]}>
|
|
133
|
+
<Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
|
|
134
|
+
</View>
|
|
135
|
+
</TouchableWithoutFeedback>
|
|
136
|
+
)
|
|
137
|
+
: null
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<View
|
|
141
|
+
style={[
|
|
142
|
+
styles.header,
|
|
143
|
+
{
|
|
144
|
+
paddingTop: safeAreaTop,
|
|
145
|
+
backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
|
|
146
|
+
}
|
|
147
|
+
]}>
|
|
148
|
+
{statusBarElement}
|
|
149
|
+
{/* TODO: 确定 height 的有效性 */}
|
|
150
|
+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
|
|
151
|
+
{/* @ts-expect-error */}
|
|
152
|
+
<View style={styles.headerContent} height={titleHeight}>
|
|
153
|
+
{backElement}
|
|
154
|
+
<Text style={[styles.title, { color: navigationBarTextStyle }]} numberOfLines={1}>
|
|
155
|
+
{innerPageConfig.navigationBarTitleText?.trim() || ''}
|
|
156
|
+
</Text>
|
|
157
|
+
</View>
|
|
158
|
+
</View>
|
|
159
|
+
)
|
|
160
|
+
})
|
|
171
161
|
|
|
172
|
-
|
|
162
|
+
MpxNav.displayName = 'MpxNav'
|
|
163
|
+
export default MpxNav
|