@mpxjs/webpack-plugin 2.9.62 → 2.9.65

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 (95) hide show
  1. package/lib/config.js +38 -10
  2. package/lib/index.js +1 -3
  3. package/lib/platform/style/wx/index.js +115 -66
  4. package/lib/platform/template/wx/index.js +12 -8
  5. package/lib/react/processStyles.js +1 -0
  6. package/lib/react/processTemplate.js +2 -3
  7. package/lib/react/style-helper.js +9 -7
  8. package/lib/runtime/components/react/context.ts +9 -7
  9. package/lib/runtime/components/react/dist/context.js +1 -0
  10. package/lib/runtime/components/react/dist/getInnerListeners.js +12 -1
  11. package/lib/runtime/components/react/dist/mpx-button.jsx +53 -74
  12. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +20 -18
  13. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -42
  14. package/lib/runtime/components/react/dist/mpx-form.jsx +18 -15
  15. package/lib/runtime/components/react/dist/mpx-icon.jsx +15 -17
  16. package/lib/runtime/components/react/dist/mpx-image/index.jsx +36 -34
  17. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
  18. package/lib/runtime/components/react/dist/mpx-input.jsx +36 -31
  19. package/lib/runtime/components/react/dist/mpx-label.jsx +30 -37
  20. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +15 -19
  21. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +10 -9
  22. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +2 -1
  23. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +11 -10
  24. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +9 -5
  25. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +13 -8
  26. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +3 -2
  27. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +22 -20
  28. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +103 -10
  29. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +149 -54
  30. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +20 -18
  31. package/lib/runtime/components/react/dist/mpx-radio.jsx +29 -43
  32. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
  33. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +36 -27
  34. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +141 -75
  35. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +16 -7
  36. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +20 -11
  37. package/lib/runtime/components/react/dist/mpx-switch.jsx +18 -14
  38. package/lib/runtime/components/react/dist/mpx-text.jsx +20 -35
  39. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  40. package/lib/runtime/components/react/dist/mpx-view.jsx +296 -210
  41. package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -7
  42. package/lib/runtime/components/react/dist/parser.js +218 -0
  43. package/lib/runtime/components/react/dist/useNodesRef.js +1 -5
  44. package/lib/runtime/components/react/dist/utils.jsx +445 -0
  45. package/lib/runtime/components/react/getInnerListeners.ts +18 -8
  46. package/lib/runtime/components/react/mpx-button.tsx +83 -91
  47. package/lib/runtime/components/react/mpx-checkbox-group.tsx +50 -43
  48. package/lib/runtime/components/react/mpx-checkbox.tsx +56 -64
  49. package/lib/runtime/components/react/mpx-form.tsx +51 -22
  50. package/lib/runtime/components/react/mpx-icon.tsx +31 -27
  51. package/lib/runtime/components/react/mpx-image/index.tsx +54 -47
  52. package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
  53. package/lib/runtime/components/react/mpx-input.tsx +59 -38
  54. package/lib/runtime/components/react/mpx-label.tsx +55 -59
  55. package/lib/runtime/components/react/mpx-movable-area.tsx +40 -25
  56. package/lib/runtime/components/react/mpx-movable-view.tsx +29 -29
  57. package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
  58. package/lib/runtime/components/react/mpx-picker/date.tsx +4 -4
  59. package/lib/runtime/components/react/mpx-picker/index.tsx +12 -11
  60. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +17 -13
  61. package/lib/runtime/components/react/mpx-picker/region.tsx +23 -19
  62. package/lib/runtime/components/react/mpx-picker/selector.tsx +7 -7
  63. package/lib/runtime/components/react/mpx-picker/time.tsx +29 -31
  64. package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
  65. package/lib/runtime/components/react/mpx-picker-view-column.tsx +149 -20
  66. package/lib/runtime/components/react/mpx-picker-view.tsx +180 -63
  67. package/lib/runtime/components/react/mpx-radio-group.tsx +51 -47
  68. package/lib/runtime/components/react/mpx-radio.tsx +57 -72
  69. package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
  70. package/lib/runtime/components/react/mpx-scroll-view.tsx +136 -104
  71. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +175 -96
  72. package/lib/runtime/components/react/mpx-swiper/index.tsx +21 -9
  73. package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
  74. package/lib/runtime/components/react/mpx-swiper-item.tsx +48 -14
  75. package/lib/runtime/components/react/mpx-switch.tsx +46 -24
  76. package/lib/runtime/components/react/mpx-text.tsx +38 -45
  77. package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
  78. package/lib/runtime/components/react/mpx-view.tsx +401 -241
  79. package/lib/runtime/components/react/mpx-web-view.tsx +22 -22
  80. package/lib/runtime/components/react/parser.ts +245 -0
  81. package/lib/runtime/components/react/types/common.ts +4 -4
  82. package/lib/runtime/components/react/types/global.d.ts +24 -2
  83. package/lib/runtime/components/react/useNodesRef.ts +1 -7
  84. package/lib/runtime/components/react/utils.tsx +524 -0
  85. package/lib/runtime/components/web/mpx-scroll-view.vue +25 -5
  86. package/lib/style-compiler/index.js +5 -4
  87. package/lib/template-compiler/compiler.js +133 -161
  88. package/lib/template-compiler/gen-node-react.js +1 -3
  89. package/lib/utils/const.js +2 -1
  90. package/lib/web/processStyles.js +2 -1
  91. package/lib/web/processTemplate.js +2 -3
  92. package/lib/wxml/loader.js +1 -1
  93. package/package.json +7 -4
  94. package/lib/runtime/components/react/dist/utils.js +0 -148
  95. package/lib/runtime/components/react/utils.ts +0 -170
