@mpxjs/core 2.10.4-beta.10 → 2.10.4-beta.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.10.4-beta.10",
3
+ "version": "2.10.4-beta.11",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@d11/react-native-fast-image": "*",
28
- "@mpxjs/api-proxy": "^2.9.0",
28
+ "@mpxjs/api-proxy": "^2.10.4-beta.0",
29
29
  "@mpxjs/store": "^2.9.0",
30
30
  "@react-navigation/native": "*",
31
31
  "@react-navigation/native-stack": "*",
@@ -4,7 +4,7 @@ import { makeMap, spreadProp, getFocusedNavigation, hasOwn } from '@mpxjs/utils'
4
4
  import { mergeLifecycle } from '../convertor/mergeLifecycle'
5
5
  import { LIFECYCLE } from '../platform/patch/lifecycle/index'
6
6
  import Mpx from '../index'
7
- import { ref } from '../observer/ref'
7
+ import { reactive } from '../observer/reactive'
8
8
  import { watch } from '../observer/watch'
9
9
  import { createElement, memo, useRef, useEffect } from 'react'
10
10
  import * as ReactNative from 'react-native'
@@ -92,77 +92,52 @@ export default function createApp (options) {
92
92
  global.__navigationHelper.lastFailCallback = null
93
93
  }
94
94
  }
95
- const appState = ref('')
96
- watch(() => appState.value, (value) => {
95
+ const appState = reactive({ state: '' })
96
+ // TODO hideReason 暂未完全模拟
97
+ // 0用户退出小程序
98
+ // 1进入其他小程序
99
+ // 2打开原生功能页
100
+ // 3其他
101
+ watch(() => appState.state, (value) => {
97
102
  if (value === 'show') {
98
- let options = global.__mpxEnterOptions || {}
99
- const navigation = getFocusedNavigation()
100
- if (navigation) {
101
- const state = navigation.getState()
102
- const current = state.routes[state.index]
103
- options = {
104
- path: current.name,
105
- query: current.params,
106
- scene: 0,
107
- shareTicket: '',
108
- referrerInfo: {}
103
+ let options = appState.showOptions
104
+ delete appState.showOptions
105
+ if (!options) {
106
+ const navigation = getFocusedNavigation()
107
+ if (navigation) {
108
+ const state = navigation.getState()
109
+ const current = state.routes[state.index]
110
+ options = {
111
+ path: current.name,
112
+ query: current.params,
113
+ scene: 0,
114
+ shareTicket: '',
115
+ referrerInfo: {}
116
+ }
109
117
  }
110
118
  }
111
119
  global.__mpxAppCbs.show.forEach((cb) => {
112
- cb(options)
120
+ cb(options || {})
113
121
  })
114
122
  } else if (value === 'hide') {
115
123
  global.__mpxAppCbs.hide.forEach((cb) => {
116
124
  cb({
117
- reason: 3
125
+ reason: appState.hideReason ?? 3
118
126
  })
127
+ delete appState.hideReason
119
128
  })
120
129
  }
121
- })
130
+ }, { sync: true })
122
131
  const onAppStateChange = (currentState) => {
123
132
  const navigation = getFocusedNavigation()
124
133
  if (currentState === 'active') {
125
- appState.value = 'show'
134
+ appState.state = 'show'
126
135
  if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
127
136
  global.__mpxPageStatusMap[navigation.pageId] = 'show'
128
137
  }
129
138
  } else if (currentState === 'inactive' || currentState === 'background') {
130
- appState.value = 'hide'
131
- if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
132
- global.__mpxPageStatusMap[navigation.pageId] = 'hide'
133
- }
134
- }
135
- }
136
-
137
- const onAppStateChange = (currentState) => {
138
- // 业务上配置禁止的话就不响应监听事件
139
- if (currentState === 'active') {
140
- let options = global.__mpxEnterOptions || {}
141
- const navigation = getFocusedNavigation()
142
- if (navigation) {
143
- const state = navigation.getState()
144
- const current = state.routes[state.index]
145
- options = {
146
- path: current.name,
147
- query: current.params,
148
- scene: 0,
149
- shareTicket: '',
150
- referrerInfo: {}
151
- }
152
- }
153
- global.__mpxAppCbs.show.forEach((cb) => {
154
- cb(options)
155
- })
156
- if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
157
- global.__mpxPageStatusMap[navigation.pageId] = 'show'
158
- }
159
- } else if (currentState === 'inactive' || currentState === 'background') {
160
- global.__mpxAppCbs.hide.forEach((cb) => {
161
- cb({
162
- reason: 3
163
- })
164
- })
165
- const navigation = getFocusedNavigation()
139
+ appState.hideReason = 3
140
+ appState.state = 'hide'
166
141
  if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
167
142
  global.__mpxPageStatusMap[navigation.pageId] = 'hide'
168
143
  }
@@ -205,7 +180,8 @@ export default function createApp (options) {
205
180
  global.__mpxLaunchOptions = options
206
181
  defaultOptions.onLaunch && defaultOptions.onLaunch.call(appInstance, options)
207
182
  }
208
- appState.value = 'show'
183
+ appState.showOptions = options
184
+ appState.state = 'show'
209
185
  global.__mpxAppLaunched = true
210
186
  global.__mpxAppHotLaunched = true
211
187
  }
@@ -230,12 +206,8 @@ export default function createApp (options) {
230
206
  }
231
207
  })
232
208
  return () => {
233
- // todo 跳到原生页面或者其他rn bundle可以考虑使用reason 1/2进行模拟抹平
234
- global.__mpxAppCbs.hide.forEach((cb) => {
235
- cb({
236
- reason: 0
237
- })
238
- })
209
+ appState.hideReason = 0
210
+ appState.state = 'hide'
239
211
  changeSubscription && changeSubscription.remove()
240
212
  resizeSubScription && resizeSubScription.remove()
241
213
  }
@@ -393,7 +393,7 @@ function usePageEffect (mpxProxy, pageId) {
393
393
  } else if (/^resize/.test(newVal)) {
394
394
  triggerResizeEvent(mpxProxy)
395
395
  }
396
- })
396
+ }, { sync: true })
397
397
  }
398
398
  }
399
399
  return () => {