@mpxjs/core 2.10.1-beta.7 → 2.10.2

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/@types/index.d.ts CHANGED
@@ -119,7 +119,8 @@ interface Context {
119
119
  selectComponent: ReplaceWxComponentIns['selectComponent']
120
120
  selectAllComponents: ReplaceWxComponentIns['selectAllComponents']
121
121
  createSelectorQuery: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createSelectorQuery']
122
- createIntersectionObserver: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createIntersectionObserver']
122
+ createIntersectionObserver: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createIntersectionObserver'],
123
+ getPageId: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['getPageId']
123
124
  }
124
125
 
125
126
  interface ComponentOpt<D extends Data, P extends Properties, C, M extends Methods, Mi extends Array<any>, S extends Record<any, any>> extends Partial<WechatMiniprogram.Component.Lifetimes & WechatMiniprogram.Component.OtherOption> {
package/LICENSE ADDED
@@ -0,0 +1,433 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+
8
+
9
+
10
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
+
12
+
13
+
14
+
15
+ 1. Definitions.
16
+
17
+
18
+
19
+
20
+ "License" shall mean the terms and conditions for use, reproduction,
21
+
22
+ and distribution as defined by Sections 1 through 9 of this document.
23
+
24
+
25
+
26
+
27
+ "Licensor" shall mean the copyright owner or entity authorized by
28
+
29
+ the copyright owner that is granting the License.
30
+
31
+
32
+
33
+
34
+ "Legal Entity" shall mean the union of the acting entity and all
35
+
36
+ other entities that control, are controlled by, or are under common
37
+
38
+ control with that entity. For the purposes of this definition,
39
+
40
+ "control" means (i) the power, direct or indirect, to cause the
41
+
42
+ direction or management of such entity, whether by contract or
43
+
44
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
45
+
46
+ outstanding shares, or (iii) beneficial ownership of such entity.
47
+
48
+
49
+
50
+
51
+ "You" (or "Your") shall mean an individual or Legal Entity
52
+
53
+ exercising permissions granted by this License.
54
+
55
+
56
+
57
+
58
+ "Source" form shall mean the preferred form for making modifications,
59
+
60
+ including but not limited to software source code, documentation
61
+
62
+ source, and configuration files.
63
+
64
+
65
+
66
+
67
+ "Object" form shall mean any form resulting from mechanical
68
+
69
+ transformation or translation of a Source form, including but
70
+
71
+ not limited to compiled object code, generated documentation,
72
+
73
+ and conversions to other media types.
74
+
75
+
76
+
77
+
78
+ "Work" shall mean the work of authorship, whether in Source or
79
+
80
+ Object form, made available under the License, as indicated by a
81
+
82
+ copyright notice that is included in or attached to the work
83
+
84
+ (an example is provided in the Appendix below).
85
+
86
+
87
+
88
+
89
+ "Derivative Works" shall mean any work, whether in Source or Object
90
+
91
+ form, that is based on (or derived from) the Work and for which the
92
+
93
+ editorial revisions, annotations, elaborations, or other modifications
94
+
95
+ represent, as a whole, an original work of authorship. For the purposes
96
+
97
+ of this License, Derivative Works shall not include works that remain
98
+
99
+ separable from, or merely link (or bind by name) to the interfaces of,
100
+
101
+ the Work and Derivative Works thereof.
102
+
103
+
104
+
105
+
106
+ "Contribution" shall mean any work of authorship, including
107
+
108
+ the original version of the Work and any modifications or additions
109
+
110
+ to that Work or Derivative Works thereof, that is intentionally
111
+
112
+ submitted to Licensor for inclusion in the Work by the copyright owner
113
+
114
+ or by an individual or Legal Entity authorized to submit on behalf of
115
+
116
+ the copyright owner. For the purposes of this definition, "submitted"
117
+
118
+ means any form of electronic, verbal, or written communication sent
119
+
120
+ to the Licensor or its representatives, including but not limited to
121
+
122
+ communication on electronic mailing lists, source code control systems,
123
+
124
+ and issue tracking systems that are managed by, or on behalf of, the
125
+
126
+ Licensor for the purpose of discussing and improving the Work, but
127
+
128
+ excluding communication that is conspicuously marked or otherwise
129
+
130
+ designated in writing by the copyright owner as "Not a Contribution."
131
+
132
+
133
+
134
+
135
+ "Contributor" shall mean Licensor and any individual or Legal Entity
136
+
137
+ on behalf of whom a Contribution has been received by Licensor and
138
+
139
+ subsequently incorporated within the Work.
140
+
141
+
142
+
143
+
144
+ 2. Grant of Copyright License. Subject to the terms and conditions of
145
+
146
+ this License, each Contributor hereby grants to You a perpetual,
147
+
148
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
149
+
150
+ copyright license to reproduce, prepare Derivative Works of,
151
+
152
+ publicly display, publicly perform, sublicense, and distribute the
153
+
154
+ Work and such Derivative Works in Source or Object form.
155
+
156
+
157
+
158
+
159
+ 3. Grant of Patent License. Subject to the terms and conditions of
160
+
161
+ this License, each Contributor hereby grants to You a perpetual,
162
+
163
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
164
+
165
+ (except as stated in this section) patent license to make, have made,
166
+
167
+ use, offer to sell, sell, import, and otherwise transfer the Work,
168
+
169
+ where such license applies only to those patent claims licensable
170
+
171
+ by such Contributor that are necessarily infringed by their
172
+
173
+ Contribution(s) alone or by combination of their Contribution(s)
174
+
175
+ with the Work to which such Contribution(s) was submitted. If You
176
+
177
+ institute patent litigation against any entity (including a
178
+
179
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
180
+
181
+ or a Contribution incorporated within the Work constitutes direct
182
+
183
+ or contributory patent infringement, then any patent licenses
184
+
185
+ granted to You under this License for that Work shall terminate
186
+
187
+ as of the date such litigation is filed.
188
+
189
+
190
+
191
+
192
+ 4. Redistribution. You may reproduce and distribute copies of the
193
+
194
+ Work or Derivative Works thereof in any medium, with or without
195
+
196
+ modifications, and in Source or Object form, provided that You
197
+
198
+ meet the following conditions:
199
+
200
+
201
+
202
+
203
+ (a) You must give any other recipients of the Work or
204
+
205
+ Derivative Works a copy of this License; and
206
+
207
+
208
+
209
+
210
+ (b) You must cause any modified files to carry prominent notices
211
+
212
+ stating that You changed the files; and
213
+
214
+
215
+
216
+
217
+ (c) You must retain, in the Source form of any Derivative Works
218
+
219
+ that You distribute, all copyright, patent, trademark, and
220
+
221
+ attribution notices from the Source form of the Work,
222
+
223
+ excluding those notices that do not pertain to any part of
224
+
225
+ the Derivative Works; and
226
+
227
+
228
+
229
+
230
+ (d) If the Work includes a "NOTICE" text file as part of its
231
+
232
+ distribution, then any Derivative Works that You distribute must
233
+
234
+ include a readable copy of the attribution notices contained
235
+
236
+ within such NOTICE file, excluding those notices that do not
237
+
238
+ pertain to any part of the Derivative Works, in at least one
239
+
240
+ of the following places: within a NOTICE text file distributed
241
+
242
+ as part of the Derivative Works; within the Source form or
243
+
244
+ documentation, if provided along with the Derivative Works; or,
245
+
246
+ within a display generated by the Derivative Works, if and
247
+
248
+ wherever such third-party notices normally appear. The contents
249
+
250
+ of the NOTICE file are for informational purposes only and
251
+
252
+ do not modify the License. You may add Your own attribution
253
+
254
+ notices within Derivative Works that You distribute, alongside
255
+
256
+ or as an addendum to the NOTICE text from the Work, provided
257
+
258
+ that such additional attribution notices cannot be construed
259
+
260
+ as modifying the License.
261
+
262
+
263
+
264
+
265
+ You may add Your own copyright statement to Your modifications and
266
+
267
+ may provide additional or different license terms and conditions
268
+
269
+ for use, reproduction, or distribution of Your modifications, or
270
+
271
+ for any such Derivative Works as a whole, provided Your use,
272
+
273
+ reproduction, and distribution of the Work otherwise complies with
274
+
275
+ the conditions stated in this License.
276
+
277
+
278
+
279
+
280
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
281
+
282
+ any Contribution intentionally submitted for inclusion in the Work
283
+
284
+ by You to the Licensor shall be under the terms and conditions of
285
+
286
+ this License, without any additional terms or conditions.
287
+
288
+ Notwithstanding the above, nothing herein shall supersede or modify
289
+
290
+ the terms of any separate license agreement you may have executed
291
+
292
+ with Licensor regarding such Contributions.
293
+
294
+
295
+
296
+
297
+ 6. Trademarks. This License does not grant permission to use the trade
298
+
299
+ names, trademarks, service marks, or product names of the Licensor,
300
+
301
+ except as required for reasonable and customary use in describing the
302
+
303
+ origin of the Work and reproducing the content of the NOTICE file.
304
+
305
+
306
+
307
+
308
+ 7. Disclaimer of Warranty. Unless required by applicable law or
309
+
310
+ agreed to in writing, Licensor provides the Work (and each
311
+
312
+ Contributor provides its Contributions) on an "AS IS" BASIS,
313
+
314
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
315
+
316
+ implied, including, without limitation, any warranties or conditions
317
+
318
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
319
+
320
+ PARTICULAR PURPOSE. You are solely responsible for determining the
321
+
322
+ appropriateness of using or redistributing the Work and assume any
323
+
324
+ risks associated with Your exercise of permissions under this License.
325
+
326
+
327
+
328
+
329
+ 8. Limitation of Liability. In no event and under no legal theory,
330
+
331
+ whether in tort (including negligence), contract, or otherwise,
332
+
333
+ unless required by applicable law (such as deliberate and grossly
334
+
335
+ negligent acts) or agreed to in writing, shall any Contributor be
336
+
337
+ liable to You for damages, including any direct, indirect, special,
338
+
339
+ incidental, or consequential damages of any character arising as a
340
+
341
+ result of this License or out of the use or inability to use the
342
+
343
+ Work (including but not limited to damages for loss of goodwill,
344
+
345
+ work stoppage, computer failure or malfunction, or any and all
346
+
347
+ other commercial damages or losses), even if such Contributor
348
+
349
+ has been advised of the possibility of such damages.
350
+
351
+
352
+
353
+
354
+ 9. Accepting Warranty or Additional Liability. While redistributing
355
+
356
+ the Work or Derivative Works thereof, You may choose to offer,
357
+
358
+ and charge a fee for, acceptance of support, warranty, indemnity,
359
+
360
+ or other liability obligations and/or rights consistent with this
361
+
362
+ License. However, in accepting such obligations, You may act only
363
+
364
+ on Your own behalf and on Your sole responsibility, not on behalf
365
+
366
+ of any other Contributor, and only if You agree to indemnify,
367
+
368
+ defend, and hold each Contributor harmless for any liability
369
+
370
+ incurred by, or claims asserted against, such Contributor by reason
371
+
372
+ of your accepting any such warranty or additional liability.
373
+
374
+
375
+
376
+
377
+ END OF TERMS AND CONDITIONS
378
+
379
+
380
+
381
+
382
+ APPENDIX: How to apply the Apache License to your work.
383
+
384
+
385
+
386
+
387
+ To apply the Apache License to your work, attach the following
388
+
389
+ boilerplate notice, with the fields enclosed by brackets "{}"
390
+
391
+ replaced with your own identifying information. (Don't include
392
+
393
+ the brackets!) The text should be enclosed in the appropriate
394
+
395
+ comment syntax for the file format. We also recommend that a
396
+
397
+ file or class name and description of purpose be included on the
398
+
399
+ same "printed page" as the copyright notice for easier
400
+
401
+ identification within third-party archives.
402
+
403
+
404
+
405
+
406
+ Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. All rights reserved.
407
+
408
+
409
+
410
+
411
+ Licensed under the Apache License, Version 2.0 (the "License");
412
+
413
+ you may not use this file except in compliance with the License.
414
+
415
+ You may obtain a copy of the License at
416
+
417
+
418
+
419
+
420
+ http://www.apache.org/licenses/LICENSE-2.0
421
+
422
+
423
+
424
+
425
+ Unless required by applicable law or agreed to in writing, software
426
+
427
+ distributed under the License is distributed on an "AS IS" BASIS,
428
+
429
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
430
+
431
+ See the License for the specific language governing permissions and
432
+
433
+ limitations under the License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.10.1-beta.7",
3
+ "version": "2.10.2",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "main": "src/index.js",
21
21
  "dependencies": {
22
- "@mpxjs/utils": "^2.10.0",
22
+ "@mpxjs/utils": "^2.10.2",
23
23
  "lodash": "^4.1.1",
24
24
  "miniprogram-api-typings": "^3.10.0"
25
25
  },
@@ -109,5 +109,5 @@
109
109
  "url": "https://github.com/didi/mpx/issues"
110
110
  },
111
111
  "sideEffects": false,
112
- "gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
112
+ "gitHead": "4445de7c3ce29fb0166d3bb77a1a0460e41a32d3"
113
113
  }
