UNPKG

1.59 kBTypeScriptView Raw
1import Taro from '../../index'
2
3declare module '../../index' {
4 namespace onMemoryWarning {
5 /** 内存不足告警事件的回调函数 */
6 type Callback = (
7 result: CallbackResult,
8 ) => void
9
10 interface CallbackResult {
11 /** 内存告警等级,只有 Android 才有,对应系统宏定义 */
12 level: keyof Level
13 }
14
15 interface Level {
16 /** TRIM_MEMORY_RUNNING_MODERATE */
17 5
18 /** TRIM_MEMORY_RUNNING_LOW */
19 10
20 /** TRIM_MEMORY_RUNNING_CRITICAL */
21 15
22 }
23 }
24
25 interface TaroStatic {
26 /** 监听内存不足告警事件。
27 *
28 * 当 iOS/Android 向小程序进程发出内存警告时,触发该事件。触发该事件不意味小程序被杀,大部分情况下仅仅是告警,开发者可在收到通知后回收一些不必要资源避免进一步加剧内存紧张。
29 * @supported weapp
30 * @example
31 * ```tsx
32 * Taro.onMemoryWarning(function () {
33 * console.log('onMemoryWarningReceive')
34 * })
35 * ```
36 * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/performance/wx.onMemoryWarning.html
37 */
38 onMemoryWarning(
39 /** 内存不足告警事件的回调函数 */
40 callback: onMemoryWarning.Callback,
41 ): void
42
43 /** 取消监听内存不足告警事件。
44 * @supported weapp
45 * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/memory/wx.offMemoryWarning.html
46 */
47 offMemoryWarning(
48 /** 取消监听内存不足告警事件 */
49 callback: onMemoryWarning.Callback,
50 ): void
51
52 }
53}