@mpxjs/core 2.10.7-beta.1 → 2.10.7-beta.11
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 +26 -3
- package/package.json +2 -2
- package/src/index.js +9 -1
- package/src/platform/builtInMixins/pageRouteMixin.ios.js +1 -1
- package/src/platform/env/index.ios.js +1 -13
- package/src/platform/env/nav.js +13 -4
- package/src/platform/env/navigationHelper.android.js +17 -0
- package/src/platform/env/navigationHelper.ios.js +0 -2
- package/src/platform/patch/getDefaultOptions.ios.js +40 -50
- package/src/platform/patch/getDefaultOptions.web.js +1 -1
package/@types/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/// <reference path="./global.d.ts" />
|
|
8
8
|
/// <reference path="./node.d.ts" />
|
|
9
9
|
|
|
10
|
-
import { GetComputedType } from '@mpxjs/store'
|
|
10
|
+
import type { GetComputedType } from '@mpxjs/store'
|
|
11
11
|
|
|
12
12
|
export * from '@mpxjs/store'
|
|
13
13
|
|
|
@@ -255,11 +255,22 @@ interface AnyConstructor {
|
|
|
255
255
|
prototype: any
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
interface WebviewConfig {
|
|
258
|
+
export interface WebviewConfig {
|
|
259
259
|
hostWhitelists?: Array<string>
|
|
260
260
|
apiImplementations?: object
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
export interface RnConfig {
|
|
264
|
+
onStateChange?: (state: any) => void
|
|
265
|
+
parseAppProps?: (props: any) => ({ initialRouteName?: string, initialParams?: any } | undefined | null | void)
|
|
266
|
+
/**
|
|
267
|
+
* 外层可能会异常设置此配置,因此加载监听函数内部
|
|
268
|
+
*/
|
|
269
|
+
disableAppStateListener?: boolean
|
|
270
|
+
/** 进入页面是否控制回推按钮的展示以及监听回推按钮的点击 */
|
|
271
|
+
onStackTopBack: () => void
|
|
272
|
+
}
|
|
273
|
+
|
|
263
274
|
interface MpxConfig {
|
|
264
275
|
useStrictDiff: boolean
|
|
265
276
|
ignoreWarning: boolean | string | RegExp | ((msg: string, location: string, e: Error) => boolean)
|
|
@@ -272,8 +283,14 @@ interface MpxConfig {
|
|
|
272
283
|
forceFlushSync: boolean,
|
|
273
284
|
webRouteConfig: object,
|
|
274
285
|
webConfig: object,
|
|
286
|
+
/*
|
|
287
|
+
* 支持两个属性
|
|
288
|
+
* hostWhitelists Array 类型 支持h5域名白名单安全校验
|
|
289
|
+
* apiImplementations webview JSSDK接口 例如getlocation
|
|
290
|
+
*/
|
|
275
291
|
webviewConfig: WebviewConfig,
|
|
276
|
-
|
|
292
|
+
/** react-native 相关配置,用于挂载事件等,如 onShareAppMessage */
|
|
293
|
+
rnConfig?: RnConfig,
|
|
277
294
|
}
|
|
278
295
|
|
|
279
296
|
type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'
|
|
@@ -664,9 +681,15 @@ export const SERVERPREFETCH: string
|
|
|
664
681
|
export const REACTHOOKSEXEC: string
|
|
665
682
|
|
|
666
683
|
declare global {
|
|
684
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
685
|
+
// @ts-expect-error
|
|
667
686
|
const defineProps: (<T extends Properties = {}>(props: T) => Readonly<GetPropsType<T>>) & (<T>() => Readonly<T>)
|
|
668
687
|
const defineOptions: <D extends Data = {}, P extends Properties = {}, C = {}, M extends Methods = {}, Mi extends Array<any> = [], S extends AnyObject = {}, O extends AnyObject = {}> (opt: ThisTypedComponentOpt<D, P, C, M, Mi, S, O>) => void
|
|
688
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
689
|
+
// @ts-expect-error
|
|
669
690
|
const defineExpose: <E extends AnyObject = AnyObject>(exposed?: E) => void
|
|
670
691
|
const useContext: () => Context
|
|
692
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
693
|
+
// @ts-expect-error
|
|
671
694
|
const withDefaults: <Props, Defaults extends InferDefaults<Props>>(props: Props, defaults: Defaults) => PropsWithDefaults<Props, Defaults>
|
|
672
695
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.10.7-beta.
|
|
3
|
+
"version": "2.10.7-beta.11",
|
|
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.
|
|
22
|
+
"@mpxjs/utils": "^2.10.6 | ^2.10.6-beta.1",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
24
|
"miniprogram-api-typings": "^3.10.0"
|
|
25
25
|
},
|
package/src/index.js
CHANGED
|
@@ -115,6 +115,9 @@ function use (plugin, options = {}) {
|
|
|
115
115
|
|
|
116
116
|
APIs.use = use
|
|
117
117
|
|
|
118
|
+
/**
|
|
119
|
+
* @returns {import('@mpxjs/core').Mpx}
|
|
120
|
+
*/
|
|
118
121
|
function factory () {
|
|
119
122
|
// 作为原型挂载属性的中间层
|
|
120
123
|
function Mpx () {
|
|
@@ -125,6 +128,9 @@ function factory () {
|
|
|
125
128
|
return Mpx
|
|
126
129
|
}
|
|
127
130
|
|
|
131
|
+
/**
|
|
132
|
+
* @type {import('@mpxjs/core').Mpx}
|
|
133
|
+
*/
|
|
128
134
|
const Mpx = factory()
|
|
129
135
|
|
|
130
136
|
Mpx.config = {
|
|
@@ -138,7 +144,9 @@ Mpx.config = {
|
|
|
138
144
|
setDataHandler: null,
|
|
139
145
|
forceFlushSync: false,
|
|
140
146
|
webRouteConfig: {},
|
|
141
|
-
webConfig: {
|
|
147
|
+
webConfig: {
|
|
148
|
+
disablePageTransition: true // 默认禁用页面切换动画
|
|
149
|
+
},
|
|
142
150
|
/*
|
|
143
151
|
支持两个属性
|
|
144
152
|
hostWhitelists Array 类型 支持h5域名白名单安全校验
|
|
@@ -4,7 +4,7 @@ export default function pageRouteMixin (mixinType) {
|
|
|
4
4
|
if (mixinType === 'page') {
|
|
5
5
|
return {
|
|
6
6
|
[BEFORECREATE] () {
|
|
7
|
-
const mpxEventChannel = global.__mpxEventChannel
|
|
7
|
+
const mpxEventChannel = global.__mpxEventChannel || {}
|
|
8
8
|
if (mpxEventChannel.route === this.route) {
|
|
9
9
|
this._eventChannel = mpxEventChannel.eventChannel
|
|
10
10
|
} else {
|
|
@@ -10,15 +10,13 @@ export function init (Mpx) {
|
|
|
10
10
|
show: [],
|
|
11
11
|
hide: [],
|
|
12
12
|
error: [],
|
|
13
|
-
rejection: []
|
|
14
|
-
lazyLoad: []
|
|
13
|
+
rejection: []
|
|
15
14
|
}
|
|
16
15
|
global.__navigationHelper = navigationHelper
|
|
17
16
|
if (global.i18n) {
|
|
18
17
|
Mpx.i18n = createI18n(global.i18n)
|
|
19
18
|
}
|
|
20
19
|
initGlobalErrorHandling()
|
|
21
|
-
initGlobalLazyLoadHandling()
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
function initGlobalErrorHandling () {
|
|
@@ -65,13 +63,3 @@ function initGlobalErrorHandling () {
|
|
|
65
63
|
require('promise/setimmediate/rejection-tracking').enable(rejectionTrackingOptions)
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
|
-
|
|
69
|
-
function initGlobalLazyLoadHandling () {
|
|
70
|
-
global.onLazyLoadError = function (error) {
|
|
71
|
-
if (global.__mpxAppCbs?.lazyLoad?.length) {
|
|
72
|
-
global.__mpxAppCbs.lazyLoad.forEach((cb) => {
|
|
73
|
-
cb(error)
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/platform/env/nav.js
CHANGED
|
@@ -95,14 +95,23 @@ export function innerNav ({ pageConfig, navigation }) {
|
|
|
95
95
|
const safeAreaTop = useSafeAreaInsets()?.top || 0
|
|
96
96
|
// 假设是栈导航,获取栈的长度
|
|
97
97
|
const stackLength = navigation.getState()?.routes?.length
|
|
98
|
-
|
|
99
|
-
const
|
|
98
|
+
const onStackTopBack = Mpx.config?.rnConfig?.onStackTopBack
|
|
99
|
+
const isHandleStackTopBack = typeof onStackTopBack === 'function'
|
|
100
100
|
|
|
101
101
|
// 回退按钮与图标
|
|
102
|
-
const backElement = stackLength
|
|
102
|
+
const backElement = stackLength > 1 || isHandleStackTopBack
|
|
103
103
|
? createElement(TouchableOpacity, {
|
|
104
104
|
style: [styles.backButton],
|
|
105
|
-
onPress: () => {
|
|
105
|
+
onPress: () => {
|
|
106
|
+
if (stackLength <= 1) {
|
|
107
|
+
if (isHandleStackTopBack) {
|
|
108
|
+
onStackTopBack()
|
|
109
|
+
}
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
navigation.goBack()
|
|
114
|
+
}
|
|
106
115
|
}, createElement(Image, {
|
|
107
116
|
source: { uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg==' },
|
|
108
117
|
// 回退按钮的颜色与设置的title文案颜色一致
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
|
2
|
+
import { NavigationContainer, StackActions } from '@react-navigation/native'
|
|
3
|
+
import PortalHost from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-portal/portal-host'
|
|
4
|
+
import { useHeaderHeight } from '@react-navigation/elements'
|
|
5
|
+
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
6
|
+
import { GestureHandlerRootView } from 'react-native-gesture-handler'
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
createNativeStackNavigator,
|
|
10
|
+
NavigationContainer,
|
|
11
|
+
useHeaderHeight,
|
|
12
|
+
StackActions,
|
|
13
|
+
GestureHandlerRootView,
|
|
14
|
+
PortalHost,
|
|
15
|
+
SafeAreaProvider,
|
|
16
|
+
useSafeAreaInsets
|
|
17
|
+
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
|
2
2
|
import { NavigationContainer, StackActions } from '@react-navigation/native'
|
|
3
3
|
import PortalHost from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-portal/portal-host'
|
|
4
|
-
import { useHeaderHeight } from '@react-navigation/elements'
|
|
5
4
|
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
6
5
|
import { GestureHandlerRootView } from 'react-native-gesture-handler'
|
|
7
6
|
|
|
8
7
|
export {
|
|
9
8
|
createNativeStackNavigator,
|
|
10
9
|
NavigationContainer,
|
|
11
|
-
useHeaderHeight,
|
|
12
10
|
StackActions,
|
|
13
11
|
GestureHandlerRootView,
|
|
14
12
|
PortalHost,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
KeyboardAvoidContext,
|
|
16
16
|
RouteContext
|
|
17
17
|
} from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/context'
|
|
18
|
-
import { PortalHost, useSafeAreaInsets } from '../env/navigationHelper'
|
|
18
|
+
import { PortalHost, useSafeAreaInsets, GestureHandlerRootView } from '../env/navigationHelper'
|
|
19
19
|
import { useInnerHeaderHeight } from '../env/nav'
|
|
20
20
|
|
|
21
21
|
const ProviderContext = createContext(null)
|
|
@@ -419,22 +419,6 @@ function usePageStatus (navigation, pageId) {
|
|
|
419
419
|
}, [navigation])
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
function usePagePreload (route) {
|
|
423
|
-
const name = route.name
|
|
424
|
-
useEffect(() => {
|
|
425
|
-
setTimeout(() => {
|
|
426
|
-
const preloadRule = global.__preloadRule || {}
|
|
427
|
-
const { packages } = preloadRule[name] || {}
|
|
428
|
-
if (packages?.length > 0) {
|
|
429
|
-
const downloadChunkAsync = mpxGlobal.__mpx.config?.rnConfig?.downloadChunkAsync
|
|
430
|
-
if (typeof downloadChunkAsync === 'function') {
|
|
431
|
-
callWithErrorHandling(() => downloadChunkAsync(packages))
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}, 800)
|
|
435
|
-
}, [])
|
|
436
|
-
}
|
|
437
|
-
|
|
438
422
|
const RelationsContext = createContext(null)
|
|
439
423
|
|
|
440
424
|
const checkRelation = (options) => {
|
|
@@ -463,6 +447,8 @@ function getLayoutData (headerHeight) {
|
|
|
463
447
|
const isLandscape = screenDimensions.height < screenDimensions.width
|
|
464
448
|
const bottomVirtualHeight = isLandscape ? screenDimensions.height - windowDimensions.height : ((screenDimensions.height - windowDimensions.height - ReactNative.StatusBar.currentHeight) || 0)
|
|
465
449
|
return {
|
|
450
|
+
x: 0,
|
|
451
|
+
y: headerHeight,
|
|
466
452
|
left: 0,
|
|
467
453
|
top: headerHeight,
|
|
468
454
|
// 此处必须为windowDimensions.width,在横屏状态下windowDimensions.width才符合预期
|
|
@@ -493,15 +479,11 @@ export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
|
|
|
493
479
|
}
|
|
494
480
|
const headerHeight = useInnerHeaderHeight(currentPageConfig)
|
|
495
481
|
navigation.layout = getLayoutData(headerHeight)
|
|
482
|
+
const onLayout = () => {
|
|
483
|
+
// 当用户处于横屏或者竖屏状态的时候,需要进行layout修正
|
|
484
|
+
navigation.layout = getLayoutData(headerHeight)
|
|
485
|
+
}
|
|
496
486
|
|
|
497
|
-
useEffect(() => {
|
|
498
|
-
const dimensionListener = ReactNative.Dimensions.addEventListener('change', ({ screen }) => {
|
|
499
|
-
navigation.layout = getLayoutData(headerHeight)
|
|
500
|
-
})
|
|
501
|
-
return () => dimensionListener?.remove()
|
|
502
|
-
}, [])
|
|
503
|
-
|
|
504
|
-
usePagePreload(route)
|
|
505
487
|
usePageStatus(navigation, currentPageId)
|
|
506
488
|
|
|
507
489
|
const withKeyboardAvoidingView = (element) => {
|
|
@@ -524,38 +506,45 @@ export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
|
|
|
524
506
|
}
|
|
525
507
|
// android存在第一次打开insets都返回为0情况,后续会触发第二次渲染后正确
|
|
526
508
|
navigation.insets = useSafeAreaInsets()
|
|
527
|
-
return
|
|
528
|
-
|
|
529
|
-
{
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
},
|
|
536
|
-
ref: rootRef
|
|
537
|
-
},
|
|
538
|
-
createElement(RouteContext.Provider,
|
|
509
|
+
return createElement(GestureHandlerRootView,
|
|
510
|
+
{
|
|
511
|
+
style: {
|
|
512
|
+
flex: 1
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
withKeyboardAvoidingView(
|
|
516
|
+
createElement(ReactNative.View,
|
|
539
517
|
{
|
|
540
|
-
|
|
518
|
+
style: {
|
|
519
|
+
flex: 1,
|
|
520
|
+
backgroundColor: currentPageConfig?.backgroundColor || '#fff',
|
|
521
|
+
// 解决页面内有元素定位relative left为负值的时候,回退的时候还能看到对应元素问题
|
|
522
|
+
overflow: 'hidden'
|
|
523
|
+
},
|
|
524
|
+
ref: rootRef,
|
|
525
|
+
onLayout
|
|
541
526
|
},
|
|
542
|
-
createElement(
|
|
527
|
+
createElement(RouteContext.Provider,
|
|
543
528
|
{
|
|
544
|
-
value:
|
|
529
|
+
value: routeContextValRef.current
|
|
545
530
|
},
|
|
546
|
-
createElement(
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
531
|
+
createElement(IntersectionObserverContext.Provider,
|
|
532
|
+
{
|
|
533
|
+
value: intersectionObservers.current
|
|
534
|
+
},
|
|
535
|
+
createElement(PortalHost,
|
|
536
|
+
null,
|
|
537
|
+
createElement(WrappedComponent, {
|
|
538
|
+
...props,
|
|
539
|
+
navigation,
|
|
540
|
+
route,
|
|
541
|
+
id: currentPageId
|
|
542
|
+
})
|
|
543
|
+
)
|
|
554
544
|
)
|
|
555
545
|
)
|
|
556
546
|
)
|
|
557
|
-
)
|
|
558
|
-
)
|
|
547
|
+
))
|
|
559
548
|
}
|
|
560
549
|
}
|
|
561
550
|
export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
@@ -625,6 +614,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
625
614
|
})
|
|
626
615
|
|
|
627
616
|
usePageEffect(proxy, pageId)
|
|
617
|
+
|
|
628
618
|
useEffect(() => {
|
|
629
619
|
proxy.mounted()
|
|
630
620
|
return () => {
|
|
@@ -89,8 +89,8 @@ export function getDefaultOptions ({ type, rawOptions = {} }) {
|
|
|
89
89
|
},
|
|
90
90
|
destroyed () {
|
|
91
91
|
if (this.__mpxProxy) {
|
|
92
|
-
this.__mpxProxy.state = UNMOUNTED
|
|
93
92
|
this.__mpxProxy.callHook(UNMOUNTED)
|
|
93
|
+
this.__mpxProxy.state = UNMOUNTED
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
serverPrefetch (...args) {
|