@@ -1,28 +1,157 @@
1
1
 
2
- import { View } from 'react-native'
3
- import React, { forwardRef, useRef } from 'react'
4
- import useInnerProps from './getInnerListeners'
2
+ import { View, Animated, SafeAreaView, NativeScrollEvent, NativeSyntheticEvent, LayoutChangeEvent, ScrollView } from 'react-native'
3
+ import React, { forwardRef, useRef, useState, useEffect, ReactElement, ReactNode } from 'react'
4
+ import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
5
5
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
6
-
7
6
  interface ColumnProps {
8
- children: React.ReactNode
7
+ children: React.ReactNode,
8
+ selectedIndex: number,
9
+ onColumnLayoutChange: Function,
10
+ getInnerLayout: Function,
11
+ onSelectChange: Function,
12
+ style: {
13
+ [key: string]: any
14
+ },
15
+ 'enable-var': boolean
16
+ 'external-var-context'?: Record<string, any>
17
+ wrapperStyle: {
18
+ height?: number,
19
+ itemHeight: string
20
+ },
21
+ prefix: number
9
22
  }
23
+ const defaultItemHeight = 36
24
+ // 每个Column 都有个外层的高度, 内部的元素高度
25
+ // 默认的高度
26
+ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>, ColumnProps>((props: ColumnProps, ref) => {
27
+ const { children, selectedIndex, onColumnLayoutChange, onSelectChange, getInnerLayout, style, wrapperStyle, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props
28
+ // PickerViewColumn
29
+ const {
30
+ normalStyle,
31
+ hasVarDec,
32
+ varContextRef,
33
+ hasSelfPercent,
34
+ setWidth,
35
+ setHeight
36
+ } = useTransformStyle(style, { enableVar, externalVarContext })
37
+ const { textStyle } = splitStyle(normalStyle)
38
+ const { textProps } = splitProps(props)
39
+ // const { innerStyle } = splitStyle(normalStyle)
40
+ // scrollView的ref
41
+ const scrollViewRef = useRef<ScrollView>(null)
42
+ useNodesRef(props, ref, scrollViewRef, {})
43
+ // 每个元素的高度
44
+ let [itemH, setItemH] = useState(0)
10
45
 
11
- const _PickerViewColumn = forwardRef<HandlerRef<View, ColumnProps>, ColumnProps>((props: ColumnProps, ref) => {
12
- const { children } = props
13
- const layoutRef = useRef({})
14
- const { nodeRef } = useNodesRef(props, ref, {})
15
- const innerProps = useInnerProps(props, {}, [], { layoutRef })
16
- return (
17
- <View
18
- ref={nodeRef}
19
- {...innerProps}>
20
- {children}
21
- </View>
22
- )
23
- })
46
+ useEffect(() => {
47
+ if (selectedIndex && itemH) {
48
+ const offsetY = selectedIndex * itemH
49
+ scrollViewRef.current?.scrollTo({ x: 0, y: offsetY, animated: true })
50
+ }
51
+ }, [selectedIndex, itemH])
24
52
 
25
- _PickerViewColumn.displayName = 'mpx-picker-view-column';
53
+ const onScrollViewLayout = () => {
54
+ getInnerLayout && getInnerLayout(layoutRef)
55
+ }
26
56
 
27
- export default _PickerViewColumn
57
+ const {
58
+ // 存储layout布局信息
59
+ layoutRef,
60
+ layoutProps
61
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout: onScrollViewLayout })
62
+
63
+ const onItemLayout = (e: LayoutChangeEvent) => {
64
+ const layout = e.nativeEvent.layout
65
+ if (layout.height && itemH !== layout.height) {
66
+ itemH = layout.height
67
+ setItemH(layout.height)
68
+ onColumnLayoutChange && onColumnLayoutChange({ height: layout.height * 5 })
69
+ }
70
+ }
71
+
72
+ const onMomentumScrollEnd = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
73
+ if (scrollViewRef && itemH) {
74
+ const { y: scrollY } = e.nativeEvent.contentOffset
75
+ const selIndex = Math.floor(scrollY / itemH)
76
+ onSelectChange(selIndex)
77
+ }
78
+ }
79
+
80
+ const renderInnerchild = () => {
81
+ // Fragment 节点
82
+ let realElement: Array<ReactNode> = []
83
+ const getRealChilds = () => {
84
+ if (Array.isArray(children)) {
85
+ realElement = children
86
+ } else {
87
+ const tempChild = children as ReactElement
88
+ if (tempChild.props.children && tempChild.props.children) {
89
+ realElement = tempChild.props.children
90
+ } else {
91
+ realElement = [children]
92
+ }
93
+ }
94
+ return realElement
95
+ }
28
96
 
97
+ const realChilds = getRealChilds()
98
+ const arrChild = realChilds.map((item: React.ReactNode, index: number) => {
99
+ const InnerProps = index === 0 ? { onLayout: onItemLayout } : {}
100
+ const strKey = 'picker' + props.prefix + '-column' + index
101
+ const arrHeight = (wrapperStyle.itemHeight + '').match(/\d+/g) || []
102
+ const iHeight = (arrHeight[0] || defaultItemHeight) as number
103
+ return <View key={strKey} {...InnerProps} style={[{ height: iHeight, width: '100%' }]}>
104
+ {wrapChildren(
105
+ {
106
+ children: item
107
+ },
108
+ {
109
+ hasVarDec,
110
+ varContext: varContextRef.current,
111
+ textStyle,
112
+ textProps
113
+ }
114
+ )}
115
+ </View>
116
+ })
117
+ const totalHeight = itemH * 5
118
+ if (wrapperStyle.height && totalHeight !== wrapperStyle.height) {
119
+ const fix = Math.ceil((totalHeight - wrapperStyle.height) / 2)
120
+ arrChild.unshift(<View key="picker-column-0" style={[{ height: itemH - fix }]}></View>)
121
+ arrChild.unshift(<View key="picker-column-1" style={[{ height: itemH }]}></View>)
122
+ arrChild.push(<View key="picker-column-2" style={[{ height: itemH }]}></View>)
123
+ arrChild.push(<View key="picker-column-3" style={[{ height: itemH - fix }]}></View>)
124
+ } else {
125
+ arrChild.unshift(<View key="picker-column-0" style={[{ height: itemH }]}></View>)
126
+ arrChild.unshift(<View key="picker-column-1" style={[{ height: itemH }]}></View>)
127
+ arrChild.push(<View key="picker-column-2" style={[{ height: itemH }]}></View>)
128
+ arrChild.push(<View key="picker-column-3" style={[{ height: itemH }]}></View>)
129
+ }
130
+ return arrChild
131
+ }
132
+
133
+ const renderScollView = () => {
134
+ return (<Animated.ScrollView
135
+ horizontal={false}
136
+ ref={scrollViewRef}
137
+ bounces={false}
138
+ scrollsToTop={false}
139
+ removeClippedSubviews={true}
140
+ showsHorizontalScrollIndicator={false}
141
+ showsVerticalScrollIndicator={false}
142
+ pagingEnabled={false}
143
+ snapToInterval={itemH}
144
+ automaticallyAdjustContentInsets={false}
145
+ {...layoutProps}
146
+ onMomentumScrollEnd={onMomentumScrollEnd}>
147
+ {renderInnerchild()}
148
+ </Animated.ScrollView>)
149
+ }
150
+
151
+ return (<SafeAreaView style={[{ display: 'flex', flex: 1 }]}>
152
+ { renderScollView() }
153
+ </SafeAreaView>)
154
+ })
155
+
156
+ _PickerViewColumn.displayName = 'mpx-picker-view-column'
157
+ export default _PickerViewColumn
@@ -1,16 +1,16 @@
1
1
  import { View } from 'react-native'
