@mpxjs/core 2.10.7-beta.9 → 2.10.8-beta.2
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 +2 -7
- package/package.json +2 -2
- package/src/platform/builtInMixins/styleHelperMixin.ios.js +3 -0
- package/src/platform/createApp.ios.js +35 -31
- package/src/platform/env/index.ios.js +13 -1
- package/src/platform/env/navigationHelper.ios.js +0 -2
- package/src/platform/patch/getDefaultOptions.ios.js +85 -51
- package/src/platform/env/nav.js +0 -133
- package/src/platform/env/navigationHelper.android.js +0 -17
package/@types/index.d.ts
CHANGED
|
@@ -267,13 +267,8 @@ export interface RnConfig {
|
|
|
267
267
|
* 外层可能会异常设置此配置,因此加载监听函数内部
|
|
268
268
|
*/
|
|
269
269
|
disableAppStateListener?: boolean
|
|
270
|
-
/**
|
|
271
|
-
|
|
272
|
-
/** 是否展示回退按钮 */
|
|
273
|
-
show?: boolean,
|
|
274
|
-
/** 监听回退按钮点击 */
|
|
275
|
-
listener?: Function
|
|
276
|
-
}
|
|
270
|
+
/** 进入页面是否控制回退按钮的展示以及监听回退按钮的点击 */
|
|
271
|
+
onStackTopBack?: () => void
|
|
277
272
|
}
|
|
278
273
|
|
|
279
274
|
interface MpxConfig {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.8-beta.2",
|
|
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.8",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
24
|
"miniprogram-api-typings": "^3.10.0"
|
|
25
25
|
},
|
|
@@ -2,6 +2,9 @@ import { isObject, isArray, dash2hump, cached, isEmptyObject } from '@mpxjs/util
|
|
|
2
2
|
import { Dimensions, StyleSheet } from 'react-native'
|
|
3
3
|
|
|
4
4
|
let { width, height } = Dimensions.get('screen')
|
|
5
|
+
// TODO 临时适配折叠屏场景适配
|
|
6
|
+
const isLargeFoldableLike = (__mpx_mode__ === 'android') && (height / width < 1.5) && (width > 600)
|
|
7
|
+
if (isLargeFoldableLike) width = width / 2
|
|
5
8
|
|
|
6
9
|
Dimensions.addEventListener('change', ({ screen }) => {
|
|
7
10
|
width = screen.width
|
|
@@ -10,7 +10,8 @@ import { createElement, memo, useRef, useEffect } from 'react'
|
|
|
10
10
|
import * as ReactNative from 'react-native'
|
|
11
11
|
import { initAppProvides } from './export/inject'
|
|
12
12
|
import { NavigationContainer, createNativeStackNavigator, SafeAreaProvider, GestureHandlerRootView } from './env/navigationHelper'
|
|
13
|
-
import
|
|
13
|
+
import createMpxNav from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/nav'
|
|
14
|
+
import { NavSharedProvider } from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-nav-container'
|
|
14
15
|
|
|
15
16
|
const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)
|
|
16
17
|
|
|
@@ -33,6 +34,15 @@ function filterOptions (options, appData) {
|
|
|
33
34
|
return newOptions
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
let CachedMpxNav = null
|
|
38
|
+
|
|
39
|
+
function getMpxNav() {
|
|
40
|
+
// Mpx toplevel 执行时获取不到
|
|
41
|
+
return (CachedMpxNav ??= createMpxNav({
|
|
42
|
+
Mpx
|
|
43
|
+
}))
|
|
44
|
+
}
|
|
45
|
+
|
|
36
46
|
export default function createApp (options) {
|
|
37
47
|
const appData = {}
|
|
38
48
|
// app选项目前不需要进行转换
|
|
@@ -53,44 +63,38 @@ export default function createApp (options) {
|
|
|
53
63
|
defaultOptions.onUnhandledRejection && global.__mpxAppCbs.rejection.push(defaultOptions.onUnhandledRejection.bind(appInstance))
|
|
54
64
|
defaultOptions.onAppInit && defaultOptions.onAppInit()
|
|
55
65
|
|
|
56
|
-
const
|
|
66
|
+
const pagesMap = currentInject.pagesMap || {}
|
|
57
67
|
const firstPage = currentInject.firstPage
|
|
58
68
|
const Stack = createNativeStackNavigator()
|
|
59
|
-
const withHeader = (wrappedComponent, { pageConfig = {} }) => {
|
|
60
|
-
return ({ navigation, ...props }) => {
|
|
61
|
-
return createElement(GestureHandlerRootView,
|
|
62
|
-
{
|
|
63
|
-
style: {
|
|
64
|
-
flex: 1
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
createElement(innerNav, {
|
|
68
|
-
pageConfig: pageConfig,
|
|
69
|
-
navigation
|
|
70
|
-
}),
|
|
71
|
-
createElement(wrappedComponent, { navigation, ...props })
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
69
|
const getPageScreens = (initialRouteName, initialParams) => {
|
|
76
|
-
return Object.entries(
|
|
77
|
-
// const options = {
|
|
78
|
-
// // __mpxPageStatusMap 为编译注入的全局变量
|
|
79
|
-
// headerShown: !(Object.assign({}, global.__mpxPageConfig, global.__mpxPageConfigsMap[key]).navigationStyle === 'custom')
|
|
80
|
-
// }
|
|
70
|
+
return Object.entries(pagesMap).map(([key, item]) => {
|
|
81
71
|
const pageConfig = Object.assign({}, global.__mpxPageConfig, global.__mpxPageConfigsMap[key])
|
|
72
|
+
const headerLayout = ({ navigation, children }) => {
|
|
73
|
+
return createElement(GestureHandlerRootView,
|
|
74
|
+
{
|
|
75
|
+
style: {
|
|
76
|
+
flex: 1
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
createElement(getMpxNav(), {
|
|
80
|
+
pageConfig: pageConfig,
|
|
81
|
+
navigation
|
|
82
|
+
}),
|
|
83
|
+
children
|
|
84
|
+
)
|
|
85
|
+
}
|
|
82
86
|
if (key === initialRouteName) {
|
|
83
87
|
return createElement(Stack.Screen, {
|
|
84
88
|
name: key,
|
|
85
|
-
|
|
86
|
-
initialParams
|
|
87
|
-
|
|
89
|
+
getComponent: () => item(),
|
|
90
|
+
initialParams,
|
|
91
|
+
layout: headerLayout
|
|
88
92
|
})
|
|
89
93
|
}
|
|
90
94
|
return createElement(Stack.Screen, {
|
|
91
95
|
name: key,
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
getComponent: () => item(),
|
|
97
|
+
layout: headerLayout
|
|
94
98
|
})
|
|
95
99
|
})
|
|
96
100
|
}
|
|
@@ -239,7 +243,7 @@ export default function createApp (options) {
|
|
|
239
243
|
headerShown: false,
|
|
240
244
|
statusBarTranslucent: true,
|
|
241
245
|
statusBarBackgroundColor: 'transparent'
|
|
242
|
-
|
|
246
|
+
}
|
|
243
247
|
|
|
244
248
|
return createElement(SafeAreaProvider,
|
|
245
249
|
null,
|
|
@@ -248,13 +252,13 @@ export default function createApp (options) {
|
|
|
248
252
|
onStateChange,
|
|
249
253
|
onUnhandledAction
|
|
250
254
|
},
|
|
251
|
-
createElement(Stack.Navigator,
|
|
255
|
+
createElement(NavSharedProvider, null, createElement(Stack.Navigator,
|
|
252
256
|
{
|
|
253
257
|
initialRouteName,
|
|
254
258
|
screenOptions: navScreenOpts
|
|
255
259
|
},
|
|
256
260
|
...getPageScreens(initialRouteName, initialParams)
|
|
257
|
-
)
|
|
261
|
+
))
|
|
258
262
|
)
|
|
259
263
|
)
|
|
260
264
|
})
|
|
@@ -10,13 +10,15 @@ export function init (Mpx) {
|
|
|
10
10
|
show: [],
|
|
11
11
|
hide: [],
|
|
12
12
|
error: [],
|
|
13
|
-
rejection: []
|
|
13
|
+
rejection: [],
|
|
14
|
+
lazyLoad: []
|
|
14
15
|
}
|
|
15
16
|
global.__navigationHelper = navigationHelper
|
|
16
17
|
if (global.i18n) {
|
|
17
18
|
Mpx.i18n = createI18n(global.i18n)
|
|
18
19
|
}
|
|
19
20
|
initGlobalErrorHandling()
|
|
21
|
+
initGlobalLazyLoadHandling()
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
function initGlobalErrorHandling () {
|
|
@@ -63,3 +65,13 @@ function initGlobalErrorHandling () {
|
|
|
63
65
|
require('promise/setimmediate/rejection-tracking').enable(rejectionTrackingOptions)
|
|
64
66
|
}
|
|
65
67
|
}
|
|
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
|
+
}
|
|
@@ -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,8 +15,8 @@ import {
|
|
|
15
15
|
KeyboardAvoidContext,
|
|
16
16
|
RouteContext
|
|
17
17
|
} from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/context'
|
|
18
|
-
import { PortalHost, useSafeAreaInsets
|
|
19
|
-
import { useInnerHeaderHeight } from '
|
|
18
|
+
import { PortalHost, useSafeAreaInsets } from '../env/navigationHelper'
|
|
19
|
+
import { useInnerHeaderHeight } from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/nav'
|
|
20
20
|
|
|
21
21
|
const ProviderContext = createContext(null)
|
|
22
22
|
function getSystemInfo () {
|
|
@@ -33,7 +33,7 @@ function getSystemInfo () {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function createEffect (proxy,
|
|
36
|
+
function createEffect (proxy, componentsMap) {
|
|
37
37
|
const update = proxy.update = () => {
|
|
38
38
|
// react update props in child render(async), do not need exec pre render
|
|
39
39
|
// if (proxy.propsUpdatedFlag) {
|
|
@@ -50,10 +50,11 @@ function createEffect (proxy, components) {
|
|
|
50
50
|
const getComponent = (tagName) => {
|
|
51
51
|
if (!tagName) return null
|
|
52
52
|
if (tagName === 'block') return Fragment
|
|
53
|
-
const
|
|
53
|
+
const appComponentsMap = global.__appComponentsMap || {}
|
|
54
54
|
const generichash = proxy.target.generichash || ''
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const genericComponentsMap = global.__mpxGenericsMap?.[generichash] || {}
|
|
56
|
+
const componentGetter = componentsMap[tagName] || genericComponentsMap[tagName] || appComponentsMap[tagName]
|
|
57
|
+
return componentGetter ? componentGetter() : getByPath(ReactNative, tagName)
|
|
57
58
|
}
|
|
58
59
|
const innerCreateElement = (type, ...rest) => {
|
|
59
60
|
if (!type) return null
|
|
@@ -123,6 +124,13 @@ const instanceProto = {
|
|
|
123
124
|
createIntersectionObserver (opt) {
|
|
124
125
|
return createIntersectionObserver(this, opt, this.__intersectionCtx)
|
|
125
126
|
},
|
|
127
|
+
// 触发页面范围内的所有observer的计算
|
|
128
|
+
__triggerIntersectionObserver () {
|
|
129
|
+
const intersectionObservers = this.__intersectionCtx
|
|
130
|
+
for (const key in this.__intersectionCtx) {
|
|
131
|
+
intersectionObservers[key].throttleMeasure()
|
|
132
|
+
}
|
|
133
|
+
},
|
|
126
134
|
__resetInstance () {
|
|
127
135
|
this.__dispatchedSlotSet = new WeakSet()
|
|
128
136
|
},
|
|
@@ -203,7 +211,7 @@ const instanceProto = {
|
|
|
203
211
|
}
|
|
204
212
|
}
|
|
205
213
|
|
|
206
|
-
function createInstance ({ propsRef, type, rawOptions, currentInject, validProps,
|
|
214
|
+
function createInstance ({ propsRef, type, rawOptions, currentInject, validProps, componentsMap, pageId, intersectionCtx, relation, parentProvides }) {
|
|
207
215
|
const instance = Object.create(instanceProto, {
|
|
208
216
|
dataset: {
|
|
209
217
|
get () {
|
|
@@ -304,7 +312,14 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
|
|
|
304
312
|
|
|
305
313
|
if (type === 'page') {
|
|
306
314
|
const props = propsRef.current
|
|
307
|
-
|
|
315
|
+
const loadParams = {}
|
|
316
|
+
// 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
|
|
317
|
+
if (isObject(props.route.params)) {
|
|
318
|
+
for (const key in props.route.params) {
|
|
319
|
+
loadParams[key] = encodeURIComponent(props.route.params[key])
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
proxy.callHook(ONLOAD, [loadParams])
|
|
308
323
|
}
|
|
309
324
|
|
|
310
325
|
Object.assign(proxy, {
|
|
@@ -312,7 +327,7 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
|
|
|
312
327
|
stateVersion: Symbol(),
|
|
313
328
|
subscribe: (onStoreChange) => {
|
|
314
329
|
if (!proxy.effect) {
|
|
315
|
-
createEffect(proxy,
|
|
330
|
+
createEffect(proxy, componentsMap)
|
|
316
331
|
proxy.stateVersion = Symbol()
|
|
317
332
|
}
|
|
318
333
|
proxy.onStoreChange = onStoreChange
|
|
@@ -328,7 +343,7 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
|
|
|
328
343
|
})
|
|
329
344
|
// react数据响应组件更新管理器
|
|
330
345
|
if (!proxy.effect) {
|
|
331
|
-
createEffect(proxy,
|
|
346
|
+
createEffect(proxy, componentsMap)
|
|
332
347
|
}
|
|
333
348
|
|
|
334
349
|
return instance
|
|
@@ -419,6 +434,26 @@ function usePageStatus (navigation, pageId) {
|
|
|
419
434
|
}, [navigation])
|
|
420
435
|
}
|
|
421
436
|
|
|
437
|
+
function usePagePreload (route) {
|
|
438
|
+
const name = route.name
|
|
439
|
+
useEffect(() => {
|
|
440
|
+
const timer = setTimeout(() => {
|
|
441
|
+
const preloadRule = global.__preloadRule || {}
|
|
442
|
+
const { packages } = preloadRule[name] || {}
|
|
443
|
+
if (packages?.length > 0) {
|
|
444
|
+
const downloadChunkAsync = mpxGlobal.__mpx.config?.rnConfig?.downloadChunkAsync
|
|
445
|
+
if (typeof downloadChunkAsync === 'function') {
|
|
446
|
+
callWithErrorHandling(() => downloadChunkAsync(packages))
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}, 800)
|
|
450
|
+
|
|
451
|
+
return () => {
|
|
452
|
+
clearTimeout(timer)
|
|
453
|
+
}
|
|
454
|
+
}, [])
|
|
455
|
+
}
|
|
456
|
+
|
|
422
457
|
const RelationsContext = createContext(null)
|
|
423
458
|
|
|
424
459
|
const checkRelation = (options) => {
|
|
@@ -447,8 +482,6 @@ function getLayoutData (headerHeight) {
|
|
|
447
482
|
const isLandscape = screenDimensions.height < screenDimensions.width
|
|
448
483
|
const bottomVirtualHeight = isLandscape ? screenDimensions.height - windowDimensions.height : ((screenDimensions.height - windowDimensions.height - ReactNative.StatusBar.currentHeight) || 0)
|
|
449
484
|
return {
|
|
450
|
-
x: 0,
|
|
451
|
-
y: headerHeight,
|
|
452
485
|
left: 0,
|
|
453
486
|
top: headerHeight,
|
|
454
487
|
// 此处必须为windowDimensions.width,在横屏状态下windowDimensions.width才符合预期
|
|
@@ -479,11 +512,15 @@ export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
|
|
|
479
512
|
}
|
|
480
513
|
const headerHeight = useInnerHeaderHeight(currentPageConfig)
|
|
481
514
|
navigation.layout = getLayoutData(headerHeight)
|
|
482
|
-
const onLayout = () => {
|
|
483
|
-
// 当用户处于横屏或者竖屏状态的时候,需要进行layout修正
|
|
484
|
-
navigation.layout = getLayoutData(headerHeight)
|
|
485
|
-
}
|
|
486
515
|
|
|
516
|
+
useEffect(() => {
|
|
517
|
+
const dimensionListener = ReactNative.Dimensions.addEventListener('change', ({ screen }) => {
|
|
518
|
+
navigation.layout = getLayoutData(headerHeight)
|
|
519
|
+
})
|
|
520
|
+
return () => dimensionListener?.remove()
|
|
521
|
+
}, [])
|
|
522
|
+
|
|
523
|
+
usePagePreload(route)
|
|
487
524
|
usePageStatus(navigation, currentPageId)
|
|
488
525
|
|
|
489
526
|
const withKeyboardAvoidingView = (element) => {
|
|
@@ -506,50 +543,48 @@ export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
|
|
|
506
543
|
}
|
|
507
544
|
// android存在第一次打开insets都返回为0情况,后续会触发第二次渲染后正确
|
|
508
545
|
navigation.insets = useSafeAreaInsets()
|
|
509
|
-
return
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
546
|
+
return withKeyboardAvoidingView(
|
|
547
|
+
createElement(ReactNative.View,
|
|
548
|
+
{
|
|
549
|
+
style: {
|
|
550
|
+
flex: 1,
|
|
551
|
+
backgroundColor: currentPageConfig?.backgroundColor || '#fff',
|
|
552
|
+
// 解决页面内有元素定位relative left为负值的时候,回退的时候还能看到对应元素问题
|
|
553
|
+
overflow: 'hidden'
|
|
554
|
+
},
|
|
555
|
+
ref: rootRef
|
|
556
|
+
},
|
|
557
|
+
createElement(RouteContext.Provider,
|
|
517
558
|
{
|
|
518
|
-
|
|
519
|
-
flex: 1,
|
|
520
|
-
backgroundColor: currentPageConfig?.backgroundColor || '#fff',
|
|
521
|
-
// 解决页面内有元素定位relative left为负值的时候,回退的时候还能看到对应元素问题
|
|
522
|
-
overflow: 'hidden'
|
|
523
|
-
},
|
|
524
|
-
ref: rootRef,
|
|
525
|
-
onLayout
|
|
559
|
+
value: routeContextValRef.current
|
|
526
560
|
},
|
|
527
|
-
createElement(
|
|
561
|
+
createElement(IntersectionObserverContext.Provider,
|
|
528
562
|
{
|
|
529
|
-
value:
|
|
563
|
+
value: intersectionObservers.current
|
|
530
564
|
},
|
|
531
|
-
createElement(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
navigation,
|
|
540
|
-
route,
|
|
541
|
-
id: currentPageId
|
|
542
|
-
})
|
|
543
|
-
)
|
|
565
|
+
createElement(PortalHost,
|
|
566
|
+
null,
|
|
567
|
+
createElement(WrappedComponent, {
|
|
568
|
+
...props,
|
|
569
|
+
navigation,
|
|
570
|
+
route,
|
|
571
|
+
id: currentPageId
|
|
572
|
+
})
|
|
544
573
|
)
|
|
545
574
|
)
|
|
546
575
|
)
|
|
547
|
-
)
|
|
576
|
+
)
|
|
577
|
+
)
|
|
548
578
|
}
|
|
549
579
|
}
|
|
550
580
|
export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
551
581
|
rawOptions = mergeOptions(rawOptions, type, false)
|
|
552
|
-
const
|
|
582
|
+
const componentsMap = currentInject.componentsMap
|
|
583
|
+
if (rawOptions.components) {
|
|
584
|
+
Object.entries(rawOptions.components).forEach(([key, item]) => {
|
|
585
|
+
componentsMap[key] = () => item
|
|
586
|
+
})
|
|
587
|
+
}
|
|
553
588
|
const validProps = Object.assign({}, rawOptions.props, rawOptions.properties)
|
|
554
589
|
const { hasDescendantRelation, hasAncestorRelation } = checkRelation(rawOptions)
|
|
555
590
|
if (rawOptions.methods) rawOptions.methods = wrapMethodsWithErrorHandling(rawOptions.methods)
|
|
@@ -567,7 +602,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
567
602
|
let isFirst = false
|
|
568
603
|
if (!instanceRef.current) {
|
|
569
604
|
isFirst = true
|
|
570
|
-
instanceRef.current = createInstance({ propsRef, type, rawOptions, currentInject, validProps,
|
|
605
|
+
instanceRef.current = createInstance({ propsRef, type, rawOptions, currentInject, validProps, componentsMap, pageId, intersectionCtx, relation, parentProvides })
|
|
571
606
|
}
|
|
572
607
|
const instance = instanceRef.current
|
|
573
608
|
useImperativeHandle(ref, () => {
|
|
@@ -614,7 +649,6 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
614
649
|
})
|
|
615
650
|
|
|
616
651
|
usePageEffect(proxy, pageId)
|
|
617
|
-
|
|
618
652
|
useEffect(() => {
|
|
619
653
|
proxy.mounted()
|
|
620
654
|
return () => {
|
package/src/platform/env/nav.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { createElement, useState, useMemo } from 'react'
|
|
2
|
-
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
3
|
-
import { StatusBar, processColor, TouchableOpacity, Image, View, StyleSheet, Text } from 'react-native'
|
|
4
|
-
import Mpx from '../../index'
|
|
5
|
-
|
|
6
|
-
function convertToHex (color) {
|
|
7
|
-
try {
|
|
8
|
-
const intColor = processColor(color)
|
|
9
|
-
if (intColor === null || intColor === undefined) {
|
|
10
|
-
return null
|
|
11
|
-
}
|
|
12
|
-
// 将32位整数颜色值转换为RGBA
|
|
13
|
-
const r = (intColor >> 16) & 255
|
|
14
|
-
const g = (intColor >> 8) & 255
|
|
15
|
-
const b = intColor & 255
|
|
16
|
-
// 转换为十六进制
|
|
17
|
-
const hexR = r.toString(16).padStart(2, '0')
|
|
18
|
-
const hexG = g.toString(16).padStart(2, '0')
|
|
19
|
-
const hexB = b.toString(16).padStart(2, '0')
|
|
20
|
-
return `#${hexR}${hexG}${hexB}`
|
|
21
|
-
} catch (error) {
|
|
22
|
-
return null
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const titleHeight = 44
|
|
27
|
-
export function useInnerHeaderHeight (pageconfig) {
|
|
28
|
-
if (pageconfig.navigationStyle === 'custom') {
|
|
29
|
-
return 0
|
|
30
|
-
} else {
|
|
31
|
-
const safeAreaTop = useSafeAreaInsets()?.top || 0
|
|
32
|
-
const headerHeight = safeAreaTop + titleHeight
|
|
33
|
-
return headerHeight
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const styles = StyleSheet.create({
|
|
38
|
-
header: {
|
|
39
|
-
elevation: 3
|
|
40
|
-
},
|
|
41
|
-
headerContent: {
|
|
42
|
-
flexDirection: 'row',
|
|
43
|
-
alignItems: 'center',
|
|
44
|
-
justifyContent: 'center'
|
|
45
|
-
},
|
|
46
|
-
backButton: {
|
|
47
|
-
position: 'absolute',
|
|
48
|
-
height: '100%',
|
|
49
|
-
width: 40,
|
|
50
|
-
left: 0,
|
|
51
|
-
top: 0,
|
|
52
|
-
alignItems: 'center',
|
|
53
|
-
justifyContent: 'center'
|
|
54
|
-
},
|
|
55
|
-
backButtonImage: {
|
|
56
|
-
width: 22,
|
|
57
|
-
height: 22
|
|
58
|
-
},
|
|
59
|
-
title: {
|
|
60
|
-
fontSize: 17,
|
|
61
|
-
fontWeight: 600,
|
|
62
|
-
width: '60%',
|
|
63
|
-
textAlign: 'center'
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
const NavColor = {
|
|
67
|
-
White: '#ffffff',
|
|
68
|
-
Black: '#000000'
|
|
69
|
-
}
|
|
70
|
-
// navigationBarTextStyle只支持黑白'white'/'black
|
|
71
|
-
const validBarTextStyle = (textStyle) => {
|
|
72
|
-
const textStyleColor = convertToHex(textStyle)
|
|
73
|
-
if (textStyle && [NavColor.White, NavColor.Black].includes(textStyleColor)) {
|
|
74
|
-
return textStyleColor
|
|
75
|
-
} else {
|
|
76
|
-
return NavColor.White
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export function innerNav ({ pageConfig, navigation }) {
|
|
80
|
-
const [innerPageConfig, setPageConfig] = useState(pageConfig || {})
|
|
81
|
-
navigation.setPageConfig = (config) => {
|
|
82
|
-
const newConfig = Object.assign({}, innerPageConfig, config)
|
|
83
|
-
setPageConfig(newConfig)
|
|
84
|
-
}
|
|
85
|
-
const isCustom = innerPageConfig.navigationStyle === 'custom'
|
|
86
|
-
const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
|
|
87
|
-
// 状态栏的颜色
|
|
88
|
-
const statusBarElement = createElement(StatusBar, {
|
|
89
|
-
translucent: true,
|
|
90
|
-
backgroundColor: 'transparent',
|
|
91
|
-
barStyle: (navigationBarTextStyle === NavColor.White) ? 'light-content' : 'dark-content' // 'default'/'light-content'/'dark-content'
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
if (isCustom) return statusBarElement
|
|
95
|
-
const safeAreaTop = useSafeAreaInsets()?.top || 0
|
|
96
|
-
// 假设是栈导航,获取栈的长度
|
|
97
|
-
const stackLength = navigation.getState()?.routes?.length
|
|
98
|
-
const stackTopConfig = Mpx.config?.rnConfig?.stackTopConfig || {}
|
|
99
|
-
|
|
100
|
-
// 回退按钮与图标
|
|
101
|
-
const backElement = stackLength > 1 || stackTopConfig.show
|
|
102
|
-
? createElement(TouchableOpacity, {
|
|
103
|
-
style: [styles.backButton],
|
|
104
|
-
onPress: () => {
|
|
105
|
-
navigation.goBack()
|
|
106
|
-
if (stackLength <= 1 && stackTopConfig.show && typeof stackTopConfig.listener === 'function') {
|
|
107
|
-
stackTopConfig.listener?.()
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}, createElement(Image, {
|
|
111
|
-
source: { uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg==' },
|
|
112
|
-
// 回退按钮的颜色与设置的title文案颜色一致
|
|
113
|
-
style: [styles.backButtonImage, { tintColor: navigationBarTextStyle }]
|
|
114
|
-
}))
|
|
115
|
-
: null
|
|
116
|
-
|
|
117
|
-
return createElement(View, {
|
|
118
|
-
style: [styles.header, {
|
|
119
|
-
paddingTop: safeAreaTop,
|
|
120
|
-
backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
|
|
121
|
-
}]
|
|
122
|
-
},
|
|
123
|
-
statusBarElement,
|
|
124
|
-
createElement(View, {
|
|
125
|
-
style: styles.headerContent,
|
|
126
|
-
height: titleHeight
|
|
127
|
-
}, backElement,
|
|
128
|
-
createElement(Text, {
|
|
129
|
-
style: [styles.title, { color: navigationBarTextStyle }],
|
|
130
|
-
numberOfLines: 1
|
|
131
|
-
}, innerPageConfig.navigationBarTitleText?.trim() || ''))
|
|
132
|
-
)
|
|
133
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|