Skip to content

Commit

Permalink
fix(app): onThemeChange triggered twice
Browse files Browse the repository at this point in the history
  • Loading branch information
StrivingRabbit committed Oct 25, 2022
1 parent 8c30bd3 commit 3c1bbcc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/service/api/device/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../platform'

const callbacks = []
const oldCallbacks = []

onMethod('onThemeChange', function (res) {
callbacks.forEach(callbackId => {
Expand All @@ -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.')
}

0 comments on commit 3c1bbcc

Please sign in to comment.