@mpxjs/webpack-plugin 2.10.14-beta.4 → 2.10.14-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/lib/platform/template/wx/component-config/index.js +3 -1
- package/lib/platform/template/wx/component-config/nav-container.js +27 -0
- package/lib/runtime/components/ali/mpx-nav-container.mpx +3 -0
- package/lib/runtime/components/react/context.ts +17 -6
- package/lib/runtime/components/react/dist/context.d.ts +78 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +49 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +28 -9
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +52 -51
- package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +63 -0
- package/lib/runtime/components/react/dist/mpx-nav-container.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-nav-container.jsx +23 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +52 -0
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts +34 -0
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
- package/lib/runtime/components/react/dist/nav.d.ts +8 -0
- package/lib/runtime/components/react/dist/nav.jsx +137 -0
- package/lib/runtime/components/react/dist/parser.d.ts +39 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +32 -0
- package/lib/runtime/components/react/dist/useNavShared.d.ts +2 -0
- package/lib/runtime/components/react/dist/useNavShared.js +6 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
- package/lib/runtime/components/react/dist/utils.d.ts +122 -0
- package/lib/runtime/components/react/mpx-input.tsx +35 -16
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +58 -59
- package/lib/runtime/components/react/mpx-nav-container.tsx +33 -0
- package/lib/runtime/components/react/nav.tsx +163 -0
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/useNavShared.ts +8 -0
- package/lib/runtime/components/web/mpx-nav-container.vue +13 -0
- package/lib/runtime/components/wx/mpx-nav-container.mpx +9 -0
- package/lib/utils/dom-tag-config.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* eslint-disable space-before-function-paren */
|
|
2
|
+
import { createElement, useState, useMemo, memo, useContext, useLayoutEffect } from 'react'
|
|
3
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
4
|
+
import { StatusBar, processColor, TouchableWithoutFeedback, Image, View, StyleSheet, Text } from 'react-native'
|
|
5
|
+
import { useNavShared } from './useNavShared'
|
|
6
|
+
|
|
7
|
+
function convertToHex(color?: string) {
|
|
8
|
+
try {
|
|
9
|
+
const intColor = processColor(color) as number | null | undefined
|
|
10
|
+
if (intColor === null || intColor === undefined) {
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
// 将32位整数颜色值转换为RGBA
|
|
14
|
+
const r = (intColor >> 16) & 255
|
|
15
|
+
const g = (intColor >> 8) & 255
|
|
16
|
+
const b = intColor & 255
|
|
17
|
+
// 转换为十六进制
|
|
18
|
+
const hexR = r.toString(16).padStart(2, '0')
|
|
19
|
+
const hexG = g.toString(16).padStart(2, '0')
|
|
20
|
+
const hexB = b.toString(16).padStart(2, '0')
|
|
21
|
+
return `#${hexR}${hexG}${hexB}`
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const titleHeight = 44
|
|
28
|
+
export function useInnerHeaderHeight(pageConfig: PageConfig) {
|
|
29
|
+
const safeArea = useSafeAreaInsets()
|
|
30
|
+
if (pageConfig.navigationStyle === 'custom') {
|
|
31
|
+
return 0
|
|
32
|
+
} else {
|
|
33
|
+
const safeAreaTop = safeArea?.top || 0
|
|
34
|
+
const headerHeight = safeAreaTop + titleHeight
|
|
35
|
+
return headerHeight
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const styles = StyleSheet.create({
|
|
40
|
+
header: {
|
|
41
|
+
elevation: 3
|
|
42
|
+
},
|
|
43
|
+
headerContent: {
|
|
44
|
+
flexDirection: 'row',
|
|
45
|
+
alignItems: 'center',
|
|
46
|
+
justifyContent: 'center'
|
|
47
|
+
},
|
|
48
|
+
backButton: {
|
|
49
|
+
position: 'absolute',
|
|
50
|
+
height: '100%',
|
|
51
|
+
width: 40,
|
|
52
|
+
left: 0,
|
|
53
|
+
top: 0,
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
justifyContent: 'center'
|
|
56
|
+
},
|
|
57
|
+
backButtonImage: {
|
|
58
|
+
width: 22,
|
|
59
|
+
height: 22
|
|
60
|
+
},
|
|
61
|
+
title: {
|
|
62
|
+
fontSize: 17,
|
|
63
|
+
fontWeight: 600,
|
|
64
|
+
width: '60%',
|
|
65
|
+
textAlign: 'center'
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
const NavColor = {
|
|
69
|
+
White: '#ffffff',
|
|
70
|
+
Black: '#000000'
|
|
71
|
+
}
|
|
72
|
+
// navigationBarTextStyle 只支持黑白 'white'/'black
|
|
73
|
+
const validBarTextStyle = (textStyle?: string) => {
|
|
74
|
+
const textStyleColor = convertToHex(textStyle)
|
|
75
|
+
if (textStyle && textStyleColor && [NavColor.White, NavColor.Black].includes(textStyleColor)) {
|
|
76
|
+
return textStyleColor
|
|
77
|
+
} else {
|
|
78
|
+
return NavColor.White
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface MpxNavProps {
|
|
83
|
+
pageConfig: PageConfig
|
|
84
|
+
navigation: any
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const BACK_ICON =
|
|
88
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg=='
|
|
89
|
+
|
|
90
|
+
const MpxNav = memo(({ pageConfig, navigation }: MpxNavProps) => {
|
|
91
|
+
const [innerPageConfig, setPageConfig] = useState<PageConfig>(pageConfig || {})
|
|
92
|
+
const [customNav] = useNavShared()
|
|
93
|
+
const safeAreaTop = useSafeAreaInsets()?.top || 0
|
|
94
|
+
|
|
95
|
+
navigation.setPageConfig = (config: PageConfig) => {
|
|
96
|
+
setPageConfig(Object.assign({}, innerPageConfig, config))
|
|
97
|
+
}
|
|
98
|
+
const isCustom = innerPageConfig.navigationStyle === 'custom'
|
|
99
|
+
const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
|
|
100
|
+
// 状态栏的颜色
|
|
101
|
+
const statusBarElement = (
|
|
102
|
+
<StatusBar
|
|
103
|
+
translucent
|
|
104
|
+
backgroundColor='transparent'
|
|
105
|
+
barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
if (isCustom)
|
|
109
|
+
return (
|
|
110
|
+
<>
|
|
111
|
+
{statusBarElement}
|
|
112
|
+
{customNav}
|
|
113
|
+
</>
|
|
114
|
+
)
|
|
115
|
+
// 假设是栈导航,获取栈的长度
|
|
116
|
+
const stackLength = navigation.getState()?.routes?.length
|
|
117
|
+
const onStackTopBack = mpxGlobal?.__mpx?.config?.rnConfig?.onStackTopBack
|
|
118
|
+
const isHandleStackTopBack = typeof onStackTopBack === 'function'
|
|
119
|
+
|
|
120
|
+
// 回退按钮与图标
|
|
121
|
+
// prettier-ignore
|
|
122
|
+
const backElement = stackLength > 1 || isHandleStackTopBack
|
|
123
|
+
? (
|
|
124
|
+
<TouchableWithoutFeedback
|
|
125
|
+
onPress={() => {
|
|
126
|
+
if (stackLength <= 1 && isHandleStackTopBack) {
|
|
127
|
+
onStackTopBack()
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
navigation.goBack()
|
|
131
|
+
}}>
|
|
132
|
+
<View style={[styles.backButton]}>
|
|
133
|
+
<Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
|
|
134
|
+
</View>
|
|
135
|
+
</TouchableWithoutFeedback>
|
|
136
|
+
)
|
|
137
|
+
: null
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<View
|
|
141
|
+
style={[
|
|
142
|
+
styles.header,
|
|
143
|
+
{
|
|
144
|
+
paddingTop: safeAreaTop,
|
|
145
|
+
backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
|
|
146
|
+
}
|
|
147
|
+
]}>
|
|
148
|
+
{statusBarElement}
|
|
149
|
+
{/* TODO: 确定 height 的有效性 */}
|
|
150
|
+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
|
|
151
|
+
{/* @ts-expect-error */}
|
|
152
|
+
<View style={styles.headerContent} height={titleHeight}>
|
|
153
|
+
{backElement}
|
|
154
|
+
<Text style={[styles.title, { color: navigationBarTextStyle }]} numberOfLines={1}>
|
|
155
|
+
{innerPageConfig.navigationBarTitleText?.trim() || ''}
|
|
156
|
+
</Text>
|
|
157
|
+
</View>
|
|
158
|
+
</View>
|
|
159
|
+
)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
MpxNav.displayName = 'MpxNav'
|
|
163
|
+
export default MpxNav
|
|
@@ -18,3 +18,22 @@ export type ExtendedFunctionComponent = FunctionComponent & {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export type AnyFunc = (...args: ReadonlyArray<any>) => any
|
|
21
|
+
|
|
22
|
+
declare global {
|
|
23
|
+
interface PageConfig {
|
|
24
|
+
/**
|
|
25
|
+
* 是否自定义导航栏
|
|
26
|
+
*/
|
|
27
|
+
navigationStyle?: 'custom'
|
|
28
|
+
/**
|
|
29
|
+
* 标题栏样式
|
|
30
|
+
*/
|
|
31
|
+
navigationBarTextStyle?: 'white' | 'black' | '#ffffff' | '#000000'
|
|
32
|
+
/**
|
|
33
|
+
* 页面标题
|
|
34
|
+
*/
|
|
35
|
+
navigationBarTitleText?: string
|
|
36
|
+
|
|
37
|
+
[key: string]: any
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -78,7 +78,7 @@ const isBuildInWebTag = makeMap(
|
|
|
78
78
|
'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
|
|
79
79
|
'mpx-switch,mpx-web-view,mpx-checkbox,mpx-movable-view,mpx-radio,' +
|
|
80
80
|
'mpx-tab-bar-container,mpx-form,mpx-navigator,mpx-rich-text,mpx-tab-bar,' +
|
|
81
|
-
'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
|
|
81
|
+
'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text,mpx-nav-container'
|
|
82
82
|
)
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -91,7 +91,7 @@ const isBuildInReactTag = makeMap(
|
|
|
91
91
|
'mpx-movable-area,mpx-label,mpx-keyboard-avoiding-view,mpx-input,mpx-inline-text,' +
|
|
92
92
|
'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
|
|
93
93
|
'mpx-rich-text,mpx-portal,mpx-popup,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
|
|
94
|
-
'mpx-icon,mpx-canvas'
|
|
94
|
+
'mpx-icon,mpx-canvas,mpx-nav-container'
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
const isSpace = makeMap('ensp,emsp,nbsp')
|