@mpxjs/core 2.9.69 → 2.9.70

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.
Files changed (38) hide show
  1. package/package.json +7 -3
  2. package/src/convertor/convertor.js +11 -32
  3. package/src/convertor/wxToAli.js +3 -3
  4. package/src/convertor/wxToSwan.js +3 -3
  5. package/src/convertor/wxToWeb.js +3 -3
  6. package/src/core/proxy.js +18 -12
  7. package/src/dynamic/dynamicRenderMixin.js +2 -2
  8. package/src/index.js +3 -14
  9. package/src/observer/reactive.js +5 -4
  10. package/src/observer/ref.js +3 -2
  11. package/src/observer/scheduler.js +4 -0
  12. package/src/observer/watch.js +5 -4
  13. package/src/platform/builtInMixins/directiveHelperMixin.ios.js +4 -1
  14. package/src/platform/builtInMixins/styleHelperMixin.ios.js +7 -4
  15. package/src/platform/createApp.ios.js +45 -33
  16. package/src/platform/createApp.js +7 -9
  17. package/src/platform/env/event.js +108 -0
  18. package/src/platform/env/index.ios.js +51 -0
  19. package/src/platform/env/index.js +8 -0
  20. package/src/platform/env/index.web.js +48 -0
  21. package/src/{external → platform/env}/vuePlugin.js +1 -1
  22. package/src/platform/export/index.js +1 -1
  23. package/src/platform/patch/{ali/getDefaultOptions.js → getDefaultOptions.ali.js} +3 -3
  24. package/src/platform/patch/{react/getDefaultOptions.ios.js → getDefaultOptions.ios.js} +263 -192
  25. package/src/platform/patch/{wx/getDefaultOptions.js → getDefaultOptions.js} +11 -5
  26. package/src/platform/patch/{web/getDefaultOptions.js → getDefaultOptions.web.js} +5 -5
  27. package/src/platform/patch/index.js +4 -21
  28. package/src/platform/patch/{ali/lifecycle.js → lifecycle/index.ali.js} +2 -0
  29. package/src/platform/patch/lifecycle/index.js +1 -0
  30. package/src/platform/patch/{swan/lifecycle.js → lifecycle/index.swan.js} +2 -0
  31. package/src/platform/patch/{web/lifecycle.js → lifecycle/index.web.js} +4 -0
  32. package/src/platform/patch/{wx/lifecycle.js → lifecycle/index.wx.js} +2 -0
  33. package/src/external/vue.js +0 -1
  34. package/src/external/vue.web.js +0 -6
  35. package/src/platform/patch/react/getDefaultOptions.js +0 -1
  36. package/src/platform/patch/swan/getDefaultOptions.js +0 -34
  37. /package/src/platform/export/{apiInject.js → inject.js} +0 -0
  38. /package/src/platform/export/{apiInject.web.js → inject.web.js} +0 -0
@@ -1,15 +1,15 @@
1
- import { useEffect, useLayoutEffect, useSyncExternalStore, useRef, useMemo, useCallback, createElement, memo, forwardRef, useImperativeHandle, useContext, Fragment, cloneElement } from 'react'
1
+ import { useEffect, useLayoutEffect, useSyncExternalStore, useRef, useMemo, useState, useCallback, createElement, memo, forwardRef, useImperativeHandle, useContext, Fragment, cloneElement } from 'react'
2
2
  import * as ReactNative from 'react-native'
