Skip to content

Commit

Permalink
feat: 修复Android某些机型statusbar状态被其他页面影响的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuzhh committed Dec 23, 2024
1 parent 2a72f25 commit 5858bf7
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/core/src/platform/patch/react/getDefaultOptions.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ function usePageStatus (navigation, pageId) {
}, [navigation])
}

const pageConfigStack = []
export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
rawOptions = mergeOptions(rawOptions, type, false)
const components = Object.assign({}, rawOptions.components, currentInject.getComponents())
Expand Down Expand Up @@ -455,12 +456,24 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
},
headerTintColor: pageConfig.navigationBarTextStyle || 'white'
})
if (__mpx_mode__ === 'android') {
ReactNative.StatusBar.setBarStyle(pageConfig.barStyle || 'dark-content')

const setStatusBar = (config) => {
ReactNative.StatusBar.setBarStyle(config.barStyle || 'dark-content')
ReactNative.StatusBar.setTranslucent(isCustom) // 控制statusbar是否占位
const color = isCustom ? 'transparent' : pageConfig.statusBarColor
const color = isCustom ? 'transparent' : config.statusBarColor
color && ReactNative.StatusBar.setBackgroundColor(color)
}
if (__mpx_mode__ === 'android') {
pageConfigStack.push(pageConfig)
setStatusBar(pageConfig)
}
return () => {
if (__mpx_mode__ === 'android') {
pageConfigStack.pop()
const config = pageConfigStack[pageConfigStack.length - 1] || {}
setStatusBar(config)
}
};
}, [])

const rootRef = useRef(null)
Expand Down

0 comments on commit 5858bf7

Please sign in to comment.