Skip to content

Commit a46409f

Browse files
committed
feat: 调整pageWrapper 包裹逻辑
1 parent 861eabb commit a46409f

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

packages/core/src/platform/patch/getDefaultOptions.ios.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,12 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
554554

555555
if (type === 'page') {
556556
const pageConfig = Object.assign({}, global.__mpxPageConfig, currentInject.pageConfig)
557-
return createElement(
557+
return ({ navigation, route }) => createElement(
558558
PageWrapper, {
559559
pageConfig,
560-
pageStatusMap
560+
pageStatusMap,
561+
navigation,
562+
route
561563
},
562564
defaultOptions
563565
)

packages/core/src/platform/patch/pageWrapper.js

+35-31
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const { useSafeAreaInsets } = global.__navigationHelper
3636
function PageWrapper ({
3737
children,
3838
navigation,
39-
pageConfig = {},
39+
pageConfig,
4040
route,
4141
pageStatusMap
4242
}) {
@@ -47,37 +47,41 @@ function PageWrapper ({
4747
navigation,
4848
pageId
4949
})
50-
console.log('route_____ 测试 route', route, navigation)
5150
const currentPageId = useMemo(() => ++pageId, [])
52-
usePageStatus(navigation, currentPageId, pageStatusMap)
53-
useLayoutEffect(() => {
54-
const isCustom = pageConfig.navigationStyle === 'custom'
55-
navigation.setOptions({
56-
headerShown: !isCustom,
57-
title: pageConfig.navigationBarTitleText?.trim() || '',
58-
headerStyle: {
59-
backgroundColor: pageConfig.navigationBarBackgroundColor || '#000000'
60-
},
61-
headerTintColor: pageConfig.navigationBarTextStyle || 'white'
62-
})
6351

64-
if (__mpx_mode__ === 'android') {
65-
ReactNative.StatusBar.setBarStyle(pageConfig.barStyle || 'dark-content')
66-
ReactNative.StatusBar.setTranslucent(isCustom) // 控制statusbar是否占位
67-
const color = isCustom ? 'transparent' : pageConfig.statusBarColor
68-
color && ReactNative.StatusBar.setBackgroundColor(color)
52+
if (navigation) {
53+
usePageStatus(navigation, currentPageId, pageStatusMap)
54+
if (pageConfig) {
55+
useLayoutEffect(() => {
56+
const isCustom = pageConfig.navigationStyle === 'custom'
57+
navigation.setOptions({
58+
headerShown: !isCustom,
59+
title: pageConfig.navigationBarTitleText?.trim() || '',
60+
headerStyle: {
61+
backgroundColor: pageConfig.navigationBarBackgroundColor || '#000000'
62+
},
63+
headerTintColor: pageConfig.navigationBarTextStyle || 'white'
64+
})
65+
66+
if (__mpx_mode__ === 'android') {
67+
ReactNative.StatusBar.setBarStyle(pageConfig.barStyle || 'dark-content')
68+
ReactNative.StatusBar.setTranslucent(isCustom) // 控制statusbar是否占位
69+
const color = isCustom ? 'transparent' : pageConfig.statusBarColor
70+
color && ReactNative.StatusBar.setBackgroundColor(color)
71+
}
72+
}, [])
6973
}
70-
}, [])
71-
72-
useEffect(() => {
73-
setTimeout(() => {
74-
rootRef.current?.measureInWindow((x, y, width, height) => {
75-
navigation.layout = { x, y, width, height }
76-
})
77-
}, 100)
78-
}, [])
79-
80-
navigation.insets = useSafeAreaInsets()
74+
75+
useEffect(() => {
76+
setTimeout(() => {
77+
rootRef.current?.measureInWindow((x, y, width, height) => {
78+
navigation.layout = { x, y, width, height }
79+
})
80+
}, 100)
81+
}, [])
82+
navigation.insets = useSafeAreaInsets()
83+
}
84+
8185

8286
const withKeyboardAvoidingView = (element) => {
8387
return createElement(KeyboardAvoidContext.Provider,
@@ -101,7 +105,7 @@ function PageWrapper ({
101105
return createElement(GestureHandlerRootView,
102106
{
103107
// https://github.com/software-mansion/react-native-reanimated/issues/6639 因存在此问题,iOS在页面上进行定宽来暂时规避
104-
style: __mpx_mode__ === 'ios' && pageConfig.navigationStyle !== 'custom'
108+
style: __mpx_mode__ === 'ios' && pageConfig?.navigationStyle !== 'custom'
105109
? {
106110
height: ReactNative.Dimensions.get('screen').height - useHeaderHeight()
107111
}
@@ -114,7 +118,7 @@ function PageWrapper ({
114118
{
115119
style: {
116120
flex: 1,
117-
backgroundColor: pageConfig.backgroundColor || '#fff'
121+
backgroundColor: pageConfig?.backgroundColor || '#fff'
118122
},
119123
ref: rootRef
120124
},

0 commit comments

Comments
 (0)