@mpxjs/core 2.10.7-beta.2 → 2.10.7-beta.6

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.10.7-beta.2",
3
+ "version": "2.10.7-beta.6",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -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 {
@@ -9,8 +9,7 @@ import { watch } from '../observer/watch'
9
9
  import { createElement, memo, useRef, useEffect } from 'react'
10
10
  import * as ReactNative from 'react-native'
11
11
  import { initAppProvides } from './export/inject'
12
- import { NavigationContainer, createNativeStackNavigator, SafeAreaProvider, GestureHandlerRootView } from './env/navigationHelper'
13
- import { innerNav } from './env/nav'
12
+ import { NavigationContainer, createNativeStackNavigator, SafeAreaProvider } from './env/navigationHelper'
14
13
 
15
14
  const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)
16
15
 
@@ -56,40 +55,23 @@ export default function createApp (options) {
56
55
  const pages = currentInject.getPages() || {}
57
56
  const firstPage = currentInject.firstPage
58
57
  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
58
  const getPageScreens = (initialRouteName, initialParams) => {
76
59
  return Object.entries(pages).map(([key, item]) => {
77
60
  // const options = {
78
61
  // // __mpxPageStatusMap 为编译注入的全局变量
79
62
  // headerShown: !(Object.assign({}, global.__mpxPageConfig, global.__mpxPageConfigsMap[key]).navigationStyle === 'custom')
80
63
  // }
81
- const pageConfig = Object.assign({}, global.__mpxPageConfig, global.__mpxPageConfigsMap[key])
82
64
  if (key === initialRouteName) {
83
65
  return createElement(Stack.Screen, {
84
66
  name: key,
85
- component: withHeader(item, { pageConfig }),
67
+ component: item,
86
68
  initialParams
87
69
  // options
88
70
  })
89
71
  }
90
72
  return createElement(Stack.Screen, {
91
73
  name: key,
92
- component: withHeader(item, { pageConfig })
74
+ component: item
93
75
  // options
94
76
  })
95
77
  })
@@ -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
- }
@@ -1,11 +1,11 @@
1
1
  import { createElement, useState, useMemo } from 'react'
2
2
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
3
- import { StatusBar, processColor, TouchableOpacity, Image, View, StyleSheet, Text } from 'react-native'
3
+ import * as ReactNative from 'react-native'
4
4
  import Mpx from '../../index'
5
5
 
6
6
  function convertToHex (color) {
7
7
  try {
8
- const intColor = processColor(color)
8
+ const intColor = ReactNative.processColor(color)
9
9
  if (intColor === null || intColor === undefined) {
10
10
  return null
11
11
  }
@@ -34,7 +34,7 @@ export function useInnerHeaderHeight (pageconfig) {
34
34
  }
35
35
  }
36
36
 
37
- const styles = StyleSheet.create({
37
+ const styles = ReactNative.StyleSheet.create({
38
38
  header: {
39
39
  elevation: 3
40
40
  },
@@ -76,7 +76,8 @@ const validBarTextStyle = (textStyle) => {
76
76
  return NavColor.White
77
77
  }
78
78
  }
79
- export function innerNav ({ pageConfig, navigation }) {
79
+ export function innerNav ({ props, navigation }) {
80
+ const { pageConfig } = props
80
81
  const [innerPageConfig, setPageConfig] = useState(pageConfig || {})
81
82
  navigation.setPageConfig = (config) => {
82
83
  const newConfig = Object.assign({}, innerPageConfig, config)
@@ -85,7 +86,7 @@ export function innerNav ({ pageConfig, navigation }) {
85
86
  const isCustom = innerPageConfig.navigationStyle === 'custom'
86
87
  const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
87
88
  // 状态栏的颜色
88
- const statusBarElement = createElement(StatusBar, {
89
+ const statusBarElement = createElement(ReactNative.StatusBar, {
89
90
  translucent: true,
90
91
  backgroundColor: 'transparent',
91
92
  barStyle: (navigationBarTextStyle === NavColor.White) ? 'light-content' : 'dark-content' // 'default'/'light-content'/'dark-content'
@@ -100,28 +101,28 @@ export function innerNav ({ pageConfig, navigation }) {
100
101
 
101
102
  // 回退按钮与图标
102
103
  const backElement = stackLength + beforeStackLength > 1
103
- ? createElement(TouchableOpacity, {
104
+ ? createElement(ReactNative.TouchableOpacity, {
104
105
  style: [styles.backButton],
105
106
  onPress: () => { navigation.goBack() }
106
- }, createElement(Image, {
107
+ }, createElement(ReactNative.Image, {
107
108
  source: { uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg==' },
108
109
  // 回退按钮的颜色与设置的title文案颜色一致
109
110
  style: [styles.backButtonImage, { tintColor: navigationBarTextStyle }]
110
111
  }))
111
112
  : null
112
113
 
113
- return createElement(View, {
114
+ return createElement(ReactNative.View, {
114
115
  style: [styles.header, {
115
116
  paddingTop: safeAreaTop,
116
117
  backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
117
118
  }]
118
119
  },
119
120
  statusBarElement,
120
- createElement(View, {
121
+ createElement(ReactNative.View, {
121
122
  style: styles.headerContent,
122
123
  height: titleHeight
123
124
  }, backElement,
124
- createElement(Text, {
125
+ createElement(ReactNative.Text, {
125
126
  style: [styles.title, { color: navigationBarTextStyle }],
126
127
  numberOfLines: 1
127
128
  }, innerPageConfig.navigationBarTitleText?.trim() || ''))
@@ -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
+ }
@@ -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 } from '../env/navigationHelper'
19
- import { useInnerHeaderHeight } from '../env/nav'
18
+ import { PortalHost, useSafeAreaInsets, GestureHandlerRootView } from '../env/navigationHelper'
19
+ import { innerNav, useInnerHeaderHeight } from '../env/nav'
20
20
 
21
21
  const ProviderContext = createContext(null)
22
22
  function getSystemInfo () {
@@ -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,49 @@ export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
524
506
  }
525
507
  // android存在第一次打开insets都返回为0情况,后续会触发第二次渲染后正确
526
508
  navigation.insets = useSafeAreaInsets()
527
- return withKeyboardAvoidingView(
528
- createElement(ReactNative.View,
529
- {
530
- style: {
531
- flex: 1,
532
- backgroundColor: currentPageConfig?.backgroundColor || '#fff',
533
- // 解决页面内有元素定位relative left为负值的时候,回退的时候还能看到对应元素问题
534
- overflow: 'hidden'
535
- },
536
- ref: rootRef
537
- },
538
- createElement(RouteContext.Provider,
509
+ return createElement(GestureHandlerRootView,
510
+ {
511
+ style: {
512
+ flex: 1
513
+ }
514
+ },
515
+ createElement(innerNav, {
516
+ props: { pageConfig: currentPageConfig },
517
+ navigation
518
+ }),
519
+ withKeyboardAvoidingView(
520
+ createElement(ReactNative.View,
539
521
  {
540
- value: routeContextValRef.current
522
+ style: {
523
+ flex: 1,
524
+ backgroundColor: currentPageConfig?.backgroundColor || '#fff',
525
+ // 解决页面内有元素定位relative left为负值的时候,回退的时候还能看到对应元素问题
526
+ overflow: 'hidden'
527
+ },
528
+ ref: rootRef,
529
+ onLayout
541
530
  },
542
- createElement(IntersectionObserverContext.Provider,
531
+ createElement(RouteContext.Provider,
543
532
  {
544
- value: intersectionObservers.current
533
+ value: routeContextValRef.current
545
534
  },
546
- createElement(PortalHost,
547
- null,
548
- createElement(WrappedComponent, {
549
- ...props,
550
- navigation,
551
- route,
552
- id: currentPageId
553
- })
535
+ createElement(IntersectionObserverContext.Provider,
536
+ {
537
+ value: intersectionObservers.current
538
+ },
539
+ createElement(PortalHost,
540
+ null,
541
+ createElement(WrappedComponent, {
542
+ ...props,
543
+ navigation,
544
+ route,
545
+ id: currentPageId
546
+ })
547
+ )
554
548
  )
555
549
  )
556
550
  )
557
- )
558
- )
551
+ ))
559
552
  }
560
553
  }
561
554
  export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
@@ -625,6 +618,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
625
618
  })
626
619
 
627
620
  usePageEffect(proxy, pageId)
621
+
628
622
  useEffect(() => {
629
623
  proxy.mounted()
630
624
  return () => {