From 36a0756090043c134480c5c26994f73c0e096195 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Mon, 13 Mar 2023 16:35:13 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=89=8B=E5=8A=A8=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=86=85=E5=AD=98=E7=9B=91=E6=8E=A7=20=E7=BB=84=E4=BB=B6=203.7?= =?UTF-8?q?.6=E4=B9=8B=E5=90=8E=E7=BC=96=E8=AF=91=E5=99=A8=E6=96=B0?= =?UTF-8?q?=E8=AF=AD=E6=B3=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 492e590992616e69bf8df2219c9616a787eed88b. --- .../utssdk/app-android/index.uts | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/uni_modules/uni-memorywarning/utssdk/app-android/index.uts b/uni_modules/uni-memorywarning/utssdk/app-android/index.uts index 5839e4d..b364d04 100644 --- a/uni_modules/uni-memorywarning/utssdk/app-android/index.uts +++ b/uni_modules/uni-memorywarning/utssdk/app-android/index.uts @@ -1,50 +1,44 @@ import { UTSAndroid } from "io.dcloud.uts" -let listeners : UTSCallback[] = [] +let listeners: UTSCallback[] = [] -const onAppTrimMemoryListener = (res : number) => { - listeners.forEach(listener => { - listener(res) - }) +const onAppTrimMemoryListener = (res: number) => { + listeners.forEach(listener => { + listener(res) + }) } @Suppress("DEPRECATION") -export function onMemoryWarning(callback : (res : number) => void) { - if (listeners.length == 0) { +export function onMemoryWarning(callback: (res: number) => void) { + if (listeners.length == 0) { // 仅首次执行底层的实际监听 - UTSAndroid.onAppTrimMemory((res : number) => { - onAppTrimMemoryListener(res) - }) - UTSAndroid.onAppActivityDestroy(() => { + UTSAndroid.onAppTrimMemory(onAppTrimMemoryListener) + UTSAndroid.onAppActivityDestroy(()=>{ // listeners 默认是静态常量周期,activity 销毁时,需要手动清空 listeners = [] }) - } - listeners.push(callback) + } + listeners.push(callback) } - @Suppress("DEPRECATION") -export function offMemoryWarning(callback : UTSCallback | null = null) { - - if (callback == null) { +export function offMemoryWarning(callback: UTSCallback | null = null) { + + if(callback == null){ // 清除全部回调 listeners = [] UTSAndroid.offAppTrimMemory(null); return } - + // 清除指定回调 - const index = listeners.indexOf(callback) - if (index > -1) { - listeners.splice(index, 1) - } - if (listeners.length == 0) { - // 当用户不再监听时,移除底层实际监听 - UTSAndroid.offAppTrimMemory((res : number) => { - onAppTrimMemoryListener(res) - }) - } + const index = listeners.indexOf(callback) + if (index > -1) { + listeners.splice(index, 1) + } + if (listeners.length == 0) { + // 当用户不再监听时,移除底层实际监听 + UTSAndroid.offAppTrimMemory(onAppTrimMemoryListener) + } } - -- GitLab