2
- import React, { forwardRef, useState, useRef, useEffect } from 'react'
3
- import { PickerView } from '@ant-design/react-native'
4
- import useInnerProps from './getInnerListeners'
5
- import { getCustomEvent } from './getInnerListeners'
2
+ import { LinearGradient, LinearGradientProps } from 'react-native-linear-gradient'
3
+ import React, { forwardRef, useState, useRef, ReactElement, JSX } from 'react'
4
+ import useInnerProps, { getCustomEvent } from './getInnerListeners'
6
5
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
6
+ import { parseInlineStyle, useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren } from './utils'
7
7
  /**
8
8
  * ✔ value
9
9
  * ✔ bindchange
10
10
  * ✘ bindpickstart
11
11
  * ✘ bindpickend
12
12
  * ✘ mask-class
13
- * indicator-style
13
+ * indicator-style: 优先级indicator-style.height > pick-view-column中的子元素设置的height
14
14
  * ✘ indicator-class
15
15
  * ✘ mask-style
16
16
  * ✘ immediate-change
@@ -21,84 +21,201 @@ interface PickerViewProps {
21
21
  // 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),数字大于 picker-view-column 可选项长度时,选择最后一项。
22
22
  value?: Array<number>
23
23
  bindchange?: Function
24
+ style: {
25
+ [key: string]: any
26
+ }
27
+ 'indicator-style'?: string
28
+ 'enable-var': boolean
29
+ 'external-var-context'?: Record<string, any>,
30
+ 'enable-offset': boolean
31
+ }
32
+
33
+ interface PickerLayout {
34
+ height: number,
35
+ itemHeight: number
36
+ }
37
+
38
+ interface PosType {
39
+ height?: number,
40
+ top?: number
24
41
  }
25
42
 
43
+ const styles: { [key: string]: Object } = {
44
+ wrapper: {
45
+ display: 'flex',
46
+ flex: 1,
47
+ flexDirection: 'row',
48
+ justifyContent: 'space-around',
49
+ overflow: 'hidden',
50
+ alignItems: 'center'
51
+ },
52
+ maskTop: {
53
+ position: 'absolute',
54
+ width: 1000,
55
+ zIndex: 100
56
+ },
57
+ maskBottom: {
58
+ position: 'absolute',
59
+ width: 1000,
60
+ zIndex: 100
61
+ }
62
+ }
26
63
  const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProps>((props: PickerViewProps, ref) => {
27
- const { children, ...restProps } = props
28
- const layoutRef = useRef({})
29
- const { nodeRef } = useNodesRef(props, ref, {})
30
- const [value, setValue] = useState(props.value)
31
- useEffect(() => {
32
- // 确认这个是变化的props变化的时候才执行,还是初始化的时候就执行
33
- setValue(props.value)
34
- }, [props.value]);
64
+ const { children, value = [], bindchange, style, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props
65
+ // indicatorStyle 需要转换为rn的style
66
+ // 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
67
+ const indicatorStyle = parseInlineStyle(props['indicator-style'])
68
+ const { height: indicatorH, width: indicatorW } = indicatorStyle
69
+ const nodeRef = useRef(null)
70
+ useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {})
71
+ // picker-view 设置的color等textStyle,在小程序上的表现是可以继承到最内层的text样式, 但是RN内部column是slot无法设置, 需要业务自己在column内的元素上设置
72
+ const {
73
+ normalStyle,
74
+ hasVarDec,
75
+ varContextRef,
76
+ hasSelfPercent,
77
+ setWidth,
78
+ setHeight
79
+ } = useTransformStyle(style, { enableVar, externalVarContext })
80
+ const { textStyle } = splitStyle(normalStyle)
81
+ const { textProps } = splitProps(props)
82
+ const {
83
+ // 存储layout布局信息
84
+ layoutRef,
85
+ layoutProps,
86
+ layoutStyle
87
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
35
88
 
36
- const onLayout = () => {
37
- nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
38
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
39
- })
89
+ const isSetW = indicatorW !== undefined ? 1 : 0
90
+ const cloneRef = useRef(null)
91
+ const maskPos: PosType = {}
92
+ let [pickH, setPickH] = useState(0)
93
+ const itemH = pickH / 5
94
+ if (normalStyle?.height && pickH && pickH !== normalStyle?.height) {
95
+ maskPos.height = itemH * 2 + Math.ceil((normalStyle.height - pickH) / 2)
96
+ } else {
97
+ maskPos.height = itemH * 2
40
98
  }
41
- const innerProps = useInnerProps(props, {}, [], { layoutRef })
42
99
 
100
+ const onColumnLayoutChange = (layoutConfig: PickerLayout) => {
101
+ pickH = layoutConfig.height
102
+ setPickH(layoutConfig.height)
103
+ }
43
104
 
44
- const onChange = (val: Array<number>): void => {
45
- const eventData = getCustomEvent('change', {}, { detail: {value: val, source: 'touch' }, layoutRef: layoutRef })
46
- setValue(val)
47
- props.bindchange && props.bindchange(eventData)
105
+ const onSelectChange = (columnIndex: number, selIndex: number) => {
106
+ const changeValue = value.slice()
107
+ changeValue[columnIndex] = selIndex
108
+ const eventData = getCustomEvent('change', {}, { detail: { value: changeValue, source: 'change' }, layoutRef })
109
+ bindchange && bindchange(eventData)
48
110
  }
49
111
 
50
- const joinString = (data: string | any[] | React.ReactElement): string => {
51
- return (Array.isArray(data) ? data : [data]).join('')
112
+ const innerProps = useInnerProps(props, {
113
+ ref: nodeRef,
114
+ style: {
115
+ ...normalStyle,
116
+ ...layoutStyle,
117
+ position: 'relative',
118
+ overflow: 'hidden'
119
+ },
120
+ ...layoutProps
121
+ }, [
122
+ 'enable-offset'
123
+ ], { layoutRef })
124
+
125
+ const cloneChild = (child: React.ReactNode, index: number) => {
126
+ // const extraProps = index === 0 ? { getInnerLayout: getInnerLayout, innerProps } : {}
127
+ const extraProps = {}
128
+ const childProps = {
129
+ ...(child as ReactElement)?.props,
130
+ ref: cloneRef,
131
+ prefix: index,
132
+ key: 'pick-view' + index,
133
+ wrapperStyle: {
134
+ height: normalStyle?.height || 0,
135
+ itemHeight: indicatorH || 0
136
+ },
137
+ onColumnLayoutChange,
138
+ onSelectChange: onSelectChange.bind(null, index),
139
+ selectedIndex: value?.[index] || 0,
140
+ ...extraProps
141
+ }
142
+ const realElement = React.cloneElement(child as ReactElement, childProps)
143
+ return wrapChildren(
144
+ {
145
+ children: realElement
146
+ },
147
+ {
148
+ hasVarDec,
149
+ varContext: varContextRef.current,
150
+ textStyle,
151
+ textProps
152
+ }
153
+ )
52
154
  }
53
155
 
54
- const getLabelFromChildren = (child: React.ReactElement): string => {
55
- return child.props && child.props.children ? getLabelFromChildren(child.props.children) : joinString(child)
156
+ const renderTopMask = () => {
157
+ const linearProps: LinearGradientProps = {
158
+ colors: ['rgba(255,255,255,0.8)', 'rgba(255,255,255,0.2)'],
159
+ style: [
160
+ styles.maskTop,
161
+ {
162
+ height: maskPos.height,
163
+ top: 0,
164
+ pointerEvents: 'none'
165
+ }
166
+ ]
167
+ }
168
+ return (<LinearGradient {...linearProps}/>)
56
169
  }
57
170
 
58
- const handleChildren = (children: React.ReactNode[]): any[] => {
59
- return children.map((child: any, index: number) => {
60
- return {
61
- label: getLabelFromChildren(child),
62
- value: index
63
- }
64
- })
171
+ const renderBottomMask = () => {
172
+ const linearProps: LinearGradientProps = {
173
+ colors: ['rgba(255,255,255,0.2)', 'rgba(255,255,255,0.8)'],
174
+ style: [
175
+ styles.maskBottom,
176
+ {
177
+ height: maskPos.height,
178
+ bottom: 0,
179
+ pointerEvents: 'none'
180
+ }
181
+ ]
182
+ }
183
+ return <LinearGradient {...linearProps}></LinearGradient>
65
184
  }
66
185
 
67
- const getDataFromChildren = (children: React.ReactNode): any[] => {
68
- return (Array.isArray(children) ? children : [children]).map((child: any) => {
69
- return handleChildren(child.props && child.props.children ? child.props.children : [child])
70
- })
186
+ const renderLine = () => {
187
+ return <View style={[{
188
+ position: 'absolute',
189
+ top: '50%',
190
+ transform: [{ translateY: -(itemH / 2) }],
191
+ height: itemH,
192
+ borderTopWidth: 1,
193
+ borderBottomWidth: 1,
194
+ borderColor: '#f0f0f0',
195
+ width: '100%',
196
+ zIndex: 101
197
+ }]}></View>
71
198
  }
72
199
 
73
- const columns = Array.isArray(children) ? children.length : 1
74
- const originData = getDataFromChildren(children)
75
- // 子节点默认的序号,这里是更新默认值的
76
- const subChildLength = originData.map((item) => {
77
- return item.length
78
- })
79
- const defaultValue = (props.value || []).map((item, index) => {
80
- if (item > subChildLength[index]) {
81
- return subChildLength[index] - 1
200
+ const renderSubChild = () => {
201
+ if (Array.isArray(children)) {
202
+ return children.map((item, index) => {
203
+ return cloneChild(item, index)
204
+ })
82
205
  } else {
83
- return item
206
+ return cloneChild(children, 0)
84
207
  }
85
- })
86
-
87
- return (
88
- <PickerView
89
- {...restProps}
90
- cols={columns}
91
- // 默认选中项
92
- defaultValue={defaultValue}
93
- // 内部维护选中项
94
- value={value}
95
- // data数据源column
96
- data={originData}
97
- onChange={onChange}
98
- cascade={false}/>
99
- )
208
+ }
209
+ return (<View {...innerProps}>
210
+ {renderTopMask()}
211
+ <View style={[styles.wrapper]}>
212
+ {renderSubChild()}
213
+ </View>
214
+ {renderBottomMask()}
215
+ {!isSetW && renderLine()}
216
+ </View>)
100
217
  })
101
218
 
102
- _PickerView.displayName = 'mpx-picker-view';
219
+ _PickerView.displayName = 'mpx-picker-view'
103
220
 
104
221
  export default _PickerView
@@ -1,47 +1,44 @@
1
1
  /**
2
2
  * ✔ bindchange
3
3
  */
