Skip to content

Commit

Permalink
feat(app): darkmode 支持 midButton
Browse files Browse the repository at this point in the history
  • Loading branch information
StrivingRabbit committed May 15, 2024
1 parent 4af2e6b commit d4c4541
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
37 changes: 19 additions & 18 deletions src/platforms/app-plus/service/framework/theme.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/h5/components/theme.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions src/shared/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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('@', '')
Expand Down

0 comments on commit d4c4541

Please sign in to comment.