forked from dcloudio/uni-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1a9e2c
commit cd01f6b
Showing
11 changed files
with
228 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { normallizeStyles } from 'uni-shared' | ||
import { weexGetSystemInfoSync } from '../api/device/system' | ||
|
||
const ON_THEME_CHANGE = 'api.onThemeChange' | ||
|
||
function onThemeChange (callback = () => { }) { | ||
UniServiceJSBridge.on(ON_THEME_CHANGE, callback) | ||
} | ||
|
||
function offThemeChange (callback = () => { }) { | ||
UniServiceJSBridge.off(ON_THEME_CHANGE, callback) | ||
} | ||
|
||
export function parseTheme (pageStyle) { | ||
let parsedStyle = {} | ||
if (__uniConfig.darkmode) { | ||
let theme = 'light' | ||
const systemInfo = weexGetSystemInfoSync() | ||
if (systemInfo) { | ||
theme = systemInfo.hostTheme || systemInfo.osTheme | ||
} | ||
parsedStyle = normallizeStyles(pageStyle, __uniConfig.themeConfig, theme) | ||
} | ||
return __uniConfig.darkmode ? parsedStyle : pageStyle | ||
} | ||
|
||
export function useTabBarThemeChange (tabBar, options) { | ||
if (__uniConfig.darkmode) { | ||
const fn = () => { | ||
const { | ||
list = [], color, selectedColor, | ||
backgroundColor, borderStyle | ||
} = parseTheme(options, false) | ||
const tabbarStyle = { | ||
color, | ||
selectedColor, | ||
backgroundColor, | ||
borderStyle | ||
} | ||
|
||
tabBar && tabBar.setTabBarStyle(tabbarStyle) | ||
tabBar && tabBar.setTabBarItems({ | ||
list: list.map((item) => ({ | ||
iconPath: item.iconPath, | ||
selectedIconPath: item.selectedIconPath | ||
})) | ||
}) | ||
// TODO 暂未实现 | ||
// tabBar && tabBar.setAnimationAlphaBGColor(parseTheme((__uniConfig.window || {}).backgroundColor, false)) | ||
} | ||
|
||
fn() | ||
|
||
onThemeChange(fn) | ||
} | ||
} | ||
|
||
export function useWebviewThemeChange (webview, getWebviewStyle) { | ||
if (__uniConfig.darkmode) { | ||
const fn = () => { | ||
const { | ||
animationAlphaBGColor, background, | ||
backgroundColorBottom, backgroundColorTop, | ||
titleNView: { backgroundColor, titleColor } = {} | ||
} = getWebviewStyle() | ||
webview && webview.setStyle({ | ||
animationAlphaBGColor, | ||
background, | ||
backgroundColorBottom, | ||
backgroundColorTop, | ||
titleNView: { | ||
backgroundColor, | ||
titleColor | ||
} | ||
}) | ||
} | ||
onThemeChange(fn) | ||
webview.addEventListener('close', () => offThemeChange(fn)) | ||
} | ||
} |
Oops, something went wrong.