From 70b87d424d9c0b3def6025428e207f6d9e81d0df Mon Sep 17 00:00:00 2001 From: cnliucheng Date: Fri, 10 Jul 2026 09:54:41 +0800 Subject: [PATCH] =?UTF-8?q?perf(theme):=20onLaunch=20=E6=8F=90=E5=89=8D?= =?UTF-8?q?=E8=AE=BE=E5=AF=BC=E8=88=AA=E6=A0=8F=E8=89=B2,=E7=BC=A9?= =?UTF-8?q?=E5=B0=8F=E5=86=B7=E5=90=AF=E5=8A=A8=E6=A9=99->=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E8=89=B2=E8=B7=B3=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 applyChrome() 在 onLaunch 第一行调用,把导航栏变色点从首页 onShow 提前到 onLaunch,缩短冷启动橙色跳变窗口。app.json 静态橙色在 JS 执行前 生效是框架硬限制,无法完全消除。 Co-Authored-By: Claude --- app.js | 7 ++++--- utils/theme.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 3afbaeb..7f28c48 100644 --- a/app.js +++ b/app.js @@ -5,6 +5,10 @@ const darkMod = require('./utils/darkMode') App({ async onLaunch() { + // 尽早设导航栏色 + 窗口背景:原生导航栏在 JS 执行前用 app.json 写死的 + // 橙色,这里在 onLaunch 第一时间切到用户主题色,缩小冷启动跳变窗口。 + themeMod.applyChrome() + // Init dark mode listener (refreshes all open pages when system theme changes) darkMod.watchDarkMode((isDark) => { const pages = getCurrentPages() @@ -39,9 +43,6 @@ App({ this.globalData.theme = themeMod.getCurrentTheme() - // 窗口背景色 — 冷启动就设好,避免暗黑模式下切 tab 闪白 - themeMod.applyWindowBg() - // Sync with cloud: always locate our doc first (pullAll caches // _openid / _docId), then either restore or push. The previous flow // only pulled when local was empty, so on a cold start with non-empty diff --git a/utils/theme.js b/utils/theme.js index 9e991a6..b10d87c 100644 --- a/utils/theme.js +++ b/utils/theme.js @@ -130,11 +130,25 @@ const applyWindowBg = () => { } catch (e) {} } +/** + * 冷启动尽早调用:设导航栏色 + 窗口背景。 + * 原生导航栏在 JS 执行前用 app.json 写死的橙色,这里在 onLaunch 第一时间 + * 切到用户主题色,把冷启动橙->主题色的跳变窗口压到最小(无法完全消除, + * 因为 app.json 静态值在 onLaunch 之前就已应用)。 + */ +const applyChrome = () => { + try { + _setNavBarColor(getCurrentTheme().primary) + applyWindowBg() + } catch (e) {} +} + module.exports = { THEMES, DEFAULT_THEME_ID, BASE_VARS, applyWindowBg, + applyChrome, getThemeById, getCurrentTheme, setTheme,