@mpxjs/core 2.10.1 → 2.10.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.10.1",
3
+ "version": "2.10.3",
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": "7e4f9ab5528f1ab0ae08fdfad1bfbbb445088848"
112
+ "gitHead": "043c9bc770ce9cc11f865bab67f46849ff573728"
113
113
  }
@@ -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)) {
@@ -18,6 +18,10 @@ export default function transferOptions (options, type, needConvert = true) {
18
18
  if (!options.__nativeRender__) {
19
19
  options = mergeInjectedMixins(options, type)
20
20
  }
21
+ if (currentInject && currentInject.injectProperties) {
22
+ // 编译属性注入
23
+ options.properties = Object.assign({}, currentInject.injectProperties, options.properties)
24
+ }
21
25
  if (currentInject && currentInject.injectComputed) {
22
26
  // 编译计算属性注入
23
27
  options.computed = Object.assign({}, currentInject.injectComputed, options.computed)
@@ -13,6 +13,7 @@ import pageRouteMixin from './pageRouteMixin'
13
13
  import { dynamicRefsMixin, dynamicRenderHelperMixin, dynamicSlotMixin } from '../../dynamic/dynamicRenderMixin.empty'
14
14
  import styleHelperMixin from './styleHelperMixin'
15
15
  import directiveHelperMixin from './directiveHelperMixin'
16
+ import pageIdMixin from './pageIdMixin'
16
17
 
17
18
  export default function getBuiltInMixins ({ type, rawOptions = {} }) {
18
19
  let bulitInMixins
@@ -36,7 +37,8 @@ export default function getBuiltInMixins ({ type, rawOptions = {} }) {
36
37
  getTabBarMixin(type),
37
38
  pageRouteMixin(type),
38
39
  // 由于relation可能是通过mixin注入的,不能通过当前的用户options中是否存在relations来简单判断是否注入该项mixin
39
- relationsMixin(type)
40
+ relationsMixin(type),
41
+ pageIdMixin(type)
40
42
  ]
41
43
  } else {
42
44
  // 此为差异抹平类mixins,原生模式下也需要注入也抹平平台差异
@@ -46,6 +48,11 @@ export default function getBuiltInMixins ({ type, rawOptions = {} }) {
46
48
  refsMixin(),
47
49
  relationsMixin(type)
48
50
  ]
51
+ if (__mpx_mode__ === 'ali') {
52
+ bulitInMixins = bulitInMixins.concat([
53
+ pageIdMixin(type)
54
+ ])
55
+ }
49
56
  // 此为纯增强类mixins,原生模式下不需要注入
50
57
  if (!rawOptions.__nativeRender__) {
51
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
+ }
@@ -195,7 +195,14 @@ export default function styleHelperMixin () {
195
195
 
196
196
  if (hide) {
197
197
  Object.assign(result, {
198
- display: 'none'
198
+ // display: 'none'
199
+ // RN下display:'none'容易引发未知异常问题,使用布局样式模拟
200
+ flex: 0,
201
+ height: 0,
202
+ width: 0,
203
+ padding: 0,
204
+ margin: 0,
205
+ overflow: 'hidden'
199
206
  })
200
207
  }
201
208
 
@@ -10,8 +10,8 @@ import { initAppProvides } from './export/inject'
10
10
 
11
11
  const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)
12
12
 
13
- function getOrientation (window = ReactNative.Dimensions.get('window')) {
14
- return window.width > window.height ? 'landscape' : 'portrait'
13
+ function getPageSize (window = ReactNative.Dimensions.get('window')) {
14
+ return window.width + 'x' + window.height
15
15
  }
16
16
 
17
17
  function filterOptions (options, appData) {
@@ -56,16 +56,22 @@ export default function createApp (options) {
56
56
  const Stack = createStackNavigator()
57
57
  const getPageScreens = (initialRouteName, initialParams) => {
58
58
  return Object.entries(pages).map(([key, item]) => {
59
+ const options = {
60
+ // __mpxPageStatusMap 为编译注入的全局变量
61
+ headerShown: !(Object.assign({}, global.__mpxPageConfig, global.__mpxPageConfigsMap[key]).navigationStyle === 'custom')
62
+ }
59
63
  if (key === initialRouteName) {
60
64
  return createElement(Stack.Screen, {
61
65
  name: key,
62
66
  component: item,
63
- initialParams
67
+ initialParams,
68
+ options
64
69
  })
65
70
  }
66
71
  return createElement(Stack.Screen, {
67
72
  name: key,
68
- component: item
73
+ component: item,
74
+ options
69
75
  })
70
76
  })
71
77
  }
@@ -154,7 +160,9 @@ export default function createApp (options) {
154
160
  }
155
161
  } else if (currentState === 'inactive' || currentState === 'background') {
156
162
  global.__mpxAppCbs.hide.forEach((cb) => {
157
- cb()
163
+ cb({
164
+ reason: 3
165
+ })
158
166
  })
159
167
  const navigation = getFocusedNavigation()
160
168
  if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
@@ -164,35 +172,55 @@ export default function createApp (options) {
164
172
  })
165
173
 
166
174
  let count = 0
167
- let lastOrientation = getOrientation()
175
+ let lastPageSize = getPageSize()
168
176
  const resizeSubScription = ReactNative.Dimensions.addEventListener('change', ({ window }) => {
169
- const orientation = getOrientation(window)
170
- if (orientation === lastOrientation) return
171
- lastOrientation = orientation
177
+ const pageSize = getPageSize(window)
178
+ if (pageSize === lastPageSize) return
179
+ lastPageSize = pageSize
172
180
  const navigation = getFocusedNavigation()
173
181
  if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
174
182
  global.__mpxPageStatusMap[navigation.pageId] = `resize${count++}`
175
183
  }
176
184
  })
177
185
  return () => {
186
+ // todo 跳到原生页面或者其他rn bundle可以考虑使用reason 1/2进行模拟抹平
187
+ global.__mpxAppCbs.hide.forEach((cb) => {
188
+ cb({
189
+ reason: 0
190
+ })
191
+ })
178
192
  changeSubscription && changeSubscription.remove()
179
193
  resizeSubScription && resizeSubScription.remove()
180
194
  }
181
195
  }, [])
182
196
 
183
197
  const { initialRouteName, initialParams } = initialRouteRef.current
184
- const headerBackImageSource = Mpx.config.rnConfig.headerBackImageSource || null
185
198
  const navScreenOpts = {
186
199
  // 7.x替换headerBackTitleVisible
187
200
  // headerBackButtonDisplayMode: 'minimal',
188
201
  headerBackTitleVisible: false,
189
- // 安卓上会出现初始化时闪现导航条的问题
190
- headerShown: false,
191
- // 隐藏导航下的那条线
192
202
  headerShadowVisible: false
203
+ // 整体切换native-stack时进行修改如下
204
+ // statusBarTranslucent: true,
205
+ // statusBarBackgroundColor: 'transparent'
193
206
  }
194
- if (headerBackImageSource) {
195
- navScreenOpts.headerBackImageSource = headerBackImageSource
207
+ if (__mpx_mode__ === 'ios') {
208
+ // ios使用native-stack
209
+ const headerBackImageSource = Mpx.config.rnConfig.headerBackImageSource || null
210
+ if (headerBackImageSource) {
211
+ navScreenOpts.headerBackImageSource = headerBackImageSource
212
+ }
213
+ } else {
214
+ // 安卓上会出现导航条闪现的问题所以默认加headerShown false(stack版本, native-stack版本可以干掉)
215
+ // iOS加上默认headerShown false的话会因为iOS根高度是screenHeight - useHeaderHeight()会导致出现渲染两次情况,因此iOS不加此默认值
216
+ navScreenOpts.headerShown = false
217
+ // 安卓和鸿蒙先用stack
218
+ const headerBackImageProps = Mpx.config.rnConfig.headerBackImageProps || null
219
+ if (headerBackImageProps) {
220
+ navScreenOpts.headerBackImage = () => {
221
+ return createElement(ReactNative.Image, headerBackImageProps)
222
+ }
223
+ }
196
224
  }
197
225
 
198
226
  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
  }
@@ -1,4 +1,4 @@
1
- import { useEffect, useLayoutEffect, useSyncExternalStore, useRef, useMemo, useCallback, createElement, memo, forwardRef, useImperativeHandle, useContext, Fragment, cloneElement, createContext } from 'react'
1
+ import { useEffect, useLayoutEffect, useSyncExternalStore, useRef, useMemo, createElement, memo, forwardRef, useImperativeHandle, useContext, Fragment, cloneElement, createContext } from 'react'
2
2
  import * as ReactNative from 'react-native'
3
3
  import { ReactiveEffect } from '../../observer/effect'
4
4
  import { watch } from '../../observer/watch'
@@ -10,20 +10,19 @@ import mergeOptions from '../../core/mergeOptions'
10
10
  import { queueJob, hasPendingJob } from '../../observer/scheduler'
11
11
  import { createSelectorQuery, createIntersectionObserver } from '@mpxjs/api-proxy'
12
12
  import { IntersectionObserverContext, RouteContext, KeyboardAvoidContext } from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/context'
13
- import KeyboardAvoidingView from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/KeyboardAvoidingView'
13
+ import MpxKeyboardAvoidingView from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view'
14
14
 
15
15
  const ProviderContext = createContext(null)
16
-
16
+ const windowDimensions = ReactNative.Dimensions.get('window')
17
+ const screenDimensions = ReactNative.Dimensions.get('screen')
17
18
  function getSystemInfo () {
18
- const window = ReactNative.Dimensions.get('window')
19
- const screen = ReactNative.Dimensions.get('screen')
20
19
  return {
21
- deviceOrientation: window.width > window.height ? 'landscape' : 'portrait',
20
+ deviceOrientation: windowDimensions.width > windowDimensions.height ? 'landscape' : 'portrait',
22
21
  size: {
23
- screenWidth: screen.width,
24
- screenHeight: screen.height,
25
- windowWidth: window.width,
26
- windowHeight: window.height
22
+ screenWidth: screenDimensions.width,
23
+ screenHeight: screenDimensions.height,
24
+ windowWidth: windowDimensions.width,
25
+ windowHeight: windowDimensions.height
27
26
  }
28
27
  }
29
28
  }
@@ -46,7 +45,9 @@ function createEffect (proxy, components) {
46
45
  if (!tagName) return null
47
46
  if (tagName === 'block') return Fragment
48
47
  const appComponents = global.__getAppComponents?.() || {}
49
- return components[tagName] || appComponents[tagName] || getByPath(ReactNative, tagName)
48
+ const generichash = proxy.target.generichash || ''
49
+ const genericComponents = global.__mpxGenericsMap[generichash] || noop
50
+ return components[tagName] || genericComponents(tagName) || appComponents[tagName] || getByPath(ReactNative, tagName)
50
51
  }
51
52
  const innerCreateElement = (type, ...rest) => {
52
53
  if (!type) return null
@@ -286,11 +287,27 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
286
287
  instance.route = props.route.name
287
288
  global.__mpxPagesMap = global.__mpxPagesMap || {}
288
289
  global.__mpxPagesMap[props.route.key] = [instance, props.navigation]
290
+ // App onLaunch 在 Page created 之前执行
291
+ if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
292
+ global.__mpxAppOnLaunch(props.navigation)
293
+ }
289
294
  }
290
295
 
291
296
  const proxy = instance.__mpxProxy = new MpxProxy(rawOptions, instance)
292
297
  proxy.created()
293
298
 
299
+ if (type === 'page') {
300
+ const loadParams = {}
301
+ const props = propsRef.current
302
+ // 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
303
+ if (isObject(props.route.params)) {
304
+ for (const key in props.route.params) {
305
+ loadParams[key] = encodeURIComponent(props.route.params[key])
306
+ }
307
+ }
308
+ proxy.callHook(ONLOAD, [loadParams])
309
+ }
310
+
294
311
  Object.assign(proxy, {
295
312
  onStoreChange: null,
296
313
  stateVersion: Symbol(),
@@ -384,7 +401,9 @@ const pageStatusMap = global.__mpxPageStatusMap = reactive({})
384
401
 
385
402
  function usePageStatus (navigation, pageId) {
386
403
  navigation.pageId = pageId
387
- set(pageStatusMap, pageId, '')
404
+ if (!hasOwn(pageStatusMap, pageId)) {
405
+ set(pageStatusMap, pageId, '')
406
+ }
388
407
  useEffect(() => {
389
408
  const focusSubscription = navigation.addListener('focus', () => {
390
409
  pageStatusMap[pageId] = 'show'
@@ -422,17 +441,8 @@ const checkRelation = (options) => {
422
441
  }
423
442
  }
424
443
 
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
-
444
+ // 临时用来存储安卓底部(iOS没有这个)的高度(虚拟按键等高度)根据第一次进入推算
445
+ let bottomVirtualHeight = null
436
446
  export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
437
447
  rawOptions = mergeOptions(rawOptions, type, false)
438
448
  const components = Object.assign({}, rawOptions.components, currentInject.getComponents())
@@ -502,19 +512,6 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
502
512
  usePageEffect(proxy, pageId)
503
513
 
504
514
  useEffect(() => {
505
- if (type === 'page') {
506
- if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
507
- global.__mpxAppOnLaunch(props.navigation)
508
- }
509
- const loadParams = {}
510
- // 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
511
- if (isObject(props.route.params)) {
512
- for (const key in props.route.params) {
513
- loadParams[key] = encodeURIComponent(props.route.params[key])
514
- }
515
- }
516
- proxy.callHook(ONLOAD, [loadParams])
517
- }
518
515
  proxy.mounted()
519
516
  return () => {
520
517
  proxy.unmounted()
@@ -552,14 +549,28 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
552
549
  root = createElement(ProviderContext.Provider, { value: provides }, root)
553
550
  }
554
551
 
555
- return hasDescendantRelation
556
- ? createElement(RelationsContext.Provider,
557
- {
558
- value: provideRelation(instance, relation)
559
- },
560
- root
561
- )
562
- : root
552
+ if (hasDescendantRelation) {
553
+ const relationProvide = useMemo(() => {
554
+ const componentPath = instance.__componentPath
555
+ if (relation) {
556
+ return Object.assign({}, relation, { [componentPath]: instance })
557
+ } else {
558
+ return {
559
+ [componentPath]: instance
560
+ }
561
+ }
562
+ }, [relation])
563
+
564
+ return createElement(
565
+ RelationsContext.Provider,
566
+ {
567
+ value: relationProvide
568
+ },
569
+ root
570
+ )
571
+ } else {
572
+ return root
573
+ }
563
574
  }))
564
575
 
565
576
  if (rawOptions.options?.isCustomText) {
@@ -572,34 +583,70 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
572
583
  const Page = ({ navigation, route }) => {
573
584
  const currentPageId = useMemo(() => ++pageId, [])
574
585
  const intersectionObservers = useRef({})
586
+ const routeContextValRef = useRef({
587
+ pageId: currentPageId,
588
+ navigation
589
+ })
575
590
  usePageStatus(navigation, currentPageId)
576
591
  useLayoutEffect(() => {
577
- const isCustom = pageConfig.navigationStyle === 'custom'
578
- navigation.setOptions(Object.assign({
579
- headerShown: !isCustom,
580
- title: pageConfig.navigationBarTitleText || '',
592
+ navigation.setOptions({
593
+ title: pageConfig.navigationBarTitleText?.trim() || '',
581
594
  headerStyle: {
582
595
  backgroundColor: pageConfig.navigationBarBackgroundColor || '#000000'
583
596
  },
584
- headerTintColor: pageConfig.navigationBarTextStyle || 'white',
585
- statusBarTranslucent: true
586
- }, __mpx_mode__ === 'android' ? { statusBarStyle: pageConfig.statusBarStyle || 'light' } : {}))
587
- }, [])
588
-
589
- const rootRef = useRef(null)
590
- const keyboardAvoidRef = useRef({ cursorSpacing: 0, ref: null })
591
- const onLayout = useCallback(() => {
592
- rootRef.current?.measureInWindow((x, y, width, height) => {
593
- navigation.layout = { x, y, width, height }
597
+ headerTintColor: pageConfig.navigationBarTextStyle || 'white'
594
598
  })
599
+
600
+ // TODO 此部分内容在native-stack可删除,用setOptions设置
601
+ if (__mpx_mode__ === 'android') {
602
+ ReactNative.StatusBar.setBarStyle(pageConfig.barStyle || 'dark-content')
603
+ ReactNative.StatusBar.setTranslucent(true) // 控制statusbar是否占位
604
+ ReactNative.StatusBar.setBackgroundColor('transparent')
605
+ }
595
606
  }, [])
596
607
 
608
+ const rootRef = useRef(null)
609
+ const keyboardAvoidRef = useRef(null)
610
+ const headerHeight = useHeaderHeight()
611
+ const onLayout = () => {
612
+ if (__mpx_mode__ === 'ios') {
613
+ navigation.layout = {
614
+ x: 0,
615
+ y: headerHeight,
616
+ width: windowDimensions.width,
617
+ height: screenDimensions.height - headerHeight
618
+ }
619
+ } else {
620
+ if (bottomVirtualHeight === null) {
621
+ rootRef.current?.measureInWindow((height) => {
622
+ // 沉浸模式的计算方式
623
+ bottomVirtualHeight = screenDimensions.height - height - headerHeight
624
+ // 非沉浸模式(translucent=true)计算方式, 现在默认是全用沉浸模式,所以先不算这个
625
+ // bottomVirtualHeight = windowDimensions.height - height - headerHeight
626
+ navigation.layout = {
627
+ x: 0,
628
+ y: headerHeight,
629
+ width: windowDimensions.width,
630
+ height: height
631
+ }
632
+ })
633
+ } else {
634
+ navigation.layout = {
635
+ x: 0,
636
+ y: headerHeight, // 这个y值
637
+ width: windowDimensions.width,
638
+ // 后续页面的layout是通过第一次路由进入时候推算出来的底部区域来推算出来的
639
+ height: screenDimensions.height - bottomVirtualHeight - headerHeight
640
+ }
641
+ }
642
+ }
643
+ }
597
644
  const withKeyboardAvoidingView = (element) => {
598
645
  return createElement(KeyboardAvoidContext.Provider,
599
646
  {
600
647
  value: keyboardAvoidRef
601
648
  },
602
- createElement(KeyboardAvoidingView,
649
+ createElement(MpxKeyboardAvoidingView,
603
650
  {
604
651
  style: {
605
652
  flex: 1
@@ -619,12 +666,12 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
619
666
  {
620
667
  // https://github.com/software-mansion/react-native-reanimated/issues/6639 因存在此问题,iOS在页面上进行定宽来暂时规避
621
668
  style: __mpx_mode__ === 'ios' && pageConfig.navigationStyle !== 'custom'
622
- ? {
623
- height: ReactNative.Dimensions.get('screen').height - useHeaderHeight()
624
- }
625
- : {
626
- flex: 1
627
- }
669
+ ? {
670
+ height: ReactNative.Dimensions.get('screen').height - useHeaderHeight()
671
+ }
672
+ : {
673
+ flex: 1
674
+ }
628
675
  },
629
676
  withKeyboardAvoidingView(
630
677
  createElement(ReactNative.View,
@@ -634,14 +681,12 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
634
681
  backgroundColor: pageConfig.backgroundColor || '#ffffff'
635
682
  },
636
683
  ref: rootRef,
684
+ // 测试过了 键盘拉起后不会重新触发onLayout
637
685
  onLayout
638
686
  },
639
687
  createElement(RouteContext.Provider,
640
688
  {
641
- value: {
642
- pageId: currentPageId,
643
- navigation
644
- }
689
+ value: routeContextValRef.current
645
690
  },
646
691
  createElement(IntersectionObserverContext.Provider,
647
692
  {
@@ -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)