4
- import {
5
- JSX,
6
- useRef,
7
- forwardRef,
8
- ReactNode,
9
- useContext
10
- } from 'react'
11
- import {
12
- View,
13
- NativeSyntheticEvent,
14
- ViewStyle
15
- } from 'react-native'
4
+ import { JSX, useRef, forwardRef, ReactNode, useContext } from 'react'
5
+ import { View, NativeSyntheticEvent, ViewStyle } from 'react-native'
6
+ import { warn } from '@mpxjs/utils'
16
7
  import { FormContext, FormFieldValue, RadioGroupContext, GroupValue } from './context'
17
8
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
18
9
  import useNodesRef, { HandlerRef } from './useNodesRef'
19
- import { throwReactWarning } from './utils'
10
+ import { useLayout, useTransformStyle, wrapChildren } from './utils'
20
11
 
21
- export interface radioGroupProps {
12
+ export interface RadioGroupProps {
22
13
  name: string
23
14
  style?: ViewStyle & Record<string, any>
24
15
  'enable-offset'?: boolean
16
+ 'enable-var'?: boolean
17
+ 'external-var-context'?: Record<string, any>
18
+ 'parent-font-size'?: number
19
+ 'parent-width'?: number
20
+ 'parent-height'?: number
25
21
  children: ReactNode
26
22
  bindchange?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
27
23
  }
28
24
 
29
25
  const radioGroup = forwardRef<
30
- HandlerRef<View, radioGroupProps>,
31
- radioGroupProps
26
+ HandlerRef<View, RadioGroupProps>,
27
+ RadioGroupProps
32
28
  >((props, ref): JSX.Element => {
33
29
  const {
34
30
  style = {},
35
- 'enable-offset': enableOffset,
36
- children,
37
- bindchange,
31
+ 'enable-var': enableVar,
32
+ 'external-var-context': externalVarContext,
33
+ 'parent-font-size': parentFontSize,
34
+ 'parent-width': parentWidth,
35
+ 'parent-height': parentHeight,
36
+ bindchange
38
37
  } = props
39
38
 
40
- const layoutRef = useRef({})
41
-
42
39
  const formContext = useContext(FormContext)
43
40
 
44
- let formValuesMap: Map<string, FormFieldValue> | undefined;
41
+ let formValuesMap: Map<string, FormFieldValue> | undefined
45
42
 
46
43
  if (formContext) {
47
44
  formValuesMap = formContext.formValuesMap
@@ -51,31 +48,30 @@ const radioGroup = forwardRef<
51
48
 
52
49
  const defaultStyle = {
53
50
  flexDirection: 'row',
54
- flexWrap: 'wrap',
55
- ...style
51
+ flexWrap: 'wrap'
56
52
  }
57
53
 
58
- const { nodeRef } = useNodesRef(props, ref, {
59
- defaultStyle
60
- })
61
-
62
- const onLayout = () => {
63
- nodeRef.current?.measure(
64
- (
65
- x: number,
66
- y: number,
67
- width: number,
68
- height: number,
69
- offsetLeft: number,
70
- offsetTop: number
71
- ) => {
72
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
73
- }
74
- )
54
+ const styleObj = {
55
+ ...defaultStyle,
56
+ ...style
75
57
  }
76
58
 
59
+ const {
60
+ hasSelfPercent,
61
+ normalStyle,
62
+ hasVarDec,
63
+ varContextRef,
64
+ setWidth,
65
+ setHeight
66
+ } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
67
+
68
+ const nodeRef = useRef(null)
69
+ useNodesRef(props, ref, nodeRef, { defaultStyle })
70
+
71
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
72
+
77
73
  const getSelectionValue = (): string | undefined => {
78
- for (let key in groupValue) {
74
+ for (const key in groupValue) {
79
75
  if (groupValue[key].checked) {
80
76
  return key
81
77
  }
@@ -95,7 +91,7 @@ const radioGroup = forwardRef<
95
91
 
96
92
  if (formValuesMap) {
97
93
  if (!props.name) {
98
- throwReactWarning('[Mpx runtime warn]: If a form component is used, the name attribute is required.')
94
+ warn('If a form component is used, the name attribute is required.')
99
95
  } else {
100
96
  formValuesMap.set(props.name, { getValue, resetValue })
101
97
  }
@@ -124,10 +120,10 @@ const radioGroup = forwardRef<
124
120
  props,
125
121
  {
126
122
  ref: nodeRef,
127
- style: defaultStyle,
128
- ...(enableOffset ? { onLayout } : {})
123
+ style: { ...normalStyle, ...layoutStyle },
124
+ ...layoutProps
129
125
  },
130
- ['enable-offset'],
126
+ [],
131
127
  {
132
128
  layoutRef
133
129
  }
@@ -136,7 +132,15 @@ const radioGroup = forwardRef<
136
132
  return (
137
133
  <View {...innerProps}>
138
134
  <RadioGroupContext.Provider value={{ groupValue, notifyChange }}>
139
- {children}
135
+ {
136
+ wrapChildren(
137
+ props,
138
+ {
139
+ hasVarDec,
140
+ varContext: varContextRef.current
141
+ }
142
+ )
143
+ }
140
144
  </RadioGroupContext.Provider>
141
145
  </View>
142
146
  )