@mpxjs/core 2.10.4-beta.6 → 2.10.4-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/platform/createApp.ios.js +47 -32
package/package.json
CHANGED
|
@@ -91,6 +91,41 @@ export default function createApp (options) {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
const onAppStateChange = (currentState) => {
|
|
95
|
+
// 业务上配置禁止的话就不响应监听事件
|
|
96
|
+
if (currentState === 'active') {
|
|
97
|
+
let options = global.__mpxEnterOptions || {}
|
|
98
|
+
const navigation = getFocusedNavigation()
|
|
99
|
+
if (navigation) {
|
|
100
|
+
const state = navigation.getState()
|
|
101
|
+
const current = state.routes[state.index]
|
|
102
|
+
options = {
|
|
103
|
+
path: current.name,
|
|
104
|
+
query: current.params,
|
|
105
|
+
scene: 0,
|
|
106
|
+
shareTicket: '',
|
|
107
|
+
referrerInfo: {}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
global.__mpxAppCbs.show.forEach((cb) => {
|
|
111
|
+
cb(options)
|
|
112
|
+
})
|
|
113
|
+
if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
|
|
114
|
+
global.__mpxPageStatusMap[navigation.pageId] = 'show'
|
|
115
|
+
}
|
|
116
|
+
} else if (currentState === 'inactive' || currentState === 'background') {
|
|
117
|
+
global.__mpxAppCbs.hide.forEach((cb) => {
|
|
118
|
+
cb({
|
|
119
|
+
reason: 3
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
const navigation = getFocusedNavigation()
|
|
123
|
+
if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
|
|
124
|
+
global.__mpxPageStatusMap[navigation.pageId] = 'hide'
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
94
129
|
global.__mpxAppLaunched = false
|
|
95
130
|
global.__mpxOptionsMap[currentInject.moduleId] = memo((props) => {
|
|
96
131
|
const firstRef = useRef(true)
|
|
@@ -136,38 +171,10 @@ export default function createApp (options) {
|
|
|
136
171
|
}
|
|
137
172
|
|
|
138
173
|
useEffect(() => {
|
|
139
|
-
const changeSubscription = ReactNative.AppState.addEventListener('change', (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (navigation) {
|
|
144
|
-
const state = navigation.getState()
|
|
145
|
-
const current = state.routes[state.index]
|
|
146
|
-
options = {
|
|
147
|
-
path: current.name,
|
|
148
|
-
query: current.params,
|
|
149
|
-
scene: 0,
|
|
150
|
-
shareTicket: '',
|
|
151
|
-
referrerInfo: {}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
global.__mpxAppCbs.show.forEach((cb) => {
|
|
155
|
-
cb(options)
|
|
156
|
-
})
|
|
157
|
-
if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
|
|
158
|
-
global.__mpxPageStatusMap[navigation.pageId] = 'show'
|
|
159
|
-
}
|
|
160
|
-
} else if (currentState === 'inactive' || currentState === 'background') {
|
|
161
|
-
global.__mpxAppCbs.hide.forEach((cb) => {
|
|
162
|
-
cb({
|
|
163
|
-
reason: 3
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
const navigation = getFocusedNavigation()
|
|
167
|
-
if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
|
|
168
|
-
global.__mpxPageStatusMap[navigation.pageId] = 'hide'
|
|
169
|
-
}
|
|
170
|
-
}
|
|
174
|
+
const changeSubscription = ReactNative.AppState.addEventListener('change', (state) => {
|
|
175
|
+
// 外层可能会异常设置此配置,因此加载监听函数内部
|
|
176
|
+
if (Mpx.config.rnConfig.disableReactNativeAppStateChange) return
|
|
177
|
+
onAppStateChange(state)
|
|
171
178
|
})
|
|
172
179
|
|
|
173
180
|
let count = 0
|
|
@@ -234,4 +241,12 @@ export default function createApp (options) {
|
|
|
234
241
|
global.__mpxPageStatusMap[navigation.pageId] = status
|
|
235
242
|
}
|
|
236
243
|
}
|
|
244
|
+
|
|
245
|
+
// 用于外层业务用来设置App的展示情况
|
|
246
|
+
global.setAppShow = function () {
|
|
247
|
+
onAppStateChange('active')
|
|
248
|
+
}
|
|
249
|
+
global.setAppHide = function () {
|
|
250
|
+
onAppStateChange('background')
|
|
251
|
+
}
|
|
237
252
|
}
|