fix(tabBar): 切换暗黑模式后其他 tab 的底栏不跟随变暗
根因:自定义 tabBar 的 pageLifetimes.show() 不触发(微信框架
特殊行为),各 tab 页 onShow 只设了 selected 没同步主题;
onSelectDarkMode 里 getCurrentPages() 只返回当前 tab 页,
其他 tab 的 tabBar 实例未收到更新。
修复:4 个 tab 页 onShow 里 tb.setData({selected:X}) 后加
tb.updateTheme(),显式同步主题。updateTheme 内部有样式未变
则跳过的优化,不会多余渲染。
This commit is contained in:
@@ -52,7 +52,10 @@ Page({
|
||||
themeMod.applyThemeToPage(this)
|
||||
try {
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ selected: 0 })
|
||||
if (tb) {
|
||||
tb.setData({ selected: 0 })
|
||||
tb.updateTheme()
|
||||
}
|
||||
} catch (e) {}
|
||||
// Skip the first onShow to avoid double-refresh; subsequent tab switches still refresh.
|
||||
if (this._firstShow) {
|
||||
|
||||
@@ -36,7 +36,10 @@ Page({
|
||||
this.setData({ theme, icons: iconsMod.build(theme) })
|
||||
try {
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ selected: 2 })
|
||||
if (tb) {
|
||||
tb.setData({ selected: 2 })
|
||||
tb.updateTheme()
|
||||
}
|
||||
} catch (e) {}
|
||||
// 训练完设的强刷标志:下次进排行榜跳过云函数缓存,立刻拿到含新记录的数据
|
||||
let force = false
|
||||
|
||||
@@ -50,7 +50,10 @@ Page({
|
||||
themeMod.applyThemeToPage(this)
|
||||
try {
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ selected: 1 })
|
||||
if (tb) {
|
||||
tb.setData({ selected: 1 })
|
||||
tb.updateTheme()
|
||||
}
|
||||
} catch (e) {}
|
||||
if (this._firstShow) {
|
||||
this._firstShow = false
|
||||
|
||||
@@ -114,7 +114,10 @@ Page({
|
||||
onShow() {
|
||||
try {
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ selected: 3 })
|
||||
if (tb) {
|
||||
tb.setData({ selected: 3 })
|
||||
tb.updateTheme()
|
||||
}
|
||||
} catch (e) {}
|
||||
themeMod.applyThemeToPage(this)
|
||||
const theme = themeMod.getCurrentTheme()
|
||||
|
||||
Reference in New Issue
Block a user