3
- import { ReactiveEffect } from '../../../observer/effect'
4
- import { watch } from '../../../observer/watch'
5
- import { reactive, set, del } from '../../../observer/reactive'
6
- import { hasOwn, isFunction, noop, isObject, isArray, getByPath, collectDataset, hump2dash, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
7
- import MpxProxy from '../../../core/proxy'
8
- import { BEFOREUPDATE, ONLOAD, UPDATED, ONSHOW, ONHIDE, ONRESIZE, REACTHOOKSEXEC } from '../../../core/innerLifecycle'
9
- import mergeOptions from '../../../core/mergeOptions'
10
- import { queueJob } from '../../../observer/scheduler'
3
+ import { ReactiveEffect } from '../../observer/effect'
4
+ import { watch } from '../../observer/watch'
5
+ import { reactive, set, del } from '../../observer/reactive'
6
+ import { hasOwn, isFunction, noop, isObject, isArray, getByPath, collectDataset, hump2dash, dash2hump, callWithErrorHandling, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
7
+ import MpxProxy from '../../core/proxy'
8
+ import { BEFOREUPDATE, ONLOAD, UPDATED, ONSHOW, ONHIDE, ONRESIZE, REACTHOOKSEXEC } from '../../core/innerLifecycle'
9
+ import mergeOptions from '../../core/mergeOptions'
10
+ import { queueJob, hasPendingJob } from '../../observer/scheduler'
11
11
  import { createSelectorQuery, createIntersectionObserver } from '@mpxjs/api-proxy'
12
- import { IntersectionObserverContext, RouteContext } from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/context'
12
+ import { IntersectionObserverContext, RouteContext, KeyboardAvoidContext } from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/context'
13
13
 
14
14
  function getSystemInfo () {
15
15
  const window = ReactNative.Dimensions.get('window')
@@ -27,15 +27,14 @@ function getSystemInfo () {
27
27
 
28
28
  function createEffect (proxy, components) {
29
29
  const update = proxy.update = () => {
30
- // pre render for props update
31
- if (proxy.propsUpdatedFlag) {
32
- proxy.updatePreRender()
33
- }
30
+ // react update props in child render(async), do not need exec pre render
31
+ // if (proxy.propsUpdatedFlag) {
32
+ // proxy.updatePreRender()
33
+ // }
34
34
  if (proxy.isMounted()) {
35
35
  proxy.callHook(BEFOREUPDATE)
36
36
  proxy.pendingUpdatedFlag = true
37
37
  }
38
- // eslint-disable-next-line symbol-description
39
38
  proxy.stateVersion = Symbol()
40
39
  proxy.onStoreChange && proxy.onStoreChange()
41
40
  }
@@ -49,153 +48,153 @@ function createEffect (proxy, components) {
49
48
  if (!type) return null
50
49
  return createElement(type, ...rest)
51
50
  }
51
+
52
52
  proxy.effect = new ReactiveEffect(() => {
53
53
  // reset instance
54
54
  proxy.target.__resetInstance()
55
- return proxy.target.__injectedRender(innerCreateElement, getComponent)
55
+ return callWithErrorHandling(proxy.target.__injectedRender.bind(proxy.target), proxy, 'render function', [innerCreateElement, getComponent])
56
56
  }, () => queueJob(update), proxy.scope)
57
+ // render effect允许自触发
58
+ proxy.toggleRecurse(true)
57
59
  }
58
60
 
59
- function getRootProps (props) {
61
+ function getRootProps (props, validProps) {
60
62
  const rootProps = {}
61
63
  for (const key in props) {
62
- if (hasOwn(props, key)) {
63
- const match = /^(bind|catch|capture-bind|capture-catch|style|enable-var):?(.*?)(?:\.(.*))?$/.exec(key)
64
- if (match) {
65
- rootProps[key] = props[key]
66
- }
64
+ const altKey = dash2hump(key)
65
+ if (!hasOwn(validProps, key) && !hasOwn(validProps, altKey) && key !== 'children') {
66
+ rootProps[key] = props[key]
67
67
  }
68
68
  }
69
69
  return rootProps
70
70
  }
71
71
 
72
- function createInstance ({ propsRef, type, rawOptions, currentInject, validProps, components, pageId, intersectionCtx }) {
73
- const instance = Object.create({
74
- setData (data, callback) {
75
- return this.__mpxProxy.forceUpdate(data, { sync: true }, callback)
76
- },
77
- getPageId () {
78
- return pageId
79
- },
80
- __getProps () {
81
- const props = propsRef.current
82
- const propsData = {}
83
- Object.keys(validProps).forEach((key) => {
84
- if (hasOwn(props, key)) {
85
- propsData[key] = props[key]
72
+ const instanceProto = {
73
+ setData (data, callback) {
74
+ return this.__mpxProxy.forceUpdate(data, { sync: true }, callback)
75
+ },
76
+ triggerEvent (eventName, eventDetail) {
77
+ const props = this.__props
78
+ const handler = props && (props['bind' + eventName] || props['catch' + eventName] || props['capture-bind' + eventName] || props['capture-catch' + eventName])
79
+ if (handler && typeof handler === 'function') {
80
+ const timeStamp = +new Date()
81
+ const dataset = collectDataset(props)
82
+ const id = props.id || ''
83
+ const eventObj = {
84
+ type: eventName,
85
+ timeStamp,
86
+ target: {
87
+ id,
88
+ dataset,
89
+ targetDataset: dataset
90
+ },
91
+ currentTarget: {
92
+ id,
93
+ dataset
94
+ },
95
+ detail: eventDetail
96
+ }
97
+ handler.call(this, eventObj)
98
+ }
99
+ },
100
+ getPageId () {
101
+ return this.__pageId
102
+ },
103
+ selectComponent (selector) {
104
+ return this.__selectRef(selector, 'component')
105
+ },
106
+ selectAllComponents (selector) {
107
+ return this.__selectRef(selector, 'component', true)
108
+ },
109
+ createSelectorQuery () {
110
+ return createSelectorQuery().in(this)
111
+ },
112
+ createIntersectionObserver (opt) {
113
+ return createIntersectionObserver(this, opt, this.__intersectionCtx)
114
+ },
115
+ __resetInstance () {
116
+ this.__refs = {}
117
+ this.__dispatchedSlotSet = new WeakSet()
118
+ },
119
+ __iter (val, fn) {
120
+ let i, l, keys, key
121
+ const result = []
122
+ if (isArray(val) || typeof val === 'string') {
123
+ for (i = 0, l = val.length; i < l; i++) {
124
+ result.push(fn.call(this, val[i], i))
125
+ }
126
+ } else if (typeof val === 'number') {
127
+ for (i = 0; i < val; i++) {
128
+ result.push(fn.call(this, i + 1, i))
129
+ }
130
+ } else if (isObject(val)) {
131
+ keys = Object.keys(val)
132
+ for (i = 0, l = keys.length; i < l; i++) {
133
+ key = keys[i]
134
+ result.push(fn.call(this, val[key], key, i))
135
+ }
136
+ }
137
+ return result
138
+ },
139
+ __getProps () {
140
+ const props = this.__props
141
+ const validProps = this.__validProps
142
+ const propsData = {}
143
+ Object.keys(validProps).forEach((key) => {
144
+ if (hasOwn(props, key)) {
145
+ propsData[key] = props[key]
146
+ } else {
147
+ const altKey = hump2dash(key)
148
+ if (hasOwn(props, altKey)) {
149
+ propsData[key] = props[altKey]
86
150
  } else {
87
- const altKey = hump2dash(key)
88
- if (hasOwn(props, altKey)) {
89
- propsData[key] = props[altKey]
90
- } else {
91
- let field = validProps[key]
92
- if (isFunction(field) || field === null) {
93
- field = {
94
- type: field
95
- }
151
+ let field = validProps[key]
152
+ if (isFunction(field) || field === null) {
153
+ field = {
154
+ type: field
96
155
  }
97
- // 处理props默认值
98
- propsData[key] = field.value
99
156
  }
157
+ // 处理props默认值
158
+ propsData[key] = field.value
100
159
  }
101
- })
102
- return propsData
103
- },
104
- __resetInstance () {
105
- this.__refs = {}
106
- this.__dispatchedSlotSet = new WeakSet()
107
- },
108
- __getSlot (name, slot) {
109
- const { children } = propsRef.current
110
- if (children) {
111
- let result = []
112
- if (isArray(children) && !hasOwn(children, '__slot')) {
113
- children.forEach(child => {
114
- if (isObject(child) && hasOwn(child, '__slot')) {
115
- if (child.__slot === name) result.push(...child)
116
- } else if (child?.props?.slot === name) {
117
- result.push(child)
118
- }
119
- })
120
- } else {
121
- if (isObject(children) && hasOwn(children, '__slot')) {
122
- if (children.__slot === name) result.push(...children)
123
- } else if (children?.props?.slot === name) {
124
- result.push(children)
160
+ }
161
+ })
162
+ return propsData
163
+ },
164
+ __getSlot (name, slot) {
165
+ const { children } = this.__props
166
+ if (children) {
167
+ let result = []
168
+ if (isArray(children) && !hasOwn(children, '__slot')) {
169
+ children.forEach(child => {
170
+ if (hasOwn(child, '__slot')) {
171
+ if (child.__slot === name) result.push(...child)
172
+ } else if (child?.props?.slot === name) {
173
+ result.push(child)
125
174
  }
126
- }
127
- result = result.filter(item => {
128
- if (!isObject(item) || this.__dispatchedSlotSet.has(item)) return false
129
- this.__dispatchedSlotSet.add(item)
130
- return true
131
175
  })
132
- if (!result.length) return null
133
- result.__slot = slot
134
- return result
135
- }
136
- return null
137
- },
138
- __injectedRender: currentInject.render || noop,
139
- __getRefsData: currentInject.getRefsData || noop,
140
- // render helper
141
- _i (val, fn) {
142
- let i, l, keys, key
143
- const result = []
144
- if (isArray(val) || typeof val === 'string') {
145
- for (i = 0, l = val.length; i < l; i++) {
146
- result.push(fn.call(this, val[i], i))
147
- }
148
- } else if (typeof val === 'number') {
149
- for (i = 0; i < val; i++) {
150
- result.push(fn.call(this, i + 1, i))
151
- }
152
- } else if (isObject(val)) {
153
- keys = Object.keys(val)
154
- for (i = 0, l = keys.length; i < l; i++) {
155
- key = keys[i]
156
- result.push(fn.call(this, val[key], key, i))
176
+ } else {
177
+ if (hasOwn(children, '__slot')) {
178
+ if (children.__slot === name) result.push(...children)
179
+ } else if (children?.props?.slot === name) {
180
+ result.push(children)
157
181
  }
158
182
  }
183
+ result = result.filter(item => {
184
+ if (!isObject(item) || this.__dispatchedSlotSet.has(item)) return false
185
+ this.__dispatchedSlotSet.add(item)
186
+ return true
187
+ })
188
+ if (!result.length) return null
189
+ result.__slot = slot
159
190
  return result
160
- },
161
- triggerEvent (eventName, eventDetail) {
162
- const props = propsRef.current
163
- const handler = props && (props['bind' + eventName] || props['catch' + eventName] || props['capture-bind' + eventName] || props['capture-catch' + eventName])
164
- if (handler && typeof handler === 'function') {
165
- const timeStamp = +new Date()
166
- const dataset = collectDataset(props)
167
- const id = props.id || ''
168
- const eventObj = {
169
- type: eventName,
170
- timeStamp,
171
- target: {
172
- id,
173
- dataset,
174
- targetDataset: dataset
175
- },
176
- currentTarget: {
177
- id,
178
- dataset
179
- },
180
- detail: eventDetail
181
- }
182
- handler.call(this, eventObj)
183
- }
184
- },
185
- selectComponent (selector) {
186
- return this.__selectRef(selector, 'component')
187
- },
188
- selectAllComponents (selector) {
189
- return this.__selectRef(selector, 'component', true)
190
- },
191
- createSelectorQuery () {
192
- return createSelectorQuery().in(this)
193
- },
194
- createIntersectionObserver (opt) {
195
- return createIntersectionObserver(this, opt, intersectionCtx)
196
- },
197
- ...rawOptions.methods
198
- }, {
191
+ }
192
+ return null
193
+ }
194
+ }
195
+
196
+ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps, components, pageId, intersectionCtx }) {
197
+ const instance = Object.create(instanceProto, {
199
198
  dataset: {
200
199
  get () {
201
200
  const props = propsRef.current
@@ -210,18 +209,55 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
210
209
  },
211
210
  enumerable: true
212
211
  },
213
- props: {
212
+ __props: {
214
213
  get () {
215
214
  return propsRef.current
216
215
  },
217
- enumerable: true
216
+ enumerable: false
217
+ },
218
+ __pageId: {
219
+ get () {
220
+ return pageId
221
+ },
222
+ enumerable: false
223
+ },
224
+ __intersectionCtx: {
225
+ get () {
226
+ return intersectionCtx
227
+ },
228
+ enumerable: false
229
+ },
230
+ __validProps: {
231
+ get () {
232
+ return validProps
233
+ },
234
+ enumerable: false
235
+ },
236
+ __injectedRender: {
237
+ get () {
238
+ return currentInject.render || noop
239
+ },
240
+ enumerable: false
241
+ },
242
+ __getRefsData: {
243
+ get () {
244
+ return currentInject.getRefsData || noop
245
+ },
246
+ enumerable: false
218
247
  }
219
248
  })
220
249
 
221
- const props = propsRef.current
250
+ // bind this & assign methods
251
+ if (rawOptions.methods) {
252
+ Object.entries(rawOptions.methods).forEach(([key, method]) => {
253
+ instance[key] = method.bind(instance)
254
+ })
255
+ }
222
256
 
223
257
  if (type === 'page') {
258
+ const props = propsRef.current
224
259
  instance.route = props.route.name
260
+ global.__mpxPagesMap = global.__mpxPagesMap || {}
225
261
  global.__mpxPagesMap[props.route.key] = [instance, props.navigation]
226
262
  }
227
263
 
@@ -230,12 +266,10 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
230
266
 
231
267
  Object.assign(proxy, {
232
268
  onStoreChange: null,
233
- // eslint-disable-next-line symbol-description
234
269
  stateVersion: Symbol(),
235
270
  subscribe: (onStoreChange) => {
236
271
  if (!proxy.effect) {
237
272
  createEffect(proxy, components)
238
- // eslint-disable-next-line symbol-description
239
273
  proxy.stateVersion = Symbol()
240
274
  }
241
275
  proxy.onStoreChange = onStoreChange
@@ -302,8 +336,8 @@ function usePageEffect (mpxProxy, pageId) {
302
336
  const hasHideHook = hasPageHook(mpxProxy, [ONHIDE, 'hide'])
303
337
  const hasResizeHook = hasPageHook(mpxProxy, [ONRESIZE, 'resize'])
304
338
  if (hasShowHook || hasHideHook || hasResizeHook) {
305
- if (hasOwn(pageStatusContext, pageId)) {
306
- unWatch = watch(() => pageStatusContext[pageId], (newVal) => {
339
+ if (hasOwn(pageStatusMap, pageId)) {
340
+ unWatch = watch(() => pageStatusMap[pageId], (newVal) => {
307
341
  if (newVal === 'show' || newVal === 'hide') {
308
342
  triggerPageStatusHook(mpxProxy, newVal)
309
343
  } else if (/^resize/.test(newVal)) {
@@ -318,32 +352,28 @@ function usePageEffect (mpxProxy, pageId) {
318
352
  }, [])
319
353
  }
320
354
 
321
- const pageStatusContext = reactive({})
322
355
  let pageId = 0
356
+ const pageStatusMap = global.__mpxPageStatusMap = reactive({})
323
357
 
324
358
  function usePageStatus (navigation, pageId) {
325
- let isFocused = true
326
- set(pageStatusContext, pageId, '')
359
+ navigation.pageId = pageId
360
+ set(pageStatusMap, pageId, '')
327
361
  useEffect(() => {
328
362
  const focusSubscription = navigation.addListener('focus', () => {
329
- pageStatusContext[pageId] = 'show'
330
- isFocused = true
363
+ pageStatusMap[pageId] = 'show'
331
364
  })
332
365
  const blurSubscription = navigation.addListener('blur', () => {
333
- pageStatusContext[pageId] = 'hide'
334
- isFocused = false
366
+ pageStatusMap[pageId] = 'hide'
335
367
  })
336
368
  const unWatchAppFocusedState = watch(global.__mpxAppFocusedState, (value) => {
337
- if (isFocused) {
338
- pageStatusContext[pageId] = value
339
- }
369
+ pageStatusMap[pageId] = value
340
370
  })
341
371
 
342
372
  return () => {
343
373
  focusSubscription()
344
374
  blurSubscription()
345
375
  unWatchAppFocusedState()
346
- del(pageStatusContext, pageId)
376
+ del(pageStatusMap, pageId)
347
377
  }
348
378
  }, [navigation])
349
379
  }
@@ -387,20 +417,21 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
387
417
  }
388
418
  }
389
419
 
390
- useEffect(() => {
391
- if (!isFirst) {
392
- // 处理props更新
393
- Object.keys(validProps).forEach((key) => {
394
- if (hasOwn(props, key)) {
395
- instance[key] = props[key]
396
- } else {
397
- const altKey = hump2dash(key)
398
- if (hasOwn(props, altKey)) {
399
- instance[key] = props[altKey]
400
- }
420
+ if (!isFirst) {
421
+ // 处理props更新
422
+ Object.keys(validProps).forEach((key) => {
423
+ if (hasOwn(props, key)) {
424
+ instance[key] = props[key]
425
+ } else {
426
+ const altKey = hump2dash(key)
427
+ if (hasOwn(props, altKey)) {
428
+ instance[key] = props[altKey]
401
429
  }
402
- })
403
- }
430
+ }
431
+ })
432
+ }
433
+
434
+ useEffect(() => {
404
435
  if (proxy.pendingUpdatedFlag) {
405
436
  proxy.pendingUpdatedFlag = false
406
437
  proxy.callHook(UPDATED)
@@ -428,10 +459,22 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
428
459
 
429
460
  useSyncExternalStore(proxy.subscribe, proxy.getSnapshot)
430
461
 
431
- const root = rawOptions.options?.disableMemo ? proxy.effect.run() : useMemo(() => proxy.effect.run(), [proxy.stateVersion])
432
- if (root) {
433
- const rootProps = getRootProps(props)
434
- rootProps.style = { ...root.props.style, ...rootProps.style }
462
+ if ((rawOptions.options?.disableMemo)) {
463
+ proxy.memoVersion = Symbol()
464
+ }
465
+
466
+ const finalMemoVersion = useMemo(() => {
467
+ if (!hasPendingJob(proxy.update)) {
468
+ proxy.finalMemoVersion = Symbol()
469
+ }
470
+ return proxy.finalMemoVersion
471
+ }, [proxy.stateVersion, proxy.memoVersion])
472
+
473
+ const root = useMemo(() => proxy.effect.run(), [finalMemoVersion])
474
+ if (root && root.props.ishost) {
475
+ // 对于组件未注册的属性继承到host节点上,如事件、样式和其他属性等
476
+ const rootProps = getRootProps(props, validProps)
477
+ rootProps.style = Object.assign({}, root.props.style, rootProps.style)
435
478
  // update root props
436
479
  return cloneElement(root, rootProps)
437
480
  }
@@ -446,6 +489,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
446
489
  const { Provider, useSafeAreaInsets, GestureHandlerRootView } = global.__navigationHelper
447
490
  const pageConfig = Object.assign({}, global.__mpxPageConfig, currentInject.pageConfig)
448
491
  const Page = ({ navigation, route }) => {
492
+ const [enabled, setEnabled] = useState(true)
449
493
  const currentPageId = useMemo(() => ++pageId, [])
450
494
  const intersectionObservers = useRef({})
451
495
  usePageStatus(navigation, currentPageId)
@@ -475,6 +519,30 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
475
519
  })
476
520
  }, [])
477
521
 
522
+ const withKeyboardAvoidingView = (element) => {
523
+ if (__mpx_mode__ === 'ios') {
524
+ return createElement(KeyboardAvoidContext.Provider,
525
+ {
526
+ value: setEnabled
527
+ },
528
+ createElement(ReactNative.KeyboardAvoidingView,
529
+ {
530
+ style: {
531
+ flex: 1
532
+ },
533
+ contentContainerStyle: {
534
+ flex: 1
535
+ },
536
+ behavior: 'position',
537
+ enabled
538
+ },
539
+ element
540
+ )
541
+ )
542
+ }
543
+ return element
544
+ }
545
+
478
546
  navigation.insets = useSafeAreaInsets()
479
547
 
480
548
  return createElement(GestureHandlerRootView,
@@ -483,16 +551,16 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
483
551
  flex: 1
484
552
  }
485
553
  },
486
- createElement(ReactNative.View, {
487
- style: {
488
- flex: 1,
489
- backgroundColor: pageConfig.backgroundColor || '#ffffff'
490
- },
491
- ref: rootRef,
492
- onLayout
493
- },
494
- createElement(Provider,
495
- null,
554
+ withKeyboardAvoidingView(
555
+ createElement(ReactNative.View,
556
+ {
557
+ style: {
558
+ flex: 1,
559
+ backgroundColor: pageConfig.backgroundColor || '#ffffff'
560
+ },
561
+ ref: rootRef,
562
+ onLayout
563
+ },
496
564
  createElement(RouteContext.Provider,
497
565
  {
498
566
  value: currentPageId
@@ -501,19 +569,22 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
501
569
  {
502
570
  value: intersectionObservers.current
503
571
  },
504
- createElement(defaultOptions,
505
- {
506
- navigation,
507
- route,
508
- id: currentPageId
509
- }
572
+ createElement(Provider,
573
+ null,
574
+ createElement(defaultOptions,
575
+ {
576
+ navigation,
577
+ route,
578
+ id: currentPageId
579
+ }
580
+ )
510
581
  )
511
582
  )
512
583
  )
513
584
  )
514
585
  )
515
- // todo custom portal host for active route
516
586
  )
587
+ // todo custom portal host for active route
517
588
  }
518
589
  return Page
519
590
  }
@@ -1,7 +1,7 @@
1
1
  import { hasOwn, noop, isFunction, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
2
- import MpxProxy from '../../../core/proxy'
3
- import builtInKeysMap from '../builtInKeysMap'
4
- import mergeOptions from '../../../core/mergeOptions'
2
+ import MpxProxy from '../../core/proxy'
3
+ import builtInKeysMap from './builtInKeysMap'
4
+ import mergeOptions from '../../core/mergeOptions'
5
5
 
6
6
  function transformProperties (properties) {
7
7
  if (!properties) {
@@ -126,7 +126,7 @@ function transformApiForProxy (context, currentInject) {
126
126
  }
127
127
  }
128
128
 
129
- export function filterOptions (options) {
129
+ function filterOptions (options) {
130
130
  const newOptions = {}
131
131
  Object.keys(options).forEach(key => {
132
132
  if (builtInKeysMap[key]) {
@@ -155,7 +155,7 @@ export function filterOptions (options) {
155
155
  return newOptions
156
156
  }
157
157
 
158
- export function initProxy (context, rawOptions, currentInject) {
158
+ function initProxy (context, rawOptions, currentInject) {
159
159
  if (!context.__mpxProxy) {
160
160
  // 提供代理对象需要的api
161
161
  transformApiForProxy(context, currentInject)
@@ -185,6 +185,12 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
185
185
  if (this.__mpxProxy) this.__mpxProxy.unmounted()
186
186
  }
187
187
  }]
188
+ // 百度环境如构造页面,优先使用onInit进行初始化
189
+ if (__mpx_mode__ === 'swan' && type === 'page') {
190
+ rootMixins[0].onInit = function (...params) {
191
+ initProxy(this, rawOptions, currentInject, params)
192
+ }
193
+ }
188
194
  rawOptions.mixins = rawOptions.mixins ? rootMixins.concat(rawOptions.mixins) : rootMixins
189
195
  rawOptions = mergeOptions(rawOptions, type, false)
190
196
  return filterOptions(rawOptions)
@@ -1,8 +1,8 @@
1
- import builtInKeysMap from '../builtInKeysMap'
2
- import mergeOptions from '../../../core/mergeOptions'
1
+ import builtInKeysMap from './builtInKeysMap'
2
+ import mergeOptions from '../../core/mergeOptions'
3
3
  import { diffAndCloneA, hasOwn, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
4
- import { getCurrentInstance as getCurrentVueInstance } from '../../export/index'
5
- import MpxProxy, { setCurrentInstance, unsetCurrentInstance } from '../../../core/proxy'
4
+ import { getCurrentInstance as getCurrentVueInstance } from '../export/index'
5
+ import MpxProxy, { setCurrentInstance, unsetCurrentInstance } from '../../core/proxy'
6
6
  import {
7
7
  BEFORECREATE,
8
8
  BEFOREUPDATE,
@@ -10,7 +10,7 @@ import {
10
10
  BEFOREUNMOUNT,
11
11
  UNMOUNTED,
12
12
  SERVERPREFETCH
13
- } from '../../../core/innerLifecycle'
13
+ } from '../../core/innerLifecycle'
14
14
 
15
15
  function filterOptions (options) {
16
16
  const newOptions = {}