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