@@ -37,8 +37,7 @@ const rulesMap = {
37
37
  wxToDd: extend({}, defaultConvertRule, wxToDdRule),
38
38
  wxToJd: extend({}, defaultConvertRule, wxToJdRule),
39
39
  wxToIos: extend({}, defaultConvertRule, wxToReactRule),
40
- wxToAndroid: extend({}, defaultConvertRule, wxToReactRule),
41
- wxToHarmony: extend({}, defaultConvertRule, wxToReactRule)
40
+ wxToAndroid: extend({}, defaultConvertRule, wxToReactRule)
42
41
  }
43
42
 
44
43
  export function getConvertRule (convertMode) {
@@ -7,8 +7,7 @@ const convertModes = {
7
7
  'wx-jd': 'wxToJd',
8
8
  'wx-dd': 'wxToDd',
9
9
  'wx-ios': 'wxToIos',
10
- 'wx-android': 'wxToAndroid',
11
- 'wx-harmony': 'wxToHarmony'
10
+ 'wx-android': 'wxToAndroid'
12
11
  }
13
12
 
14
13
  export function getConvertMode (srcMode) {
@@ -2,6 +2,8 @@ import { getConvertRule } from '../convertor/convertor'
2
2
  import builtInKeysMap from '../platform/patch/builtInKeysMap'
3
3
  import { implemented } from './implement'
4
4
  import {
5
+ isArray,
6
+ isFunction,
5
7
  isObject,
6
8
  aliasReplace,
7
9
  makeMap,
@@ -221,6 +223,10 @@ function mergeMixins (parent, child) {
221
223
  mergeToArray(parent, child, key)
222
224
  } else if (/^behaviors|externalClasses$/.test(key)) {
223
225
  mergeArray(parent, child, key)
226
+ } else if (key === 'inject') {
227
+ mergeInject(parent, child, key)
228
+ } else if (key === 'provide') {
229
+ mergeProvide(parent, child, key)
224
230
  } else if (key !== 'mixins' && key !== 'mpxCustomKeysForBlend') {
225
231
  // 收集非函数的自定义属性,在Component创建的页面中挂载到this上,模拟Page创建页面的表现,swan当中component构造器也能自动挂载自定义数据,不需要框架模拟挂载
226
232
  if (curType === 'blend' && typeof child[key] !== 'function' && !builtInKeysMap[key] && __mpx_mode__ !== 'swan') {
@@ -277,6 +283,37 @@ function mergeDataFn (parent, child, key) {
277
283
  }
278
284
  }
279
285
 
286
+ function normalizeInject (options) {
287
+ const injectOpt = options.inject
288
+ if (isArray(injectOpt)) {
289
+ const normalized = (options.inject = {})
290
+ for (let i = 0; i < injectOpt.length; i++) {
291
+ normalized[injectOpt[i]] = injectOpt[i]
292
+ }
293
+ }
294
+ }
295
+
296
+ function mergeInject (parent, child, key) {
297
+ normalizeInject(child)
298
+ mergeShallowObj(parent, child, key)
299
+ }
300
+
301
+ function mergeProvide (parent, child, key) {
302
+ const parentVal = parent[key]
303
+ const childVal = child[key]
304
+ if (!parentVal) {
305
+ parent[key] = childVal
306
+ } else if (!childVal) {
307
+ parent[key] = parentVal
308
+ } else {
309
+ parent[key] = function mergedProvide () {
310
+ const to = isFunction(parentVal) ? parentVal.call(this) : parentVal
311
+ const from = isFunction(childVal) ? childVal.call(this) : childVal
312
+ return Object.assign(to, from)
313
+ }
314
+ }
315
+ }
316
+
280
317
  export function mergeArray (parent, child, key) {
281
318
  const childVal = child[key]
282
319
  if (!parent[key]) {
package/src/core/proxy.js CHANGED
@@ -101,7 +101,6 @@ function preProcessRenderData (renderData) {
101
101
  })
102
102
  return processedRenderData
103
103
  }
104
-
105
104
  export default class MpxProxy {
106
105
  constructor (options, target, reCreated) {
107
106
  this.target = target
@@ -317,7 +316,8 @@ export default class MpxProxy {
317
316
  selectComponent: this.target.selectComponent.bind(this.target),
318
317
  selectAllComponents: this.target.selectAllComponents.bind(this.target),
319
318
  createSelectorQuery: this.target.createSelectorQuery ? this.target.createSelectorQuery.bind(this.target) : envObj.createSelectorQuery.bind(envObj),
320
- createIntersectionObserver: this.target.createIntersectionObserver ? this.target.createIntersectionObserver.bind(this.target) : envObj.createIntersectionObserver.bind(envObj)
319
+ createIntersectionObserver: this.target.createIntersectionObserver ? this.target.createIntersectionObserver.bind(this.target) : envObj.createIntersectionObserver.bind(envObj),
320
+ getPageId: this.target.getPageId.bind(this.target)
321
321
  }
322
322
  ])
323
323
  if (!isObject(setupResult)) {
@@ -1,4 +1,3 @@
1
- import { isReact } from '@mpxjs/utils'
2
1
  import pageStatusMixin from './pageStatusMixin'
3
2
  import proxyEventMixin from './proxyEventMixin'
4
3
  import renderHelperMixin from './renderHelperMixin'
@@ -14,10 +13,11 @@ import pageRouteMixin from './pageRouteMixin'
14
13
  import { dynamicRefsMixin, dynamicRenderHelperMixin, dynamicSlotMixin } from '../../dynamic/dynamicRenderMixin.empty'
15
14
  import styleHelperMixin from './styleHelperMixin'
16
15
  import directiveHelperMixin from './directiveHelperMixin'
16
+ import pageIdMixin from './pageIdMixin'
17
17
 
18
18
  export default function getBuiltInMixins ({ type, rawOptions = {} }) {
19
19
  let bulitInMixins
20
- if (isReact) {
20
+ if (__mpx_mode__ === 'ios' || __mpx_mode__ === 'android') {
21
21
  bulitInMixins = [
22
22
  proxyEventMixin(),
23
23
  directiveHelperMixin(),
@@ -37,7 +37,8 @@ export default function getBuiltInMixins ({ type, rawOptions = {} }) {
37
37
  getTabBarMixin(type),
38
38
  pageRouteMixin(type),
39
39
  // 由于relation可能是通过mixin注入的,不能通过当前的用户options中是否存在relations来简单判断是否注入该项mixin
40
- relationsMixin(type)
40
+ relationsMixin(type),
41
+ pageIdMixin(type)
41
42
  ]
42
43
  } else {
43
44
  // 此为差异抹平类mixins,原生模式下也需要注入也抹平平台差异
@@ -47,6 +48,11 @@ export default function getBuiltInMixins ({ type, rawOptions = {} }) {
47
48
  refsMixin(),
48
49
  relationsMixin(type)
49
50
  ]
51
+ if (__mpx_mode__ === 'ali') {
52
+ bulitInMixins = bulitInMixins.concat([
53
+ pageIdMixin(type)
54
+ ])
55
+ }
50
56
  // 此为纯增强类mixins,原生模式下不需要注入
51
57
  if (!rawOptions.__nativeRender__) {
52
58
  bulitInMixins = bulitInMixins.concat([
@@ -0,0 +1,13 @@
1
+ export default function pageIdMixin (mixinType) {
2
+ return {
3
+ methods: {
4
+ getPageId () {
5
+ if (mixinType === 'component') {
6
+ return this.$page.$id
7
+ } else {
8
+ return this.$id
9
+ }
10
+ }
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,25 @@
1
+ let pageId = 0
2
+
3
+ export default function pageIdMixin (mixinType) {
4
+ const mixin = {}
5
+
6
+ if (mixinType === 'page') {
7
+ Object.assign(mixin, {
8
+ beforeCreate () {
9
+ this.__pageId = ++pageId
10
+ },
11
+ provide () {
12
+ return {
13
+ __pageId: this.__pageId
14
+ }
15
+ }
16
+ })
17
+ }
18
+ if (mixinType === 'component') {
19
+ Object.assign(mixin, {
20
+ inject: ['__pageId']
21
+ })
22
+ }
23
+
24
+ return mixin
25
+ }
@@ -6,8 +6,6 @@ import { LIFECYCLE } from '../platform/patch/lifecycle/index'
6
6
  import Mpx from '../index'
7
7
  import { createElement, memo, useRef, useEffect } from 'react'
8
8
  import * as ReactNative from 'react-native'
9
- import { Image } from 'react-native'
10
-
11
9
  import { initAppProvides } from './export/inject'
12
10
 
13
11
  const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)
@@ -183,23 +181,29 @@ export default function createApp (options) {
183
181
  }, [])
184
182
 
185
183
  const { initialRouteName, initialParams } = initialRouteRef.current
186
- const headerBackImageProps = Mpx.config.rnConfig.headerBackImageProps || null
187
- const headerBackImageSource = Mpx.config.rnConfig.headerBackImageSource || null
188
184
  const navScreenOpts = {
189
185
  // 7.x替换headerBackTitleVisible
190
186
  // headerBackButtonDisplayMode: 'minimal',
191
187
  headerBackTitleVisible: false,
192
- // 安卓上会出现初始化时闪现导航条的问题
193
- headerShown: false,
194
188
  headerShadowVisible: false
195
189
  }
196
- if (headerBackImageProps) {
197
- navScreenOpts.headerBackImage = () => {
198
- return createElement(Image, headerBackImageProps)
190
+ if (__mpx_mode__ === 'ios') {
191
+ // ios使用native-stack
192
+ const headerBackImageSource = Mpx.config.rnConfig.headerBackImageSource || null
193
+ if (headerBackImageSource) {
194
+ navScreenOpts.headerBackImageSource = headerBackImageSource
195
+ }
196
+ } else {
197
+ // 安卓上会出现导航条闪现的问题所以默认加headerShown false(stack版本, native-stack版本可以干掉)
198
+ // iOS加上默认headerShown false的话会因为iOS根高度是screenHeight - useHeaderHeight()会导致出现渲染两次情况,因此iOS不加此默认值
199
+ navScreenOpts.headerShown = false
200
+ // 安卓和鸿蒙先用stack
201
+ const headerBackImageProps = Mpx.config.rnConfig.headerBackImageProps || null
202
+ if (headerBackImageProps) {
203
+ navScreenOpts.headerBackImage = () => {
204
+ return createElement(ReactNative.Image, headerBackImageProps)
205
+ }
199
206
  }
200
- }
201
- if (headerBackImageSource) {
202
- navScreenOpts.headerBackImageSource = headerBackImageSource
203
207
  }
204
208
 
205
209
  return createElement(SafeAreaProvider,
@@ -126,5 +126,9 @@ export default function install (Vue) {
126
126
  Vue.prototype.createIntersectionObserver = function (options) {
127
127
  return createIntersectionObserver(this, options)
128
128
  }
129
+
130
+ Vue.prototype.getPageId = function () {
131
+ return this.__pageId
132
+ }
129
133
  hackEffectScope()
130
134
  }
@@ -286,11 +286,27 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
286
286
  instance.route = props.route.name
287
287
  global.__mpxPagesMap = global.__mpxPagesMap || {}
288
288
  global.__mpxPagesMap[props.route.key] = [instance, props.navigation]
289
+ // App onLaunch 在 Page created 之前执行
290
+ if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
291
+ global.__mpxAppOnLaunch(props.navigation)
292
+ }
289
293
  }
290
294
 
291
295
  const proxy = instance.__mpxProxy = new MpxProxy(rawOptions, instance)
292
296
  proxy.created()
293
297
 
298
+ if (type === 'page') {
299
+ const loadParams = {}
300
+ const props = propsRef.current
301
+ // 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
302
+ if (isObject(props.route.params)) {
303
+ for (const key in props.route.params) {
304
+ loadParams[key] = encodeURIComponent(props.route.params[key])
305
+ }
306
+ }
307
+ proxy.callHook(ONLOAD, [loadParams])
308
+ }
309
+
294
310
  Object.assign(proxy, {
295
311
  onStoreChange: null,
296
312
  stateVersion: Symbol(),
@@ -384,7 +400,9 @@ const pageStatusMap = global.__mpxPageStatusMap = reactive({})
384
400
 
385
401
  function usePageStatus (navigation, pageId) {
386
402
  navigation.pageId = pageId
387
- set(pageStatusMap, pageId, '')
403
+ if (!hasOwn(pageStatusMap, pageId)) {
404
+ set(pageStatusMap, pageId, '')
405
+ }
388
406
  useEffect(() => {
389
407
  const focusSubscription = navigation.addListener('focus', () => {
390
408
  pageStatusMap[pageId] = 'show'
@@ -422,16 +440,6 @@ const checkRelation = (options) => {
422
440
  }
423
441
  }
424
442
 
425
- const provideRelation = (instance, relation) => {
426
- const componentPath = instance.__componentPath
427
- if (relation) {
428
- return Object.assign({}, relation, { [componentPath]: instance })
429
- } else {
430
- return {
431
- [componentPath]: instance
432
- }
433
- }
434
- }
435
443
  export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
436
444
  rawOptions = mergeOptions(rawOptions, type, false)
437
445
  const components = Object.assign({}, rawOptions.components, currentInject.getComponents())
@@ -501,19 +509,6 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
501
509
  usePageEffect(proxy, pageId)
502
510
 
503
511
  useEffect(() => {
504
- if (type === 'page') {
505
- if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
506
- global.__mpxAppOnLaunch(props.navigation)
507
- }
508
- const loadParams = {}
509
- // 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
510
- if (isObject(props.route.params)) {
511
- for (const key in props.route.params) {
512
- loadParams[key] = encodeURIComponent(props.route.params[key])
513
- }
514
- }
515
- proxy.callHook(ONLOAD, [loadParams])
516
- }
517
512
  proxy.mounted()
518
513
  return () => {
519
514
  proxy.unmounted()
@@ -551,14 +546,28 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
551
546
  root = createElement(ProviderContext.Provider, { value: provides }, root)
552
547
  }
553
548
 
554
- return hasDescendantRelation
555
- ? createElement(RelationsContext.Provider,
556
- {
557
- value: provideRelation(instance, relation)
558
- },
559
- root
560
- )
561
- : root
549
+ if (hasDescendantRelation) {
550
+ const relationProvide = useMemo(() => {
551
+ const componentPath = instance.__componentPath
552
+ if (relation) {
553
+ return Object.assign({}, relation, { [componentPath]: instance })
554
+ } else {
555
+ return {
556
+ [componentPath]: instance
557
+ }
558
+ }
559
+ }, [relation])
560
+
561
+ return createElement(
562
+ RelationsContext.Provider,
563
+ {
564
+ value: relationProvide
565
+ },
566
+ root
567
+ )
568
+ } else {
569
+ return root
570
+ }
562
571
  }))
563
572
 
564
573
  if (rawOptions.options?.isCustomText) {
@@ -571,6 +580,10 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
571
580
  const Page = ({ navigation, route }) => {
572
581
  const currentPageId = useMemo(() => ++pageId, [])
573
582
  const intersectionObservers = useRef({})
583
+ const routeContextValRef = useRef({
584
+ pageId: currentPageId,
585
+ navigation
586
+ })
574
587
  usePageStatus(navigation, currentPageId)
575
588
  useLayoutEffect(() => {
576
589
  const isCustom = pageConfig.navigationStyle === 'custom'
@@ -583,7 +596,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
583
596
  headerTintColor: pageConfig.navigationBarTextStyle || 'white'
584
597
  })
585
598
 
586
- if (__mpx_mode__ === 'android' || __mpx_mode__ === 'harmony') {
599
+ if (__mpx_mode__ === 'android') {
587
600
  ReactNative.StatusBar.setBarStyle(pageConfig.barStyle || 'dark-content')
588
601
  ReactNative.StatusBar.setTranslucent(isCustom) // 控制statusbar是否占位
589
602
  const color = isCustom ? 'transparent' : pageConfig.statusBarColor
@@ -592,7 +605,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
592
605
  }, [])
593
606
 
594
607
  const rootRef = useRef(null)
595
- const keyboardAvoidRef = useRef({ cursorSpacing: 0, ref: null })
608
+ const keyboardAvoidRef = useRef(null)
596
609
  useEffect(() => {
597
610
  setTimeout(() => {
598
611
  rootRef.current?.measureInWindow((x, y, width, height) => {
@@ -625,12 +638,12 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
625
638
  {
626
639
  // https://github.com/software-mansion/react-native-reanimated/issues/6639 因存在此问题,iOS在页面上进行定宽来暂时规避
627
640
  style: __mpx_mode__ === 'ios' && pageConfig.navigationStyle !== 'custom'
628
- ? {
629
- height: ReactNative.Dimensions.get('screen').height - useHeaderHeight()
630
- }
631
- : {
632
- flex: 1
633
- }
641
+ ? {
642
+ height: ReactNative.Dimensions.get('screen').height - useHeaderHeight()
643
+ }
644
+ : {
645
+ flex: 1
646
+ }
634
647
  },
635
648
  withKeyboardAvoidingView(
636
649
  createElement(ReactNative.View,
@@ -643,10 +656,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
643
656
  },
644
657
  createElement(RouteContext.Provider,
645
658
  {
646
- value: {
647
- pageId: currentPageId,
648
- navigation
649
- }
659
+ value: routeContextValRef.current
650
660
  },
651
661
  createElement(IntersectionObserverContext.Provider,
652
662
  {
@@ -60,7 +60,8 @@ export function getDefaultOptions ({ type, rawOptions = {} }) {
60
60
  selectComponent: instance.selectComponent.bind(instance),
61
61
  selectAllComponents: instance.selectAllComponents.bind(instance),
62
62
  createSelectorQuery: instance.createSelectorQuery.bind(instance),
63
- createIntersectionObserver: instance.createIntersectionObserver.bind(instance)
63
+ createIntersectionObserver: instance.createIntersectionObserver.bind(instance),
64
+ getPageId: instance.getPageId.bind(instance)
64
65
  }
65
66
  const setupRes = rawSetup(props, newContext)
66
67
  unsetCurrentInstance(instance.__mpxProxy)
File without changes