提交 c5587266 编写于 作者: D DCloud_LXH

fix(app): darkmode statusBarStyle question/157497

上级 3d598a08
...@@ -48,7 +48,7 @@ export function getAppBaseInfo () { ...@@ -48,7 +48,7 @@ export function getAppBaseInfo () {
hostPackageName, hostName, osLanguage, hostPackageName, hostName, osLanguage,
hostVersion, hostLanguage, hostTheme, hostVersion, hostLanguage, hostTheme,
appId, appName, appVersion, appVersionCode, appId, appName, appVersion, appVersionCode,
appWgtVersion, osTheme appWgtVersion
} = systemInfo } = systemInfo
const appLanguage = uni const appLanguage = uni
...@@ -74,7 +74,7 @@ export function getAppBaseInfo () { ...@@ -74,7 +74,7 @@ export function getAppBaseInfo () {
hostFontSizeSetting: undefined, hostFontSizeSetting: undefined,
language: osLanguage, language: osLanguage,
SDKVersion: '', SDKVersion: '',
theme: hostTheme || osTheme, theme: plus.navigator.getUIStyle(),
version: plus.runtime.innerVersion version: plus.runtime.innerVersion
} }
} }
......
...@@ -52,6 +52,8 @@ import { ...@@ -52,6 +52,8 @@ import {
parseRedirectInfo parseRedirectInfo
} from './utils' } from './utils'
import { changePagesNavigatorStyle } from './theme'
let appCtx let appCtx
const defaultApp = { const defaultApp = {
...@@ -131,6 +133,7 @@ function initGlobalListeners () { ...@@ -131,6 +133,7 @@ function initGlobalListeners () {
publish('onUIStyleChange', { publish('onUIStyleChange', {
style: event.uistyle style: event.uistyle
}) })
changePagesNavigatorStyle()
}) })
globalEvent.addEventListener('uniMPNativeEvent', function (event) { globalEvent.addEventListener('uniMPNativeEvent', function (event) {
......
import { normallizeStyles } from 'uni-shared' import { normallizeStyles } from 'uni-shared'
import { weexGetSystemInfoSync } from '../api/device/system' import { weexGetSystemInfoSync } from '../api/device/system'
import { setStatusBarStyle } from '../bridge'
import { getCurrentPages } from './page'
const ON_THEME_CHANGE = 'api.onThemeChange' const ON_THEME_CHANGE = 'api.onThemeChange'
...@@ -11,13 +13,28 @@ function offThemeChange (callback = () => { }) { ...@@ -11,13 +13,28 @@ function offThemeChange (callback = () => { }) {
UniServiceJSBridge.off(ON_THEME_CHANGE, callback) UniServiceJSBridge.off(ON_THEME_CHANGE, callback)
} }
function getNavigatorStyle () {
return plus.navigator.getUIStyle() === 'dark' ? 'light' : 'dark'
}
export function changePagesNavigatorStyle () {
const theme = getNavigatorStyle()
setStatusBarStyle(theme)
const pages = getCurrentPages(true)
pages.forEach((page) => {
page.$page.meta.statusBarStyle = theme
})
}
export function parseTheme (pageStyle) { export function parseTheme (pageStyle) {
let parsedStyle = {} let parsedStyle = {}
if (__uniConfig.darkmode) { if (__uniConfig.darkmode) {
let theme = 'light' let theme = plus.navigator.getUIStyle()
const systemInfo = weexGetSystemInfoSync() const systemInfo = weexGetSystemInfoSync()
if (systemInfo) { if (systemInfo && systemInfo.hostTheme) {
theme = systemInfo.hostTheme || systemInfo.osTheme theme = systemInfo.hostTheme
} }
parsedStyle = normallizeStyles(pageStyle, __uniConfig.themeConfig, theme) parsedStyle = normallizeStyles(pageStyle, __uniConfig.themeConfig, theme)
} }
......
...@@ -106,5 +106,6 @@ export function parseWebviewStyle (id, path, _routeOptions = {}) { ...@@ -106,5 +106,6 @@ export function parseWebviewStyle (id, path, _routeOptions = {}) {
} }
} }
_routeOptions.meta = routeOptions.meta
return webviewStyle return webviewStyle
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册