From d4c4541546fed563299e210cb88f73449512031e Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 15 May 2024 19:12:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20darkmode=20=E6=94=AF=E6=8C=81=20mi?= =?UTF-8?q?dButton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app-plus/service/framework/theme.js | 37 ++++++++++--------- src/platforms/h5/components/theme.js | 4 +- src/shared/theme.js | 6 +-- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/platforms/app-plus/service/framework/theme.js b/src/platforms/app-plus/service/framework/theme.js index 3fdca941e42..f58d9b02908 100644 --- a/src/platforms/app-plus/service/framework/theme.js +++ b/src/platforms/app-plus/service/framework/theme.js @@ -1,4 +1,4 @@ -import { normallizeStyles } from 'uni-shared' +import { normalizeStyles } from 'uni-shared' import { weexGetSystemInfoSync } from '../api/device/system' import { setStatusBarStyle } from '../bridge' import { getCurrentPages } from './page' @@ -41,7 +41,7 @@ export function parseTheme (pageStyle) { theme = systemInfo.hostTheme } - parsedStyle = normallizeStyles(pageStyle, __uniConfig.themeConfig, theme) + parsedStyle = normalizeStyles(pageStyle, __uniConfig.themeConfig, theme) return parsedStyle } return pageStyle @@ -52,23 +52,24 @@ export function useTabBarThemeChange (tabBar, options) { const fn = () => { const { list = [], color, selectedColor, - backgroundColor, borderStyle - } = parseTheme(options, false) - const tabbarStyle = { - color, - selectedColor, - backgroundColor, - borderStyle + backgroundColor, borderStyle, midButton + } = parseTheme(options) + if (tabBar) { + tabBar.setTabBarStyle({ + color, + selectedColor, + backgroundColor, + borderStyle, + midButton + }) + tabBar.setTabBarItems({ + list: list.map((item) => ({ + iconPath: item.iconPath, + selectedIconPath: item.selectedIconPath, + visible: item.visible + })) + }) } - - tabBar && tabBar.setTabBarStyle(tabbarStyle) - tabBar && tabBar.setTabBarItems({ - list: list.map((item) => ({ - iconPath: item.iconPath, - selectedIconPath: item.selectedIconPath, - visible: item.visible - })) - }) // TODO 暂未实现 // tabBar && tabBar.setAnimationAlphaBGColor(parseTheme((__uniConfig.window || {}).backgroundColor, false)) } diff --git a/src/platforms/h5/components/theme.js b/src/platforms/h5/components/theme.js index 877cb3aff52..8f7d0e541ee 100644 --- a/src/platforms/h5/components/theme.js +++ b/src/platforms/h5/components/theme.js @@ -1,4 +1,4 @@ -import { normallizeStyles } from 'uni-shared' +import { normalizeStyles } from 'uni-shared' import { getTheme } from '../service/api/base/get-browser-info' import { ON_THEME_CHANGE @@ -20,7 +20,7 @@ export function parseTheme (pageStyle) { let parsedStyle = {} if (__uniConfig.darkmode) { const theme = getTheme() - parsedStyle = normallizeStyles(pageStyle, __uniConfig.themeConfig, theme) + parsedStyle = normalizeStyles(pageStyle, __uniConfig.themeConfig, theme) } return __uniConfig.darkmode ? parsedStyle : pageStyle } diff --git a/src/shared/theme.js b/src/shared/theme.js index 059ab4da6b2..b048a4b8f50 100644 --- a/src/shared/theme.js +++ b/src/shared/theme.js @@ -12,7 +12,7 @@ export function normalizeTabBarStyles (borderStyle) { return borderStyle } -export function normallizeStyles (pageStyle, themeConfig = {}, mode = 'light') { +export function normalizeStyles (pageStyle, themeConfig = {}, mode = 'light') { const modeStyle = themeConfig[mode] const styles = {} if (!modeStyle) { @@ -22,10 +22,10 @@ export function normallizeStyles (pageStyle, themeConfig = {}, mode = 'light') { const styleItem = pageStyle[key] // Object Array String styles[key] = (() => { if (isPlainObject(styleItem)) { - return normallizeStyles(styleItem, themeConfig, mode) + return normalizeStyles(styleItem, themeConfig, mode) } else if (Array.isArray(styleItem)) { return styleItem.map((item) => isPlainObject(item) - ? normallizeStyles(item, themeConfig, mode) + ? normalizeStyles(item, themeConfig, mode) : item) } else if (isStr(styleItem) && styleItem.startsWith('@')) { const _key = styleItem.replace('@', '')