@mpxjs/core 2.9.59 → 2.9.62

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
@@ -34,17 +34,17 @@ type Data = object | (() => object)
34
34
  export type PropType<T> = {
35
35
  __type: T
36
36
  } & (
37
- T extends String
37
+ T extends String
38
38
  ? StringConstructor
39
39
  : T extends number
40
- ? NumberConstructor
41
- : T extends boolean
42
- ? BooleanConstructor
43
- : T extends any[]
44
- ? ArrayConstructor
45
- : T extends object
46
- ? ObjectConstructor
47
- : never
40
+ ? NumberConstructor
41
+ : T extends boolean
42
+ ? BooleanConstructor
43
+ : T extends any[]
44
+ ? ArrayConstructor
45
+ : T extends object
46
+ ? ObjectConstructor
47
+ : never
48
48
  )
49
49
 
50
50
  type FullPropType<T> = {
@@ -85,10 +85,10 @@ type GetDataType<T> = T extends () => any ? ReturnType<T> : T
85
85
 
86
86
  type GetPropsType<T extends Properties> = {
87
87
  readonly [K in keyof T]: T[K] extends FullPropType<infer V>
88
- ? V
89
- : T[K] extends PropType<infer V>
90
- ? V
91
- : WechatMiniprogram.Component.PropertyToData<T[K]>
88
+ ? V
89
+ : T[K] extends PropType<infer V>
90
+ ? V
91
+ : WechatMiniprogram.Component.PropertyToData<T[K]>
92
92
  }
93
93
 
94
94
  type RequiredPropertyNames<T> = {
@@ -246,7 +246,7 @@ export function injectMixins (mixins: object | Array<object>, options?: MixinTyp
246
246
  // export function watch (expr: string | (() => any), handler: WatchHandler | WatchOptWithHandler, options?: WatchOpt): () => void
247
247
 
248
248
  interface AnyConstructor {
249
- new (...args: any[]): any
249
+ new(...args: any[]): any
250
250
 
251
251
  prototype: any
252
252
  }
@@ -266,6 +266,7 @@ interface MpxConfig {
266
266
  setDataHandler: (data: object, target: ComponentIns<{}, {}, {}, {}, []>) => any | null
267
267
  forceFlushSync: boolean,
268
268
  webRouteConfig: object,
269
+ webConfig: object,
269
270
  webviewConfig?: WebviewConfig
270
271
  }
271
272
 
@@ -285,9 +286,9 @@ export type Plugin = PluginInstallFunction | {
285
286
  install: PluginInstallFunction
286
287
  }
287
288
 
288
- export type PluginFunction<T extends Plugin> = T extends PluginInstallFunction ? T : T extends { install: infer U } ? U : never;
289
+ export type PluginFunction<T extends Plugin> = T extends PluginInstallFunction ? T : T extends { install: infer U } ? U : never
289
290
 
290
- export type PluginFunctionParams<T extends PluginInstallFunction> = T extends (app: any, ...args: infer P) => any ? P : [];
291
+ export type PluginFunctionParams<T extends PluginInstallFunction> = T extends (app: any, ...args: infer P) => any ? P : []
291
292
 
292
293
  export interface Mpx {
293
294
  getMixin: typeof getMixin
@@ -297,7 +298,7 @@ export interface Mpx {
297
298
  observable: typeof observable
298
299
  watch: typeof watch
299
300
 
300
- use <T extends Plugin = Plugin>(plugin: T, ...rest: PluginFunctionParams<PluginFunction<T>>): Mpx
301
+ use<T extends Plugin = Plugin> (plugin: T, ...rest: PluginFunctionParams<PluginFunction<T>>): Mpx
301
302
 
302
303
  implement (name: string, options?: ImplementOptions): void
303
304
 
@@ -376,8 +377,8 @@ export interface RefUnwrapBailTypes {
376
377
  export type UnwrapRef<T> = T extends ShallowRef<infer V>
377
378
  ? V
378
379
  : T extends Ref<infer V>
379
- ? UnwrapRefSimple<V>
380
- : UnwrapRefSimple<T>
380
+ ? UnwrapRefSimple<V>
381
+ : UnwrapRefSimple<T>
381
382
 
382
383
  export type UnwrapRefSimple<T> = T extends | Function
383
384
  | CollectionTypes
@@ -386,10 +387,10 @@ export type UnwrapRefSimple<T> = T extends | Function
386
387
  | RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
387
388
  ? T
388
389
  : T extends Array<any>
389
- ? { [K in keyof T]: UnwrapRefSimple<T[K]> }
390
- : T extends object & { [ShallowReactiveMarker]?: never } // not a shallowReactive
391
- ? { [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]> }
392
- : T
390
+ ? { [K in keyof T]: UnwrapRefSimple<T[K]> }
391
+ : T extends object & { [ShallowReactiveMarker]?: never } // not a shallowReactive
392
+ ? { [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]> }
393
+ : T
393
394
 
394
395
  // If the the type T accepts type "any", output type Y, otherwise output type N.
395
396
  // https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
@@ -572,13 +573,9 @@ export function watch<T extends Reactive<object>> ( // for reactive value
572
573
  ): () => void
573
574
 
574
575
  export function effectScope (detached?: boolean): EffectScope
575
-
576
576
  export function getCurrentScope (): EffectScope | undefined
577
-
578
577
  export function onScopeDispose (fn: () => void): void
579
-
580
578
  export function set<T extends object> (target: T, key: string | number, value: any): void
581
-
582
579
  export function del<T extends object> (target: T, key: keyof T): void
583
580
 
584
581
  // nextTick
@@ -586,43 +583,25 @@ export function nextTick (fn: () => any): void
586
583
 
587
584
  // lifecycle
588
585
  export function onBeforeMount (callback: () => void): void
589
-
590
586
  export function onMounted (callback: () => void): void
591
-
592
587
  export function onBeforeUpdate (callback: () => void): void
593
-
594
588
  export function onUpdated (callback: () => void): void
595
-
596
589
  export function onBeforeUnmount (callback: () => void): void
597
-
598
590
  export function onUnmounted (callback: () => void): void
599
-
600
591
  export function onLoad<T extends Record<string, string | undefined>> (callback: (query: T) => void): void
601
-
602
- // wechat dose not have generics
603
- // export function onLoad (callback: WechatMiniprogram.Page.ILifetime['onLoad']): void
604
-
605
592
  export function onShow (callback: WechatMiniprogram.Page.ILifetime['onShow']): void
606
-
607
593
  export function onHide (callback: WechatMiniprogram.Page.ILifetime['onHide']): void
608
-
609
594
  export function onResize (callback: WechatMiniprogram.Page.ILifetime['onResize']): void
610
-
611
595
  export function onPullDownRefresh (callback: WechatMiniprogram.Page.ILifetime['onPullDownRefresh']): void
612
-
613
596
  export function onReachBottom (callback: WechatMiniprogram.Page.ILifetime['onReachBottom']): void
614
-
615
597
  export function onShareAppMessage (callback: WechatMiniprogram.Page.ILifetime['onShareAppMessage']): void
616
-
617
598
  export function onShareTimeline (callback: WechatMiniprogram.Page.ILifetime['onShareTimeline']): void
618
-
619
599
  export function onAddToFavorites (callback: WechatMiniprogram.Page.ILifetime['onAddToFavorites']): void
620
-
621
600
  export function onPageScroll (callback: WechatMiniprogram.Page.ILifetime['onPageScroll']): void
622
-
623
601
  export function onTabItemTap (callback: WechatMiniprogram.Page.ILifetime['onTabItemTap']): void
624
-
625
602
  export function onSaveExitState (callback: () => void): void
603
+ export function onServerPrefetch (callback: () => any): void
604
+ export function onReactHooksExec (callback: () => void): void
626
605
 
627
606
  // get instance
628
607
  export function getCurrentInstance<T extends ComponentIns<{}, {}, {}>> (): { proxy: T, [x: string]: any }
@@ -672,6 +651,8 @@ export const ONLOAD: string
672
651
  export const ONSHOW: string
673
652
  export const ONHIDE: string
674
653
  export const ONRESIZE: string
654
+ export const SERVERPREFETCH: string
655
+ export const REACTHOOKSEXEC: string
675
656
 
676
657
  declare global {
677
658
  const defineProps: (<T extends Properties = {}>(props: T) => Readonly<GetPropsType<T>>) & (<T>() => Readonly<T>)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.9.59",
3
+ "version": "2.9.62",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -31,7 +31,9 @@
31
31
  "@react-navigation/native-stack": "^6.9.26",
32
32
  "react": "*",
33
33
  "react-native": "*",
34
+ "react-native-gesture-handler": "^2.19.0",
34
35
  "react-native-safe-area-context": "^4.10.1",
36
+ "react-native-webview": "^13.10.5",
35
37
  "vue": "^2.7.10",
36
38
  "vue-demi": "^0.14.6",
37
39
  "vue-i18n": "^8.27.2",
@@ -67,6 +69,12 @@
67
69
  },
68
70
  "react-native-safe-area-context": {
69
71
  "optional": true
72
+ },
73
+ "react-native-webview": {
74
+ "optional": true
75
+ },
76
+ "react-native-gesture-handler": {
77
+ "optional": true
70
78
  }
71
79
  },
72
80
  "publishConfig": {
@@ -85,5 +93,5 @@
85
93
  "url": "https://github.com/didi/mpx/issues"
86
94
  },
87
95
  "sideEffects": false,
88
- "gitHead": "aa001c11cc7b21772fc6f9f5bcdd13118fc6d67c"
96
+ "gitHead": "c31a343e7ef2c1c1585002752d8c50f016a858ae"
89
97
  }
@@ -5,7 +5,7 @@ import {
5
5
  import { implemented } from '../core/implement'
6
6
 
7
7
  // 暂不支持的wx选项,后期需要各种花式支持
8
- const unsupported = ['relations', 'moved', 'definitionFilter', 'onShareAppMessage', 'options', 'behaviors', 'externalClasses']
8
+ const unsupported = ['relations', 'moved', 'definitionFilter', 'onShareAppMessage', 'options']
9
9
 
10
10
  function convertErrorDesc (key) {
11
11
  error(`Options.${key} is not supported in runtime conversion from wx to react native.`, global.currentResource)
@@ -11,6 +11,7 @@ export const ONSHOW = '__onShow__'
11
11
  export const ONHIDE = '__onHide__'
12
12
  export const ONRESIZE = '__onResize__'
13
13
  export const SERVERPREFETCH = '__serverPrefetch__'
14
+ export const REACTHOOKSEXEC = '__reactHooksExec__'
14
15
 
15
16
  export const INNER_LIFECYCLES = [
16
17
  BEFORECREATE,
@@ -21,6 +22,7 @@ export const INNER_LIFECYCLES = [
21
22
  UPDATED,
22
23
  BEFOREUNMOUNT,
23
24
  SERVERPREFETCH,
25
+ REACTHOOKSEXEC,
24
26
  UNMOUNTED,
25
27
  ONLOAD,
26
28
  ONSHOW,
@@ -354,7 +354,7 @@ function transformHOOKS (options) {
354
354
  const componentHooksMap = makeMap(convertRule.lifecycle.component)
355
355
  for (const key in options) {
356
356
  // 使用Component创建page实例,页面专属生命周期&自定义方法需写在methods内部
357
- if (typeof options[key] === 'function' && key !== 'dataFn' && key !== 'setup' && key !== 'serverPrefetch' && !componentHooksMap[key]) {
357
+ if (typeof options[key] === 'function' && key !== 'dataFn' && key !== 'setup' && !componentHooksMap[key]) {
358
358
  if (!options.methods) options.methods = {}
359
359
  options.methods[key] = options[key]
360
360
  delete options[key]
package/src/core/proxy.js CHANGED
@@ -42,7 +42,8 @@ import {
42
42
  ONLOAD,
43
43
  ONSHOW,
44
44
  ONHIDE,
45
- ONRESIZE
45
+ ONRESIZE,
46
+ REACTHOOKSEXEC
46
47
  } from './innerLifecycle'
47
48
  import contextMap from '../dynamic/vnode/context'
48
49
  import { getAst } from '../dynamic/astCache'
@@ -498,11 +499,28 @@ export default class MpxProxy {
498
499
  return result
499
500
  }
500
501
 
501
- doRenderWithVNode (vnode) {
502
+ doRenderWithVNode (vnode, cb) {
503
+ const renderTask = this.createRenderTask()
504
+ let callback = cb
505
+ // mounted之后才会触发BEFOREUPDATE/UPDATED
506
+ if (this.isMounted()) {
507
+ this.callHook(BEFOREUPDATE)
508
+ callback = () => {
509
+ cb && cb()
510
+ this.callHook(UPDATED)
511
+ renderTask && renderTask.resolve()
512
+ }
513
+ }
502
514
  if (!this._vnode) {
503
- this.target.__render({ r: vnode })
515
+ this._vnode = diffAndCloneA(vnode).clone
516
+ pauseTracking()
517
+ // 触发渲染时暂停数据响应追踪,避免误收集到子组件的数据依赖
518
+ this.target.__render({ r: vnode }, callback)
519
+ resetTracking()
504
520
  } else {
505
- let diffPath = diffAndCloneA(vnode, this._vnode).diffData
521
+ const result = diffAndCloneA(vnode, this._vnode)
522
+ this._vnode = result.clone
523
+ let diffPath = result.diffData
506
524
  if (!isEmptyObject(diffPath)) {
507
525
  // 构造 diffPath 数据
508
526
  diffPath = Object.keys(diffPath).reduce((preVal, curVal) => {
@@ -510,11 +528,11 @@ export default class MpxProxy {
510
528
  preVal[key] = diffPath[curVal]
511
529
  return preVal
512
530
  }, {})
513
- this.target.__render(diffPath)
531
+ pauseTracking()
532
+ this.target.__render(diffPath, callback)
533
+ resetTracking()
514
534
  }
515
535
  }
516
- // 缓存本地的 vnode 用以下一次 diff
517
- this._vnode = diffAndCloneA(vnode).clone
518
536
  }
519
537
 
520
538
  doRender (data, cb) {
@@ -734,6 +752,7 @@ export const onShow = createHook(ONSHOW)
734
752
  export const onHide = createHook(ONHIDE)
735
753
  export const onResize = createHook(ONRESIZE)
736
754
  export const onServerPrefetch = createHook(SERVERPREFETCH)
755
+ export const onReactHooksExec = createHook(REACTHOOKSEXEC)
737
756
  export const onPullDownRefresh = createHook('__onPullDownRefresh__')
738
757
  export const onReachBottom = createHook('__onReachBottom__')
739
758
  export const onShareAppMessage = createHook('__onShareAppMessage__')
package/src/index.js CHANGED
@@ -29,11 +29,12 @@ export {
29
29
  UPDATED,
30
30
  BEFOREUNMOUNT,
31
31
  UNMOUNTED,
32
- SERVERPREFETCH,
33
32
  ONLOAD,
34
33
  ONSHOW,
35
34
  ONHIDE,
36
- ONRESIZE
35
+ ONRESIZE,
36
+ SERVERPREFETCH,
37
+ REACTHOOKSEXEC
37
38
  } from './core/innerLifecycle'
38
39
 
39
40
  export {
@@ -43,7 +44,6 @@ export {
43
44
  onUpdated,
44
45
  onBeforeUnmount,
45
46
  onUnmounted,
46
- onServerPrefetch,
47
47
  onLoad,
48
48
  onShow,
49
49
  onHide,
@@ -55,7 +55,9 @@ export {
55
55
  onAddToFavorites,
56
56
  onPageScroll,
57
57
  onTabItemTap,
58
- onSaveExitState
58
+ onSaveExitState,
59
+ onServerPrefetch,
60
+ onReactHooksExec
59
61
  } from './core/proxy'
60
62
 
61
63
  export { getMixin } from './core/mergeOptions'
@@ -140,15 +142,16 @@ Mpx.config = {
140
142
  setDataHandler: null,
141
143
  forceFlushSync: false,
142
144
  webRouteConfig: {},
145
+ webConfig: {},
143
146
  /*
144
147
  支持两个属性
145
148
  hostWhitelists Array 类型 支持h5域名白名单安全校验
146
149
  apiImplementations webview JSSDK接口 例如getlocation
147
150
  */
148
151
  webviewConfig: {},
149
- /**
150
- * react-native 相关配置,用于挂载事件等,如 onShareAppMessage
151
- */
152
+ /**
153
+ * react-native 相关配置,用于挂载事件等,如 onShareAppMessage
154
+ */
152
155
  rnConfig: {}
153
156
  }
154
157
 
@@ -1,14 +1,8 @@
1
- import { warn, type } from '@mpxjs/utils'
2
1
  export default function directiveHelperMixin () {
3
2
  return {
4
3
  methods: {
5
4
  __getWxKey (item, key) {
6
- const value = key === '*this' ? item : item[key]
7
- if (typeof value === 'string' || typeof value === 'number') {
8
- return value
9
- } else {
10
- warn(`wx:key's value should return a string or a number, received: ${type(value)}`, this.__mpxProxy.options.mpxFileResource)
11
- }
5
+ return key === '*this' ? item : item[key]
12
6
  }
13
7
  }
14
8
  }
@@ -57,13 +57,15 @@ export default function getRefsMixin () {
57
57
  })
58
58
  },
59
59
  __getRefVal (key) {
60
- if (!this.__refs[key]) {
61
- this.__refs[key] = []
60
+ return (instance) => {
61
+ if (instance) {
62
+ this.__refs[key] = this.__refs[key] || []
63
+ this.__refs[key].push(instance)
64
+ }
62
65
  }
63
- return (instance) => instance && this.__refs[key].push(instance)
64
66
  },
65
67
  __selectRef (selector, refType, all = false) {
66
- const splitedSelector = selector.match(/(#|\.)?\w+/g) || []
68
+ const splitedSelector = selector.match(/(#|\.)?[^.#]+/g) || []
67
69
  const refsArr = splitedSelector.map(selector => {
68
70
  const selectorMap = this.__selectorMap?.value[selector] || []
69
71
  const res = []
@@ -1,8 +1,8 @@
1
1
  import { isObject, isArray, dash2hump, isFunction } from '@mpxjs/utils'
2
2
  import { Dimensions } from 'react-native'
3
3
 
4
- function concat (a, b) {
5
- return a ? b ? (a + ' ' + b) : a : (b || '')
4
+ function concat (a = '', b = '') {
5
+ return a ? b ? (a + ' ' + b) : a : b
6
6
  }
7
7
 
8
8
  function stringifyArray (value) {
@@ -44,7 +44,7 @@ const propertyDelimiter = /:(.+)/
44
44
  const rpxRegExp = /^\s*(-?\d+(\.\d+)?)rpx\s*$/
45
45
  const pxRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/
46
46
 
47
- function parseStyleText (cssText) {
47
+ function parseStyleText (cssText = '') {
48
48
  const res = {}
49
49
  const arr = cssText.split(listDelimiter)
50
50
  for (let i = 0; i < arr.length; i++) {
@@ -111,7 +111,7 @@ export default function styleHelperMixin (type) {
111
111
  },
112
112
  __getStyle (staticClass, dynamicClass, staticStyle, dynamicStyle, show) {
113
113
  // todo 每次返回新对象会导致react memo优化失效,需要考虑优化手段
114
- const result = []
114
+ const result = {}
115
115
  const classMap = {}
116
116
  if (type === 'page' && isFunction(global.__getAppClassMap)) {
117
117
  Object.assign(classMap, global.__getAppClassMap.call(this))
@@ -123,21 +123,21 @@ export default function styleHelperMixin (type) {
123
123
  const classString = concat(staticClass, stringifyDynamicClass(dynamicClass))
124
124
  classString.split(/\s+/).forEach((className) => {
125
125
  if (classMap[className]) {
126
- result.push(classMap[className])
127
- } else if (this.props[className]) {
128
- // externalClasses必定以数组形式传递下来
129
- result.push(...this.props[className])
126
+ Object.assign(result, classMap[className])
127
+ } else if (this.props[className] && isObject(this.props[className])) {
128
+ // externalClasses必定以对象形式传递下来
129
+ Object.assign(result, this.props[className])
130
130
  }
131
131
  })
132
132
  }
133
133
 
134
134
  if (staticStyle || dynamicStyle) {
135
135
  const styleObj = Object.assign(parseStyleText(staticStyle), normalizeDynamicStyle(dynamicStyle))
136
- result.push(transformStyleObj(this, styleObj))
136
+ Object.assign(result, transformStyleObj(this, styleObj))
137
137
  }
138
138
 
139
139
  if (show === false) {
140
- result.push({
140
+ Object.assign(result, {
141
141
  display: 'none'
142
142
  })
143
143
  }
@@ -133,7 +133,7 @@ export default function createApp (option, config = {}) {
133
133
  global.__mpxAppFocusedState.value = `resize${count++}`
134
134
  })
135
135
  return () => {
136
- changeSubscription()
136
+ changeSubscription && changeSubscription.remove()
137
137
  resizeSubScription && resizeSubScription.remove()
138
138
  }
139
139
  }, [])
@@ -5,7 +5,7 @@ import { watch } from '../../../observer/watch'
5
5
  import { reactive, set, del } from '../../../observer/reactive'
6
6
  import { hasOwn, isFunction, noop, isObject, error, getByPath, collectDataset } from '@mpxjs/utils'
7
7
  import MpxProxy from '../../../core/proxy'
8
- import { BEFOREUPDATE, ONLOAD, UPDATED, ONSHOW, ONHIDE, ONRESIZE } from '../../../core/innerLifecycle'
8
+ import { BEFOREUPDATE, ONLOAD, UPDATED, ONSHOW, ONHIDE, ONRESIZE, REACTHOOKSEXEC } from '../../../core/innerLifecycle'
9
9
  import mergeOptions from '../../../core/mergeOptions'
10
10
  import { queueJob } from '../../../observer/scheduler'
11
11
  import { createSelectorQuery } from '@mpxjs/api-proxy'
@@ -24,20 +24,7 @@ function getSystemInfo () {
24
24
  }
25
25
  }
26
26
 
27
- function getRootProps (props) {
28
- const rootProps = {}
29
- for (const key in props) {
30
- if (hasOwn(props, key)) {
31
- const match = /^(bind|catch|capture-bind|capture-catch|style):?(.*?)(?:\.(.*))?$/.exec(key)
32
- if (match) {
33
- rootProps[key] = props[key]
34
- }
35
- }
36
- }
37
- return rootProps
38
- }
39
-
40
- function createEffect (proxy, components, props) {
27
+ function createEffect (proxy, components) {
41
28
  const update = proxy.update = () => {
42
29
  // pre render for props update
43
30
  if (proxy.propsUpdatedFlag) {
@@ -57,7 +44,9 @@ function createEffect (proxy, components, props) {
57
44
  return components[tagName] || getByPath(ReactNative, tagName)
58
45
  }
59
46
  proxy.effect = new ReactiveEffect(() => {
60
- return proxy.target.__injectedRender(createElement, getComponent, getRootProps(props))
47
+ // reset instance
48
+ proxy.target.__resetInstance()
49
+ return proxy.target.__injectedRender(createElement, getComponent, proxy.target.__getRootProps())
61
50
  }, () => queueJob(update), proxy.scope)
62
51
  }
63
52
 
@@ -67,8 +56,8 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
67
56
  return this.__mpxProxy.forceUpdate(data, { sync: true }, callback)
68
57
  },
69
58
  __getProps () {
70
- const propsData = {}
71
59
  const props = propsRef.current
60
+ const propsData = {}
72
61
  Object.keys(validProps).forEach((key) => {
73
62
  if (hasOwn(props, key)) {
74
63
  propsData[key] = props[key]
@@ -85,6 +74,23 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
85
74
  })
86
75
  return propsData
87
76
  },
77
+ __getRootProps () {
78
+ const props = propsRef.current
79
+ const rootProps = {}
80
+ for (const key in props) {
81
+ if (hasOwn(props, key)) {
82
+ const match = /^(bind|catch|capture-bind|capture-catch|style):?(.*?)(?:\.(.*))?$/.exec(key)
83
+ if (match) {
84
+ rootProps[key] = props[key]
85
+ }
86
+ }
87
+ }
88
+ return rootProps
89
+ },
90
+ __resetInstance () {
91
+ this.__refs = {}
92
+ this.__dispatchedSlotSet = new WeakSet()
93
+ },
88
94
  __getSlot (name) {
89
95
  const { children } = propsRef.current
90
96
  if (children) {
@@ -204,17 +210,13 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
204
210
  const proxy = instance.__mpxProxy = new MpxProxy(rawOptions, instance)
205
211
  proxy.created()
206
212
 
207
- if (type === 'page') {
208
- proxy.callHook(ONLOAD, [props.route.params || {}])
209
- }
210
-
211
213
  Object.assign(proxy, {
212
214
  onStoreChange: null,
213
215
  // eslint-disable-next-line symbol-description
214
216
  stateVersion: Symbol(),
215
217
  subscribe: (onStoreChange) => {
216
218
  if (!proxy.effect) {
217
- createEffect(proxy, components, propsRef.current)
219
+ createEffect(proxy, components)
218
220
  // eslint-disable-next-line symbol-description
219
221
  proxy.stateVersion = Symbol()
220
222
  }
@@ -231,7 +233,7 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
231
233
  })
232
234
  // react数据响应组件更新管理器
233
235
  if (!proxy.effect) {
234
- createEffect(proxy, components, propsRef.current)
236
+ createEffect(proxy, components)
235
237
  }
236
238
 
237
239
  return instance
@@ -343,42 +345,43 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
343
345
  const validProps = Object.assign({}, rawOptions.props, rawOptions.properties)
344
346
  const defaultOptions = memo(forwardRef((props, ref) => {
345
347
  const instanceRef = useRef(null)
346
- const propsRef = useRef(props)
348
+ const propsRef = useRef(null)
349
+ propsRef.current = props
347
350
  let isFirst = false
348
351
  if (!instanceRef.current) {
349
352
  isFirst = true
350
353
  instanceRef.current = createInstance({ propsRef, type, rawOptions, currentInject, validProps, components })
351
354
  }
352
355
  const instance = instanceRef.current
353
- // reset instance
354
- instance.__refs = {}
355
- instance.__dispatchedSlotSet = new WeakSet()
356
356
  useImperativeHandle(ref, () => {
357
357
  return instance
358
358
  })
359
- const proxy = instance.__mpxProxy
360
359
 
361
- if (!isFirst) {
362
- // 处理props更新
363
- propsRef.current = props
364
- Object.keys(props).forEach(key => {
365
- if (hasOwn(validProps, key)) {
366
- instance[key] = props[key]
367
- }
368
- })
369
- proxy.propsUpdated()
370
- }
360
+ const proxy = instance.__mpxProxy
371
361
 
372
- usePageContext(proxy, instance)
362
+ proxy.callHook(REACTHOOKSEXEC)
373
363
 
374
364
  useEffect(() => {
365
+ if (!isFirst) {
366
+ // 处理props更新
367
+ Object.keys(props).forEach(key => {
368
+ if (hasOwn(validProps, key)) {
369
+ instance[key] = props[key]
370
+ }
371
+ })
372
+ }
375
373
  if (proxy.pendingUpdatedFlag) {
376
374
  proxy.pendingUpdatedFlag = false
377
375
  proxy.callHook(UPDATED)
378
376
  }
379
377
  })
380
378
 
379
+ usePageContext(proxy, instance)
380
+
381
381
  useEffect(() => {
382
+ if (type === 'page') {
383
+ proxy.callHook(ONLOAD, [props.route.params || {}])
384
+ }
382
385
  proxy.mounted()
383
386
  return () => {
384
387
  proxy.unmounted()
@@ -390,11 +393,11 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
390
393
 
391
394
  useSyncExternalStore(proxy.subscribe, proxy.getSnapshot)
392
395
 
393
- return proxy.effect.run()
396
+ return rawOptions.__disableMemo ? proxy.effect.run() : useMemo(() => proxy.effect.run(), [proxy.stateVersion])
394
397
  }))
395
398
 
396
399
  if (type === 'page') {
397
- const { Provider, useSafeAreaInsets } = global.__navigationHelper
400
+ const { Provider, useSafeAreaInsets, GestureHandlerRootView } = global.__navigationHelper
398
401
  const pageConfig = Object.assign({}, global.__mpxPageConfig, currentInject.pageConfig)
399
402
  const Page = ({ navigation, route }) => {
400
403
  const currentPageId = useMemo(() => ++pageId, [])
@@ -411,20 +414,18 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
411
414
  })
412
415
  }, [])
413
416
 
414
- const insets = useSafeAreaInsets()
415
- const safeAreaPadding = {
416
- paddingTop: insets.top,
417
- paddingLeft: insets.left
418
- }
417
+ navigation.insets = useSafeAreaInsets()
419
418
 
420
419
  return createElement(Provider,
421
420
  null,
422
- createElement(ReactNative.View,
421
+ createElement(GestureHandlerRootView,
423
422
  {
424
423
  style: {
425
- ...pageConfig.navigationStyle === 'custom' && safeAreaPadding,
426
- ...ReactNative.StyleSheet.absoluteFillObject,
424
+ flex: 1,
427
425
  backgroundColor: pageConfig.backgroundColor || '#ffffff'
426
+ },
427
+ onLayout (e) {
428
+ navigation.layout = e.nativeEvent.layout
428
429
  }
429
430
  },
430
431
  createElement(routeContext.Provider,
@@ -5,7 +5,9 @@ import {
5
5
  ONSHOW,
6
6
  ONHIDE,
7
7
  ONLOAD,
8
- ONRESIZE
8
+ ONRESIZE,
9
+ SERVERPREFETCH,
10
+ REACTHOOKSEXEC
9
11
  } from '../../../core/innerLifecycle'
10
12
 
11
13
  const APP_HOOKS = [
@@ -16,6 +18,7 @@ const APP_HOOKS = [
16
18
  'onPageNotFound',
17
19
  'onUnhandledRejection',
18
20
  'onThemeChange',
21
+ 'onSSRAppCreated',
19
22
  'onAppInit'
20
23
  ]
21
24
 
@@ -43,7 +46,9 @@ const COMPONENT_HOOKS = [
43
46
  'moved',
44
47
  'detached',
45
48
  'pageShow',
46
- 'pageHide'
49
+ 'pageHide',
50
+ 'serverPrefetch',
51
+ 'reactHooksExec'
47
52
  ]
48
53
 
49
54
  export const lifecycleProxyMap = {
@@ -54,7 +59,9 @@ export const lifecycleProxyMap = {
54
59
  [ONSHOW]: ['pageShow', 'onShow'],
55
60
  [ONHIDE]: ['pageHide', 'onHide'],
56
61
  [ONLOAD]: ['onLoad'],
57
- [ONRESIZE]: ['onResize']
62
+ [ONRESIZE]: ['onResize'],
63
+ [SERVERPREFETCH]: ['serverPrefetch'],
64
+ [REACTHOOKSEXEC]: ['reactHooksExec']
58
65
  }
59
66
 
60
67
  export const LIFECYCLE = {