@mpxjs/core 2.10.7-beta.6 → 2.10.7-beta.8
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
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,27 @@ 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
|
+
stackTopConfig?: {
|
|
272
|
+
/** 是否展示回退按钮 */
|
|
273
|
+
show?: boolean,
|
|
274
|
+
/** 监听回退按钮点击 */
|
|
275
|
+
listener?: Function
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
263
279
|
interface MpxConfig {
|
|
264
280
|
useStrictDiff: boolean
|
|
265
281
|
ignoreWarning: boolean | string | RegExp | ((msg: string, location: string, e: Error) => boolean)
|
|
@@ -272,8 +288,14 @@ interface MpxConfig {
|
|
|
272
288
|
forceFlushSync: boolean,
|
|
273
289
|
webRouteConfig: object,
|
|
274
290
|
webConfig: object,
|
|
291
|
+
/*
|
|
292
|
+
* 支持两个属性
|
|
293
|
+
* hostWhitelists Array 类型 支持h5域名白名单安全校验
|
|
294
|
+
* apiImplementations webview JSSDK接口 例如getlocation
|
|
295
|
+
*/
|
|
275
296
|
webviewConfig: WebviewConfig,
|
|
276
|
-
|
|
297
|
+
/** react-native 相关配置,用于挂载事件等,如 onShareAppMessage */
|
|
298
|
+
rnConfig?: RnConfig,
|
|
277
299
|
}
|
|
278
300
|
|
|
279
301
|
type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'
|
|
@@ -664,9 +686,15 @@ export const SERVERPREFETCH: string
|
|
|
664
686
|
export const REACTHOOKSEXEC: string
|
|
665
687
|
|
|
666
688
|
declare global {
|
|
689
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
690
|
+
// @ts-expect-error
|
|
667
691
|
const defineProps: (<T extends Properties = {}>(props: T) => Readonly<GetPropsType<T>>) & (<T>() => Readonly<T>)
|
|
668
692
|
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
|
|
693
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
694
|
+
// @ts-expect-error
|
|
669
695
|
const defineExpose: <E extends AnyObject = AnyObject>(exposed?: E) => void
|
|
670
696
|
const useContext: () => Context
|
|
697
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
698
|
+
// @ts-expect-error
|
|
671
699
|
const withDefaults: <Props, Defaults extends InferDefaults<Props>>(props: Props, defaults: Defaults) => PropsWithDefaults<Props, Defaults>
|
|
672
700
|
}
|
package/package.json
CHANGED
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 = {
|
|
@@ -9,7 +9,8 @@ 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 } from './env/navigationHelper'
|
|
12
|
+
import { NavigationContainer, createNativeStackNavigator, SafeAreaProvider, GestureHandlerRootView } from './env/navigationHelper'
|
|
13
|
+
import { innerNav } from './env/nav'
|
|
13
14
|
|
|
14
15
|
const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)
|
|
15
16
|
|
|
@@ -55,23 +56,40 @@ export default function createApp (options) {
|
|
|
55
56
|
const pages = currentInject.getPages() || {}
|
|
56
57
|
const firstPage = currentInject.firstPage
|
|
57
58
|
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
|
+
}
|
|
58
75
|
const getPageScreens = (initialRouteName, initialParams) => {
|
|
59
76
|
return Object.entries(pages).map(([key, item]) => {
|
|
60
77
|
// const options = {
|
|
61
78
|
// // __mpxPageStatusMap 为编译注入的全局变量
|
|
62
79
|
// headerShown: !(Object.assign({}, global.__mpxPageConfig, global.__mpxPageConfigsMap[key]).navigationStyle === 'custom')
|
|
63
80
|
// }
|
|
81
|
+
const pageConfig = Object.assign({}, global.__mpxPageConfig, global.__mpxPageConfigsMap[key])
|
|
64
82
|
if (key === initialRouteName) {
|
|
65
83
|
return createElement(Stack.Screen, {
|
|
66
84
|
name: key,
|
|
67
|
-
component: item,
|
|
85
|
+
component: withHeader(item, { pageConfig }),
|
|
68
86
|
initialParams
|
|
69
87
|
// options
|
|
70
88
|
})
|
|
71
89
|
}
|
|
72
90
|
return createElement(Stack.Screen, {
|
|
73
91
|
name: key,
|
|
74
|
-
component: item
|
|
92
|
+
component: withHeader(item, { pageConfig })
|
|
75
93
|
// options
|
|
76
94
|
})
|
|
77
95
|
})
|
package/src/platform/env/nav.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createElement, useState, useMemo } from 'react'
|
|
2
2
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
3
|
-
import
|
|
3
|
+
import { StatusBar, processColor, TouchableOpacity, Image, View, StyleSheet, Text } from 'react-native'
|
|
4
4
|
import Mpx from '../../index'
|
|
5
5
|
|
|
6
6
|
function convertToHex (color) {
|
|
7
7
|
try {
|
|
8
|
-
const intColor =
|
|
8
|
+
const intColor = 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 =
|
|
37
|
+
const styles = StyleSheet.create({
|
|
38
38
|
header: {
|
|
39
39
|
elevation: 3
|
|
40
40
|
},
|
|
@@ -76,8 +76,7 @@ const validBarTextStyle = (textStyle) => {
|
|
|
76
76
|
return NavColor.White
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
export function innerNav ({
|
|
80
|
-
const { pageConfig } = props
|
|
79
|
+
export function innerNav ({ pageConfig, navigation }) {
|
|
81
80
|
const [innerPageConfig, setPageConfig] = useState(pageConfig || {})
|
|
82
81
|
navigation.setPageConfig = (config) => {
|
|
83
82
|
const newConfig = Object.assign({}, innerPageConfig, config)
|
|
@@ -86,7 +85,7 @@ export function innerNav ({ props, navigation }) {
|
|
|
86
85
|
const isCustom = innerPageConfig.navigationStyle === 'custom'
|
|
87
86
|
const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
|
|
88
87
|
// 状态栏的颜色
|
|
89
|
-
const statusBarElement = createElement(
|
|
88
|
+
const statusBarElement = createElement(StatusBar, {
|
|
90
89
|
translucent: true,
|
|
91
90
|
backgroundColor: 'transparent',
|
|
92
91
|
barStyle: (navigationBarTextStyle === NavColor.White) ? 'light-content' : 'dark-content' // 'default'/'light-content'/'dark-content'
|
|
@@ -96,33 +95,37 @@ export function innerNav ({ props, navigation }) {
|
|
|
96
95
|
const safeAreaTop = useSafeAreaInsets()?.top || 0
|
|
97
96
|
// 假设是栈导航,获取栈的长度
|
|
98
97
|
const stackLength = navigation.getState()?.routes?.length
|
|
99
|
-
|
|
100
|
-
const beforeStackLength = Mpx.config?.rnConfig?.beforeStackLength || 0
|
|
98
|
+
const stackTopConfig = Mpx.config?.rnConfig?.stackTopConfig || {}
|
|
101
99
|
|
|
102
100
|
// 回退按钮与图标
|
|
103
|
-
const backElement = stackLength
|
|
104
|
-
? createElement(
|
|
101
|
+
const backElement = stackLength > 1 || stackTopConfig.show
|
|
102
|
+
? createElement(TouchableOpacity, {
|
|
105
103
|
style: [styles.backButton],
|
|
106
|
-
onPress: () => {
|
|
107
|
-
|
|
104
|
+
onPress: () => {
|
|
105
|
+
navigation.goBack()
|
|
106
|
+
if (stackLength <= 1 && stackTopConfig.show && typeof stackTopConfig.listener === 'function') {
|
|
107
|
+
stackTopConfig.listener?.()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}, createElement(Image, {
|
|
108
111
|
source: { uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg==' },
|
|
109
112
|
// 回退按钮的颜色与设置的title文案颜色一致
|
|
110
113
|
style: [styles.backButtonImage, { tintColor: navigationBarTextStyle }]
|
|
111
114
|
}))
|
|
112
115
|
: null
|
|
113
116
|
|
|
114
|
-
return createElement(
|
|
117
|
+
return createElement(View, {
|
|
115
118
|
style: [styles.header, {
|
|
116
119
|
paddingTop: safeAreaTop,
|
|
117
120
|
backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
|
|
118
121
|
}]
|
|
119
122
|
},
|
|
120
123
|
statusBarElement,
|
|
121
|
-
createElement(
|
|
124
|
+
createElement(View, {
|
|
122
125
|
style: styles.headerContent,
|
|
123
126
|
height: titleHeight
|
|
124
127
|
}, backElement,
|
|
125
|
-
createElement(
|
|
128
|
+
createElement(Text, {
|
|
126
129
|
style: [styles.title, { color: navigationBarTextStyle }],
|
|
127
130
|
numberOfLines: 1
|
|
128
131
|
}, innerPageConfig.navigationBarTitleText?.trim() || ''))
|
|
@@ -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) {
|