@mpxjs/webpack-plugin 2.9.67 → 2.9.69
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/index.js +13 -8
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processStyles.js +14 -4
- package/lib/resolver/AddModePlugin.js +8 -8
- package/lib/runtime/components/react/context.ts +2 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
- package/lib/runtime/components/react/dist/mpx-button.jsx +43 -8
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +143 -84
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
- package/lib/runtime/components/react/dist/mpx-view.jsx +45 -26
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +19 -5
- package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
- package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
- package/lib/runtime/components/react/dist/utils.jsx +54 -3
- package/lib/runtime/components/react/getInnerListeners.ts +3 -17
- package/lib/runtime/components/react/mpx-button.tsx +41 -8
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +232 -103
- package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
- package/lib/runtime/components/react/mpx-view.tsx +57 -27
- package/lib/runtime/components/react/mpx-web-view.tsx +22 -5
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +2 -0
- package/lib/runtime/components/react/utils.tsx +78 -7
- package/lib/template-compiler/compiler.js +3 -2
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/package.json +5 -4
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { WebView } from 'react-native-webview'
|
|
3
|
+
import Bus from './Bus'
|
|
4
|
+
|
|
5
|
+
export const WEBVIEW_TARGET = '@@WEBVIEW_TARGET'
|
|
6
|
+
|
|
7
|
+
export const constructors: Record<string, any> = {}
|
|
8
|
+
|
|
9
|
+
export const ID = () => Math.random().toString(32).slice(2)
|
|
10
|
+
|
|
11
|
+
const SPECIAL_CONSTRUCTOR: Record<string, { className: string, paramNum: number }> = {
|
|
12
|
+
ImageData: {
|
|
13
|
+
className: 'Uint8ClampedArray',
|
|
14
|
+
paramNum: 0
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Instance {
|
|
19
|
+
postMessage: (...args: any[]) => void;
|
|
20
|
+
[WEBVIEW_TARGET]?: string;
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface WebviewConstructor {
|
|
25
|
+
new (...args: any[]): Instance;
|
|
26
|
+
constructLocally?: (...args: unknown[]) => Instance;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface WebviewMessage {
|
|
30
|
+
type: 'set' | 'exec' | 'listen' | 'event' | 'construct'
|
|
31
|
+
payload: {
|
|
32
|
+
target?: string | { [key: string]: any }
|
|
33
|
+
key?: string
|
|
34
|
+
value?: any
|
|
35
|
+
method?: string
|
|
36
|
+
args?: any[]
|
|
37
|
+
types?: string[]
|
|
38
|
+
type?: string
|
|
39
|
+
constructor?: string | Function
|
|
40
|
+
id?: string
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface CanvasInstance {
|
|
45
|
+
webview: WebView | null;
|
|
46
|
+
bus: Bus | null;
|
|
47
|
+
context2D: CanvasRenderingContext2D;
|
|
48
|
+
getContext: (contextType: string) => CanvasRenderingContext2D | null;
|
|
49
|
+
createImage: (width?: number, height?: number) => any;
|
|
50
|
+
postMessage: (message: WebviewMessage) => Promise<any>;
|
|
51
|
+
listeners: Array<(payload: any) => void>;
|
|
52
|
+
addMessageListener: (listener: (payload: any) => void) => () => void;
|
|
53
|
+
removeMessageListener: (listener: (payload: any) => void) => void;
|
|
54
|
+
createImageData: (dataArray: number[], width?: number, height?: number) => any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const registerWebviewTarget = (instance: Instance, targetName: string): void => {
|
|
58
|
+
instance[WEBVIEW_TARGET] = targetName
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const registerWebviewProperties = (instance: Instance, properties: Record<string, any>): void => {
|
|
62
|
+
Object.entries(properties).forEach(([key, initialValue]) => {
|
|
63
|
+
const privateKey = `__${key}__`
|
|
64
|
+
instance[privateKey] = initialValue
|
|
65
|
+
Object.defineProperty(instance, key, {
|
|
66
|
+
configurable: true,
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get () {
|
|
69
|
+
return instance[privateKey]
|
|
70
|
+
},
|
|
71
|
+
set (value) {
|
|
72
|
+
instance.postMessage({
|
|
73
|
+
type: 'set',
|
|
74
|
+
payload: {
|
|
75
|
+
target: instance[WEBVIEW_TARGET],
|
|
76
|
+
key,
|
|
77
|
+
value
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
if (instance.forceUpdate) {
|
|
82
|
+
instance.forceUpdate()
|
|
83
|
+
}
|
|
84
|
+
return (instance[privateKey] = value)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const registerWebviewMethods = (instance: Instance, methods: string[]): void => {
|
|
91
|
+
methods.forEach(method => {
|
|
92
|
+
instance[method] = (...args: any[]) => {
|
|
93
|
+
return instance.postMessage({
|
|
94
|
+
type: 'exec',
|
|
95
|
+
payload: {
|
|
96
|
+
target: instance[WEBVIEW_TARGET],
|
|
97
|
+
method,
|
|
98
|
+
args
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const registerWebviewConstructor = (constructor: WebviewConstructor, constructorName: string): void => {
|
|
106
|
+
constructors[constructorName] = constructor
|
|
107
|
+
constructor.constructLocally = function (...args: unknown[]): Instance {
|
|
108
|
+
return new (constructor as any)(...args, true)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
constructor.prototype.onConstruction = function (...args: any[]): void {
|
|
112
|
+
if (SPECIAL_CONSTRUCTOR[constructorName] !== undefined) {
|
|
113
|
+
const { className, paramNum } = SPECIAL_CONSTRUCTOR[constructorName]
|
|
114
|
+
args[paramNum] = { className, classArgs: [args[paramNum]] }
|
|
115
|
+
}
|
|
116
|
+
this[WEBVIEW_TARGET] = ID()
|
|
117
|
+
this.postMessage({
|
|
118
|
+
type: 'construct',
|
|
119
|
+
payload: {
|
|
120
|
+
constructor: constructorName,
|
|
121
|
+
id: this[WEBVIEW_TARGET],
|
|
122
|
+
args
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
constructor.prototype.toJSON = function () {
|
|
127
|
+
return { __ref__: this[WEBVIEW_TARGET] }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export const useWebviewBinding = ({
|
|
131
|
+
targetName,
|
|
132
|
+
properties = {},
|
|
133
|
+
methods = []
|
|
134
|
+
}: {
|
|
135
|
+
targetName: string;
|
|
136
|
+
properties?: Record<string, any>;
|
|
137
|
+
methods?: string[]
|
|
138
|
+
}) => {
|
|
139
|
+
const instanceRef = useRef({})
|
|
140
|
+
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (instanceRef.current) {
|
|
143
|
+
registerWebviewTarget(instanceRef.current as Instance, targetName)
|
|
144
|
+
registerWebviewProperties(instanceRef.current as Instance, properties)
|
|
145
|
+
registerWebviewMethods(instanceRef.current as Instance, methods)
|
|
146
|
+
}
|
|
147
|
+
}, [])
|
|
148
|
+
|
|
149
|
+
return instanceRef
|
|
150
|
+
}
|
|
@@ -1,31 +1,51 @@
|
|
|
1
1
|
|
|
2
2
|
import { View, Animated, SafeAreaView, NativeScrollEvent, NativeSyntheticEvent, LayoutChangeEvent, ScrollView } from 'react-native'
|
|
3
|
-
import React, { forwardRef, useRef, useState,
|
|
4
|
-
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
|
|
5
|
-
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
3
|
+
import React, { forwardRef, useRef, useState, useMemo, useCallback, useEffect } from 'react'
|
|
4
|
+
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout, usePrevious } from './utils'
|
|
5
|
+
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
6
|
+
import { createFaces } from './pickerFaces'
|
|
7
|
+
import PickerOverlay from './pickerOverlay'
|
|
8
|
+
|
|
6
9
|
interface ColumnProps {
|
|
7
|
-
children
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
children?: React.ReactNode
|
|
11
|
+
columnData: React.ReactNode[]
|
|
12
|
+
initialIndex: number
|
|
13
|
+
onColumnItemRawHChange: Function
|
|
14
|
+
getInnerLayout: Function
|
|
15
|
+
onSelectChange: Function
|
|
12
16
|
style: {
|
|
13
17
|
[key: string]: any
|
|
14
|
-
}
|
|
18
|
+
}
|
|
15
19
|
'enable-var': boolean
|
|
16
20
|
'external-var-context'?: Record<string, any>
|
|
17
21
|
wrapperStyle: {
|
|
18
|
-
height
|
|
19
|
-
itemHeight:
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
+
height: number
|
|
23
|
+
itemHeight: number
|
|
24
|
+
}
|
|
25
|
+
pickerOverlayStyle: Record<string, any>
|
|
26
|
+
columnIndex: number
|
|
22
27
|
}
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
|
|
28
|
+
|
|
29
|
+
// 默认的单个选项高度
|
|
30
|
+
const DefaultPickerItemH = 36
|
|
31
|
+
// 默认一屏可见选项个数
|
|
32
|
+
const visibleCount = 5
|
|
33
|
+
|
|
26
34
|
const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>, ColumnProps>((props: ColumnProps, ref) => {
|
|
27
|
-
const {
|
|
28
|
-
|
|
35
|
+
const {
|
|
36
|
+
columnData,
|
|
37
|
+
columnIndex,
|
|
38
|
+
initialIndex,
|
|
39
|
+
onSelectChange,
|
|
40
|
+
onColumnItemRawHChange,
|
|
41
|
+
getInnerLayout,
|
|
42
|
+
style,
|
|
43
|
+
wrapperStyle,
|
|
44
|
+
pickerOverlayStyle,
|
|
45
|
+
'enable-var': enableVar,
|
|
46
|
+
'external-var-context': externalVarContext
|
|
47
|
+
} = props
|
|
48
|
+
|
|
29
49
|
const {
|
|
30
50
|
normalStyle,
|
|
31
51
|
hasVarDec,
|
|
@@ -36,122 +56,231 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
36
56
|
} = useTransformStyle(style, { enableVar, externalVarContext })
|
|
37
57
|
const { textStyle } = splitStyle(normalStyle)
|
|
38
58
|
const { textProps } = splitProps(props)
|
|
39
|
-
// const { innerStyle } = splitStyle(normalStyle)
|
|
40
|
-
// scrollView的ref
|
|
41
59
|
const scrollViewRef = useRef<ScrollView>(null)
|
|
42
60
|
useNodesRef(props, ref, scrollViewRef, {})
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
|
|
62
|
+
const { height: pickerH, itemHeight = DefaultPickerItemH } = wrapperStyle
|
|
63
|
+
const [itemRawH, setItemRawH] = useState(0) // 单个选项真实渲染高度
|
|
64
|
+
const maxIndex = useMemo(() => columnData.length - 1, [columnData])
|
|
65
|
+
const touching = useRef(false)
|
|
66
|
+
const scrolling = useRef(false)
|
|
67
|
+
const activeIndex = useRef(initialIndex)
|
|
68
|
+
const prevIndex = usePrevious(initialIndex)
|
|
69
|
+
const prevMaxIndex = usePrevious(maxIndex)
|
|
70
|
+
|
|
71
|
+
const initialOffset = useMemo(() => ({
|
|
72
|
+
x: 0,
|
|
73
|
+
y: itemRawH * initialIndex
|
|
74
|
+
}), [itemRawH])
|
|
75
|
+
|
|
76
|
+
const snapToOffsets = useMemo(
|
|
77
|
+
() => columnData.map((_, i) => i * itemRawH),
|
|
78
|
+
[columnData, itemRawH]
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
const contentContainerStyle = useMemo(() => {
|
|
82
|
+
return [
|
|
83
|
+
{
|
|
84
|
+
paddingVertical: Math.round(pickerH - itemRawH) / 2
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}, [pickerH, itemRawH])
|
|
45
88
|
|
|
46
89
|
useEffect(() => {
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
90
|
+
if (
|
|
91
|
+
!scrollViewRef.current ||
|
|
92
|
+
!itemRawH ||
|
|
93
|
+
touching.current ||
|
|
94
|
+
scrolling.current ||
|
|
95
|
+
prevIndex == null ||
|
|
96
|
+
initialIndex === prevIndex ||
|
|
97
|
+
initialIndex === activeIndex.current ||
|
|
98
|
+
maxIndex !== prevMaxIndex
|
|
99
|
+
) {
|
|
100
|
+
return
|
|
50
101
|
}
|
|
51
|
-
|
|
102
|
+
|
|
103
|
+
activeIndex.current = initialIndex
|
|
104
|
+
scrollViewRef.current.scrollTo({
|
|
105
|
+
x: 0,
|
|
106
|
+
y: itemRawH * initialIndex,
|
|
107
|
+
animated: false
|
|
108
|
+
})
|
|
109
|
+
}, [itemRawH, initialIndex])
|
|
52
110
|
|
|
53
111
|
const onScrollViewLayout = () => {
|
|
54
112
|
getInnerLayout && getInnerLayout(layoutRef)
|
|
55
113
|
}
|
|
56
114
|
|
|
57
115
|
const {
|
|
58
|
-
// 存储layout布局信息
|
|
59
116
|
layoutRef,
|
|
60
117
|
layoutProps
|
|
61
|
-
} = useLayout({
|
|
118
|
+
} = useLayout({
|
|
119
|
+
props,
|
|
120
|
+
hasSelfPercent,
|
|
121
|
+
setWidth,
|
|
122
|
+
setHeight,
|
|
123
|
+
nodeRef: scrollViewRef,
|
|
124
|
+
onLayout: onScrollViewLayout
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const onContentSizeChange = (w: number, h: number) => {
|
|
128
|
+
scrollViewRef.current?.scrollTo({
|
|
129
|
+
x: 0,
|
|
130
|
+
y: itemRawH * initialIndex,
|
|
131
|
+
animated: false
|
|
132
|
+
})
|
|
133
|
+
}
|
|
62
134
|
|
|
63
135
|
const onItemLayout = (e: LayoutChangeEvent) => {
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
onColumnLayoutChange && onColumnLayoutChange({ height: layout.height * 5 })
|
|
136
|
+
const { height: rawH } = e.nativeEvent.layout
|
|
137
|
+
if (rawH && itemRawH !== rawH) {
|
|
138
|
+
setItemRawH(rawH)
|
|
139
|
+
onColumnItemRawHChange(rawH)
|
|
69
140
|
}
|
|
70
141
|
}
|
|
71
142
|
|
|
143
|
+
const onTouchStart = () => {
|
|
144
|
+
touching.current = true
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const onTouchEnd = () => {
|
|
148
|
+
touching.current = false
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const onTouchCancel = () => {
|
|
152
|
+
touching.current = false
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const onMomentumScrollBegin = () => {
|
|
156
|
+
scrolling.current = true
|
|
157
|
+
}
|
|
158
|
+
|
|
72
159
|
const onMomentumScrollEnd = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
160
|
+
scrolling.current = false
|
|
161
|
+
if (!itemRawH) {
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
const { y: scrollY } = e.nativeEvent.contentOffset
|
|
165
|
+
let calcIndex = Math.round(scrollY / itemRawH)
|
|
166
|
+
activeIndex.current = calcIndex
|
|
167
|
+
if (calcIndex !== initialIndex) {
|
|
168
|
+
calcIndex = Math.max(0, Math.min(calcIndex, maxIndex)) || 0
|
|
169
|
+
onSelectChange(calcIndex)
|
|
77
170
|
}
|
|
78
171
|
}
|
|
79
172
|
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
173
|
+
const offsetY = useRef(new Animated.Value(0)).current
|
|
174
|
+
|
|
175
|
+
const onScroll = useMemo(
|
|
176
|
+
() =>
|
|
177
|
+
Animated.event([{ nativeEvent: { contentOffset: { y: offsetY } } }], {
|
|
178
|
+
useNativeDriver: true
|
|
179
|
+
}),
|
|
180
|
+
[offsetY]
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
const faces = useMemo(() => createFaces(itemRawH, visibleCount), [itemRawH])
|
|
184
|
+
|
|
185
|
+
const getTransform = useCallback(
|
|
186
|
+
(index: number) => {
|
|
187
|
+
const inputRange = faces.map((f) => itemRawH * (index + f.index))
|
|
188
|
+
return {
|
|
189
|
+
opacity: offsetY.interpolate({
|
|
190
|
+
inputRange: inputRange,
|
|
191
|
+
outputRange: faces.map((x) => x.opacity),
|
|
192
|
+
extrapolate: 'clamp'
|
|
193
|
+
}),
|
|
194
|
+
rotateX: offsetY.interpolate({
|
|
195
|
+
inputRange: inputRange,
|
|
196
|
+
outputRange: faces.map((x) => `${x.deg}deg`),
|
|
197
|
+
extrapolate: 'extend'
|
|
198
|
+
}),
|
|
199
|
+
translateY: offsetY.interpolate({
|
|
200
|
+
inputRange: inputRange,
|
|
201
|
+
outputRange: faces.map((x) => x.offsetY),
|
|
202
|
+
extrapolate: 'extend'
|
|
203
|
+
})
|
|
93
204
|
}
|
|
94
|
-
|
|
95
|
-
|
|
205
|
+
},
|
|
206
|
+
[offsetY, faces, itemRawH]
|
|
207
|
+
)
|
|
96
208
|
|
|
97
|
-
|
|
98
|
-
|
|
209
|
+
const renderInnerchild = () =>
|
|
210
|
+
columnData.map((item: React.ReactNode, index: number) => {
|
|
99
211
|
const InnerProps = index === 0 ? { onLayout: onItemLayout } : {}
|
|
100
|
-
const strKey =
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
{
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
212
|
+
const strKey = `picker-column-${columnIndex}-${index}`
|
|
213
|
+
const { opacity, rotateX, translateY } = getTransform(index)
|
|
214
|
+
return (
|
|
215
|
+
<Animated.View
|
|
216
|
+
key={strKey}
|
|
217
|
+
{...InnerProps}
|
|
218
|
+
style={[
|
|
219
|
+
{
|
|
220
|
+
height: itemHeight || DefaultPickerItemH,
|
|
221
|
+
width: '100%',
|
|
222
|
+
opacity,
|
|
223
|
+
transform: [
|
|
224
|
+
{ translateY },
|
|
225
|
+
{ rotateX },
|
|
226
|
+
{ perspective: 1000 } // 适配 Android
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
]}
|
|
230
|
+
>
|
|
231
|
+
{wrapChildren(
|
|
232
|
+
{ children: item },
|
|
233
|
+
{
|
|
234
|
+
hasVarDec,
|
|
235
|
+
varContext: varContextRef.current,
|
|
236
|
+
textStyle,
|
|
237
|
+
textProps
|
|
238
|
+
}
|
|
239
|
+
)}
|
|
240
|
+
</Animated.View>
|
|
241
|
+
)
|
|
116
242
|
})
|
|
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
243
|
|
|
133
244
|
const renderScollView = () => {
|
|
134
|
-
return (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
245
|
+
return (
|
|
246
|
+
<Animated.ScrollView
|
|
247
|
+
ref={scrollViewRef}
|
|
248
|
+
bounces={true}
|
|
249
|
+
horizontal={false}
|
|
250
|
+
pagingEnabled={false}
|
|
251
|
+
nestedScrollEnabled={true}
|
|
252
|
+
removeClippedSubviews={true}
|
|
253
|
+
showsVerticalScrollIndicator={false}
|
|
254
|
+
showsHorizontalScrollIndicator={false}
|
|
255
|
+
{...layoutProps}
|
|
256
|
+
scrollEventThrottle={16}
|
|
257
|
+
contentContainerStyle={contentContainerStyle}
|
|
258
|
+
contentOffset={initialOffset}
|
|
259
|
+
snapToOffsets={snapToOffsets}
|
|
260
|
+
onContentSizeChange={onContentSizeChange}
|
|
261
|
+
onScroll={onScroll}
|
|
262
|
+
onTouchStart={onTouchStart}
|
|
263
|
+
onTouchEnd={onTouchEnd}
|
|
264
|
+
onTouchCancel={onTouchCancel}
|
|
265
|
+
onMomentumScrollBegin={onMomentumScrollBegin}
|
|
266
|
+
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
267
|
+
>
|
|
147
268
|
{renderInnerchild()}
|
|
148
|
-
|
|
269
|
+
</Animated.ScrollView>
|
|
270
|
+
)
|
|
149
271
|
}
|
|
150
272
|
|
|
151
|
-
|
|
152
|
-
{
|
|
153
|
-
|
|
273
|
+
const renderOverlay = () => (
|
|
274
|
+
<PickerOverlay itemHeight={itemHeight} overlayItemStyle={pickerOverlayStyle} />
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<SafeAreaView style={[{ display: 'flex', flex: 1 }]}>
|
|
279
|
+
{renderScollView()}
|
|
280
|
+
{renderOverlay()}
|
|
281
|
+
</SafeAreaView>
|
|
282
|
+
)
|
|
154
283
|
})
|
|
155
284
|
|
|
156
|
-
_PickerViewColumn.displayName = '
|
|
285
|
+
_PickerViewColumn.displayName = 'MpxPickerViewColumn'
|
|
157
286
|
export default _PickerViewColumn
|