@mpxjs/core 2.9.58 → 2.9.59
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.59",
|
|
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.9.
|
|
22
|
+
"@mpxjs/utils": "^2.9.59",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
24
|
"miniprogram-api-typings": "^3.10.0"
|
|
25
25
|
},
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@react-navigation/native-stack": "^6.9.26",
|
|
32
32
|
"react": "*",
|
|
33
33
|
"react-native": "*",
|
|
34
|
+
"react-native-safe-area-context": "^4.10.1",
|
|
34
35
|
"vue": "^2.7.10",
|
|
35
36
|
"vue-demi": "^0.14.6",
|
|
36
37
|
"vue-i18n": "^8.27.2",
|
|
@@ -63,6 +64,9 @@
|
|
|
63
64
|
},
|
|
64
65
|
"@ant-design/react-native": {
|
|
65
66
|
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"react-native-safe-area-context": {
|
|
69
|
+
"optional": true
|
|
66
70
|
}
|
|
67
71
|
},
|
|
68
72
|
"publishConfig": {
|
|
@@ -81,5 +85,5 @@
|
|
|
81
85
|
"url": "https://github.com/didi/mpx/issues"
|
|
82
86
|
},
|
|
83
87
|
"sideEffects": false,
|
|
84
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "aa001c11cc7b21772fc6f9f5bcdd13118fc6d67c"
|
|
85
89
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isObject, isArray, dash2hump, isFunction
|
|
1
|
+
import { isObject, isArray, dash2hump, isFunction } from '@mpxjs/utils'
|
|
2
2
|
import { Dimensions } from 'react-native'
|
|
3
3
|
|
|
4
4
|
function concat (a, b) {
|
|
@@ -110,6 +110,7 @@ export default function styleHelperMixin (type) {
|
|
|
110
110
|
return concat(staticClass, stringifyDynamicClass(dynamicClass))
|
|
111
111
|
},
|
|
112
112
|
__getStyle (staticClass, dynamicClass, staticStyle, dynamicStyle, show) {
|
|
113
|
+
// todo 每次返回新对象会导致react memo优化失效,需要考虑优化手段
|
|
113
114
|
const result = []
|
|
114
115
|
const classMap = {}
|
|
115
116
|
if (type === 'page' && isFunction(global.__getAppClassMap)) {
|
|
@@ -118,11 +119,14 @@ export default function styleHelperMixin (type) {
|
|
|
118
119
|
if (isFunction(this.__getClassMap)) {
|
|
119
120
|
Object.assign(classMap, this.__getClassMap())
|
|
120
121
|
}
|
|
121
|
-
if (
|
|
122
|
+
if (staticClass || dynamicClass) {
|
|
122
123
|
const classString = concat(staticClass, stringifyDynamicClass(dynamicClass))
|
|
123
|
-
classString.split(
|
|
124
|
+
classString.split(/\s+/).forEach((className) => {
|
|
124
125
|
if (classMap[className]) {
|
|
125
126
|
result.push(classMap[className])
|
|
127
|
+
} else if (this.props[className]) {
|
|
128
|
+
// externalClasses必定以数组形式传递下来
|
|
129
|
+
result.push(...this.props[className])
|
|
126
130
|
}
|
|
127
131
|
})
|
|
128
132
|
}
|
|
@@ -40,7 +40,7 @@ function createAppInstance (appData) {
|
|
|
40
40
|
export default function createApp (option, config = {}) {
|
|
41
41
|
const appData = {}
|
|
42
42
|
|
|
43
|
-
const { NavigationContainer, createNavigationContainerRef, createNativeStackNavigator } = global.__navigationHelper
|
|
43
|
+
const { NavigationContainer, createNavigationContainerRef, createNativeStackNavigator, SafeAreaProvider } = global.__navigationHelper
|
|
44
44
|
// app选项目前不需要进行转换
|
|
45
45
|
const { rawOptions, currentInject } = transferOptions(option, 'app', false)
|
|
46
46
|
const defaultOptions = filterOptions(spreadProp(rawOptions, 'methods'), appData)
|
|
@@ -114,13 +114,13 @@ export default function createApp (option, config = {}) {
|
|
|
114
114
|
if (currentState === 'active') {
|
|
115
115
|
global.__mpxAppCbs.show.forEach((cb) => {
|
|
116
116
|
cb(options)
|
|
117
|
-
global.__mpxAppFocusedState.value = 'show'
|
|
118
117
|
})
|
|
119
|
-
|
|
118
|
+
global.__mpxAppFocusedState.value = 'show'
|
|
119
|
+
} else if (currentState === 'inactive') {
|
|
120
120
|
global.__mpxAppCbs.hide.forEach((cb) => {
|
|
121
121
|
cb()
|
|
122
|
-
global.__mpxAppFocusedState.value = 'hide'
|
|
123
122
|
})
|
|
123
|
+
global.__mpxAppFocusedState.value = 'hide'
|
|
124
124
|
}
|
|
125
125
|
})
|
|
126
126
|
|
|
@@ -138,17 +138,20 @@ export default function createApp (option, config = {}) {
|
|
|
138
138
|
}
|
|
139
139
|
}, [])
|
|
140
140
|
|
|
141
|
-
return createElement(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
onStateChange,
|
|
145
|
-
onUnhandledAction
|
|
146
|
-
},
|
|
147
|
-
createElement(Stack.Navigator,
|
|
141
|
+
return createElement(SafeAreaProvider,
|
|
142
|
+
null,
|
|
143
|
+
createElement(NavigationContainer,
|
|
148
144
|
{
|
|
149
|
-
|
|
145
|
+
ref: navigationRef,
|
|
146
|
+
onStateChange,
|
|
147
|
+
onUnhandledAction
|
|
150
148
|
},
|
|
151
|
-
|
|
149
|
+
createElement(Stack.Navigator,
|
|
150
|
+
{
|
|
151
|
+
initialRouteName: firstPage
|
|
152
|
+
},
|
|
153
|
+
...pageScreens
|
|
154
|
+
)
|
|
152
155
|
)
|
|
153
156
|
)
|
|
154
157
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useSyncExternalStore, useRef, createElement, memo, forwardRef, useImperativeHandle, useContext, createContext, Fragment } from 'react'
|
|
1
|
+
import { useEffect, useLayoutEffect, useSyncExternalStore, useRef, useMemo, createElement, memo, forwardRef, useImperativeHandle, useContext, createContext, Fragment } from 'react'
|
|
2
2
|
import * as ReactNative from 'react-native'
|
|
3
3
|
import { ReactiveEffect } from '../../../observer/effect'
|
|
4
4
|
import { watch } from '../../../observer/watch'
|
|
5
|
-
import { reactive, set } from '../../../observer/reactive'
|
|
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
8
|
import { BEFOREUPDATE, ONLOAD, UPDATED, ONSHOW, ONHIDE, ONRESIZE } from '../../../core/innerLifecycle'
|
|
@@ -185,6 +185,12 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
|
|
|
185
185
|
return props.id
|
|
186
186
|
},
|
|
187
187
|
enumerable: true
|
|
188
|
+
},
|
|
189
|
+
props: {
|
|
190
|
+
get () {
|
|
191
|
+
return propsRef.current
|
|
192
|
+
},
|
|
193
|
+
enumerable: true
|
|
188
194
|
}
|
|
189
195
|
})
|
|
190
196
|
|
|
@@ -271,8 +277,12 @@ const triggerResizeEvent = (mpxProxy) => {
|
|
|
271
277
|
}
|
|
272
278
|
}
|
|
273
279
|
|
|
274
|
-
function usePageContext (mpxProxy) {
|
|
275
|
-
const {
|
|
280
|
+
function usePageContext (mpxProxy, instance) {
|
|
281
|
+
const { pageId } = useContext(routeContext) || {}
|
|
282
|
+
|
|
283
|
+
instance.getPageId = () => {
|
|
284
|
+
return pageId
|
|
285
|
+
}
|
|
276
286
|
|
|
277
287
|
useEffect(() => {
|
|
278
288
|
let unWatch
|
|
@@ -280,8 +290,8 @@ function usePageContext (mpxProxy) {
|
|
|
280
290
|
const hasHideHook = hasPageHook(mpxProxy, [ONHIDE, 'hide'])
|
|
281
291
|
const hasResizeHook = hasPageHook(mpxProxy, [ONRESIZE, 'resize'])
|
|
282
292
|
if (hasShowHook || hasHideHook || hasResizeHook) {
|
|
283
|
-
if (hasOwn(pageStatusContext,
|
|
284
|
-
unWatch = watch(() => pageStatusContext[
|
|
293
|
+
if (hasOwn(pageStatusContext, pageId)) {
|
|
294
|
+
unWatch = watch(() => pageStatusContext[pageId], (newVal) => {
|
|
285
295
|
if (newVal === 'show' || newVal === 'hide') {
|
|
286
296
|
triggerPageStatusHook(mpxProxy, newVal)
|
|
287
297
|
} else if (/^resize/.test(newVal)) {
|
|
@@ -298,27 +308,23 @@ function usePageContext (mpxProxy) {
|
|
|
298
308
|
}
|
|
299
309
|
|
|
300
310
|
const pageStatusContext = reactive({})
|
|
301
|
-
|
|
302
|
-
set(pageStatusContext, routeName, val)
|
|
303
|
-
}
|
|
311
|
+
let pageId = 0
|
|
304
312
|
|
|
305
|
-
function usePageStatus (navigation,
|
|
313
|
+
function usePageStatus (navigation, pageId) {
|
|
306
314
|
let isFocused = true
|
|
307
|
-
|
|
315
|
+
set(pageStatusContext, pageId, '')
|
|
308
316
|
useEffect(() => {
|
|
309
|
-
setPageStatus(route.name, 'show')
|
|
310
317
|
const focusSubscription = navigation.addListener('focus', () => {
|
|
311
|
-
|
|
318
|
+
pageStatusContext[pageId] = 'show'
|
|
312
319
|
isFocused = true
|
|
313
320
|
})
|
|
314
321
|
const blurSubscription = navigation.addListener('blur', () => {
|
|
315
|
-
|
|
322
|
+
pageStatusContext[pageId] = 'hide'
|
|
316
323
|
isFocused = false
|
|
317
324
|
})
|
|
318
|
-
|
|
319
325
|
const unWatchAppFocusedState = watch(global.__mpxAppFocusedState, (value) => {
|
|
320
326
|
if (isFocused) {
|
|
321
|
-
|
|
327
|
+
pageStatusContext[pageId] = value
|
|
322
328
|
}
|
|
323
329
|
})
|
|
324
330
|
|
|
@@ -326,6 +332,7 @@ function usePageStatus (navigation, route) {
|
|
|
326
332
|
focusSubscription()
|
|
327
333
|
blurSubscription()
|
|
328
334
|
unWatchAppFocusedState()
|
|
335
|
+
del(pageStatusContext, pageId)
|
|
329
336
|
}
|
|
330
337
|
}, [navigation])
|
|
331
338
|
}
|
|
@@ -362,7 +369,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
362
369
|
proxy.propsUpdated()
|
|
363
370
|
}
|
|
364
371
|
|
|
365
|
-
usePageContext(proxy)
|
|
372
|
+
usePageContext(proxy, instance)
|
|
366
373
|
|
|
367
374
|
useEffect(() => {
|
|
368
375
|
if (proxy.pendingUpdatedFlag) {
|
|
@@ -387,13 +394,15 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
387
394
|
}))
|
|
388
395
|
|
|
389
396
|
if (type === 'page') {
|
|
390
|
-
const { Provider } = global.__navigationHelper
|
|
397
|
+
const { Provider, useSafeAreaInsets } = global.__navigationHelper
|
|
391
398
|
const pageConfig = Object.assign({}, global.__mpxPageConfig, currentInject.pageConfig)
|
|
392
399
|
const Page = ({ navigation, route }) => {
|
|
393
|
-
|
|
400
|
+
const currentPageId = useMemo(() => ++pageId, [])
|
|
401
|
+
usePageStatus(navigation, currentPageId)
|
|
394
402
|
|
|
395
403
|
useLayoutEffect(() => {
|
|
396
404
|
navigation.setOptions({
|
|
405
|
+
headerShown: pageConfig.navigationStyle !== 'custom',
|
|
397
406
|
headerTitle: pageConfig.navigationBarTitleText || '',
|
|
398
407
|
headerStyle: {
|
|
399
408
|
backgroundColor: pageConfig.navigationBarBackgroundColor || '#000000'
|
|
@@ -402,18 +411,25 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
402
411
|
})
|
|
403
412
|
}, [])
|
|
404
413
|
|
|
414
|
+
const insets = useSafeAreaInsets()
|
|
415
|
+
const safeAreaPadding = {
|
|
416
|
+
paddingTop: insets.top,
|
|
417
|
+
paddingLeft: insets.left
|
|
418
|
+
}
|
|
419
|
+
|
|
405
420
|
return createElement(Provider,
|
|
406
421
|
null,
|
|
407
422
|
createElement(ReactNative.View,
|
|
408
423
|
{
|
|
409
424
|
style: {
|
|
425
|
+
...pageConfig.navigationStyle === 'custom' && safeAreaPadding,
|
|
410
426
|
...ReactNative.StyleSheet.absoluteFillObject,
|
|
411
427
|
backgroundColor: pageConfig.backgroundColor || '#ffffff'
|
|
412
428
|
}
|
|
413
429
|
},
|
|
414
430
|
createElement(routeContext.Provider,
|
|
415
431
|
{
|
|
416
|
-
value: {
|
|
432
|
+
value: { pageId: currentPageId }
|
|
417
433
|
},
|
|
418
434
|
createElement(defaultOptions,
|
|
419
435
|
{
|