提交 36a07560 编写于 作者: 杜庆泉's avatar 杜庆泉

Revert "手动修复内存监控 组件 3.7.6之后编译器新语法"

This reverts commit 492e5909.
上级 492e5909
import { UTSAndroid } from "io.dcloud.uts" import { UTSAndroid } from "io.dcloud.uts"
let listeners : UTSCallback[] = [] let listeners: UTSCallback[] = []
const onAppTrimMemoryListener = (res : number) => { const onAppTrimMemoryListener = (res: number) => {
listeners.forEach(listener => { listeners.forEach(listener => {
listener(res) listener(res)
}) })
...@@ -10,13 +10,11 @@ const onAppTrimMemoryListener = (res : number) => { ...@@ -10,13 +10,11 @@ const onAppTrimMemoryListener = (res : number) => {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
export function onMemoryWarning(callback : (res : number) => void) { export function onMemoryWarning(callback: (res: number) => void) {
if (listeners.length == 0) { if (listeners.length == 0) {
// 仅首次执行底层的实际监听 // 仅首次执行底层的实际监听
UTSAndroid.onAppTrimMemory((res : number) => { UTSAndroid.onAppTrimMemory(onAppTrimMemoryListener)
onAppTrimMemoryListener(res) UTSAndroid.onAppActivityDestroy(()=>{
})
UTSAndroid.onAppActivityDestroy(() => {
// listeners 默认是静态常量周期,activity 销毁时,需要手动清空 // listeners 默认是静态常量周期,activity 销毁时,需要手动清空
listeners = [] listeners = []
}) })
...@@ -24,11 +22,10 @@ export function onMemoryWarning(callback : (res : number) => void) { ...@@ -24,11 +22,10 @@ export function onMemoryWarning(callback : (res : number) => void) {
listeners.push(callback) listeners.push(callback)
} }
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
export function offMemoryWarning(callback : UTSCallback | null = null) { export function offMemoryWarning(callback: UTSCallback | null = null) {
if (callback == null) { if(callback == null){
// 清除全部回调 // 清除全部回调
listeners = [] listeners = []
UTSAndroid.offAppTrimMemory(null); UTSAndroid.offAppTrimMemory(null);
...@@ -42,9 +39,6 @@ export function offMemoryWarning(callback : UTSCallback | null = null) { ...@@ -42,9 +39,6 @@ export function offMemoryWarning(callback : UTSCallback | null = null) {
} }
if (listeners.length == 0) { if (listeners.length == 0) {
// 当用户不再监听时,移除底层实际监听 // 当用户不再监听时,移除底层实际监听
UTSAndroid.offAppTrimMemory((res : number) => { UTSAndroid.offAppTrimMemory(onAppTrimMemoryListener)
onAppTrimMemoryListener(res)
})
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册