Skip to content

Commit 25287ed

Browse files
authored
Merge pull request #2200 from didi/fix-rn-onAppHide
fix(rn): expose exit reason number 0 of `onAppHide`
2 parents 06b893d + fe39348 commit 25287ed

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

packages/core/src/platform/createApp.ios.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default function createApp (options) {
108108
}
109109
}
110110
const appState = reactive({ state: '' })
111-
// TODO hideReason 暂未完全模拟
111+
// TODO reason 目前支持模拟 0/3
112112
// 0用户退出小程序
113113
// 1进入其他小程序
114114
// 2打开原生功能页
@@ -136,12 +136,10 @@ export default function createApp (options) {
136136
global.__mpxAppCbs.show.forEach((cb) => {
137137
cb(options)
138138
})
139-
} else if (value === 'hide') {
140-
const reason = appState.hideReason ?? 3
141-
delete appState.hideReason
142-
global.__mpxAppCbs.hide.forEach((cb) => {
139+
} else if (value === 'hide' || value === 'exit') {
140+
global.__mpxAppCbs.hide.forEach((cb) => {
143141
cb({
144-
reason
142+
reason: value === 'exit' ? 0 : 3
145143
})
146144
})
147145
}
@@ -154,7 +152,6 @@ export default function createApp (options) {
154152
global.__mpxPageStatusMap[navigation.pageId] = 'show'
155153
}
156154
} else if (currentState === 'inactive' || currentState === 'background') {
157-
appState.hideReason = 3
158155
appState.state = 'hide'
159156
if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
160157
global.__mpxPageStatusMap[navigation.pageId] = 'hide'
@@ -224,8 +221,7 @@ export default function createApp (options) {
224221
}
225222
})
226223
return () => {
227-
appState.hideReason = 0
228-
appState.state = 'hide'
224+
appState.state = 'exit'
229225
changeSubscription && changeSubscription.remove()
230226
resizeSubScription && resizeSubScription.remove()
231227
}

0 commit comments

Comments
 (0)