@mpxjs/webpack-plugin 2.10.6-beta.7 → 2.10.6-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.
Files changed (79) hide show
  1. package/lib/runtime/components/react/context.ts +8 -3
  2. package/lib/runtime/components/react/dist/AsyncSuspense.d.ts +16 -0
  3. package/lib/runtime/components/react/dist/context.d.ts +74 -0
  4. package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
  5. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
  6. package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
  7. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
  8. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
  9. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
  10. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
  11. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
  12. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
  13. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
  14. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
  15. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
  16. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
  17. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
  18. package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
  19. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
  20. package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
  21. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
  22. package/lib/runtime/components/react/dist/mpx-input.d.ts +49 -0
  23. package/lib/runtime/components/react/dist/mpx-input.jsx +30 -9
  24. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
  25. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +63 -28
  26. package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
  27. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
  28. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +61 -0
  29. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
  30. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
  31. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
  32. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
  33. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
  34. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
  35. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
  36. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
  37. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
  38. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
  39. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +31 -0
  40. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
  41. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +22 -0
  42. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
  43. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
  44. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
  46. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
  47. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
  48. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
  49. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
  50. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
  51. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
  52. package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
  53. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
  54. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
  55. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
  56. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +53 -0
  57. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
  58. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
  59. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
  60. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
  61. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
  62. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
  63. package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
  64. package/lib/runtime/components/react/dist/mpx-text.d.ts +21 -0
  65. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
  66. package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
  67. package/lib/runtime/components/react/dist/mpx-view.d.ts +34 -0
  68. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
  69. package/lib/runtime/components/react/dist/nav.d.ts +11 -0
  70. package/lib/runtime/components/react/dist/nav.jsx +189 -0
  71. package/lib/runtime/components/react/dist/parser.d.ts +39 -0
  72. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +32 -0
  73. package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
  74. package/lib/runtime/components/react/dist/utils.d.ts +121 -0
  75. package/lib/runtime/components/react/mpx-input.tsx +36 -16
  76. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +68 -28
  77. package/lib/runtime/components/react/nav.tsx +219 -0
  78. package/lib/runtime/components/react/types/common.d.ts +19 -0
  79. package/package.json +1 -1
@@ -0,0 +1,219 @@
1
+ /* eslint-disable space-before-function-paren */
2
+ import { createElement, useState, useMemo, memo } 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 Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated'
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
+ export interface MpxNavFactorOptions {
88
+ Mpx: any
89
+ }
90
+
91
+ const BACK_ICON =
92
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg=='
93
+
94
+ function createMpxNav(options: MpxNavFactorOptions) {
95
+ const { Mpx } = options
96
+ const innerNav = memo(({ pageConfig, navigation }: MpxNavProps) => {
97
+ const [innerPageConfig, setPageConfig] = useState<PageConfig>(pageConfig || {})
98
+
99
+ const translateY = useSharedValue(0)
100
+ const safeAreaTop = useSafeAreaInsets()?.top || 0
101
+
102
+ const animatedStyle = useAnimatedStyle(() => ({
103
+ transform: [{ translateY: translateY.value }]
104
+ }))
105
+
106
+ navigation.setPageConfig = (config: PageConfig) => {
107
+ const newConfig = Object.assign({}, innerPageConfig, config)
108
+ translateY.value =
109
+ newConfig?.animatedNavStyle?.top ?? withTiming(0, { duration: 100, easing: Easing.in(Easing.bezierFn(0.51, 1.18, 0.97, 0.94)) })
110
+ setPageConfig(newConfig)
111
+ }
112
+ const isCustom = innerPageConfig.navigationStyle === 'custom'
113
+ const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
114
+ // 状态栏的颜色
115
+ const statusBarElement = (
116
+ <StatusBar
117
+ translucent
118
+ backgroundColor='transparent'
119
+ barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>
120
+ )
121
+ createElement(StatusBar, {
122
+ translucent: true,
123
+ backgroundColor: 'transparent',
124
+ barStyle: navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content' // 'default'/'light-content'/'dark-content'
125
+ })
126
+
127
+ if (isCustom) return statusBarElement
128
+ // 假设是栈导航,获取栈的长度
129
+ const stackLength = navigation.getState()?.routes?.length
130
+ const onStackTopBack = Mpx.config?.rnConfig?.onStackTopBack
131
+ const isHandleStackTopBack = typeof onStackTopBack === 'function'
132
+
133
+ // 回退按钮与图标
134
+ // prettier-ignore
135
+ const backElement = stackLength > 1 || isHandleStackTopBack
136
+ ? (
137
+ <TouchableWithoutFeedback
138
+ onPress={() => {
139
+ if (stackLength <= 1 && isHandleStackTopBack) {
140
+ onStackTopBack()
141
+ return
142
+ }
143
+ navigation.goBack()
144
+ }}>
145
+ <View style={[styles.backButton]}>
146
+ <Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
147
+ </View>
148
+ </TouchableWithoutFeedback>
149
+ )
150
+ : null
151
+
152
+ return (
153
+ // 不设置 zIndex transform 无法生效
154
+ <Animated.View style={[{ position: 'relative', zIndex: 10000 }, animatedStyle]}>
155
+ <View
156
+ style={[
157
+ styles.header,
158
+ {
159
+ paddingTop: safeAreaTop,
160
+ backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
161
+ }
162
+ ]}>
163
+ {statusBarElement}
164
+ {/* TODO: 确定 height 的有效性 */}
165
+ {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
166
+ {/* @ts-expect-error */}
167
+ <View style={styles.headerContent} height={titleHeight}>
168
+ {backElement}
169
+ <Text style={[styles.title, { color: navigationBarTextStyle }]} numberOfLines={1}>
170
+ {innerPageConfig.navigationBarTitleText?.trim() || ''}
171
+ </Text>
172
+ </View>
173
+ </View>
174
+ </Animated.View>
175
+ )
176
+
177
+ // return createElement(
178
+ // Animated.View,
179
+ // {
180
+ // style: [animatedStyle]
181
+ // },
182
+ // createElement(
183
+ // View,
184
+ // {
185
+ // style: [
186
+ // styles.header,
187
+ // {
188
+ // paddingTop: safeAreaTop,
189
+ // backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
190
+ // },
191
+ // innerPageConfig.navStyle ?? {}
192
+ // ]
193
+ // },
194
+ // statusBarElement,
195
+ // createElement(
196
+ // View,
197
+ // {
198
+ // style: styles.headerContent,
199
+ // height: titleHeight
200
+ // },
201
+ // backElement,
202
+ // createElement(
203
+ // Text,
204
+ // {
205
+ // style: [styles.title, { color: navigationBarTextStyle }],
206
+ // numberOfLines: 1
207
+ // },
208
+ // innerPageConfig.navigationBarTitleText?.trim() || ''
209
+ // )
210
+ // )
211
+ // )
212
+ // )
213
+ })
214
+
215
+ innerNav.displayName = 'MpxNav'
216
+ return innerNav
217
+ }
218
+
219
+ export default createMpxNav
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.6-beta.7",
3
+ "version": "2.10.6-beta.8",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"