From 3c1bbccd73a699fc0515236cf7c5071a3f02b8fd Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Tue, 25 Oct 2022 15:48:55 +0800 Subject: [PATCH] fix(app): onThemeChange triggered twice --- src/core/service/api/device/theme.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/service/api/device/theme.js b/src/core/service/api/device/theme.js index 95de5a7ac..49e5ffeb1 100644 --- a/src/core/service/api/device/theme.js +++ b/src/core/service/api/device/theme.js @@ -7,6 +7,7 @@ import { } from '../../platform' const callbacks = [] +const oldCallbacks = [] onMethod('onThemeChange', function (res) { callbacks.forEach(callbackId => { @@ -20,12 +21,12 @@ export function onThemeChange (callbackId) { // 旧版本 API,后期文档更新后考虑移除 onMethod('onUIStyleChange', function (res) { - callbacks.forEach(callbackId => { + oldCallbacks.forEach(callbackId => { invoke(callbackId, res) }) }) export function onUIStyleChange (callbackId) { - callbacks.push(callbackId) + oldCallbacks.push(callbackId) console.warn('The "uni.onUIStyleChange" API is deprecated, please use "uni.onThemeChange". Learn more: https://uniapp.dcloud.net.cn/api/system/theme.') } -- GitLab