@mpxjs/webpack-plugin 2.9.70 → 2.9.71
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/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/picker-view.js +1 -5
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
- package/lib/platform/template/wx/index.js +0 -4
- package/lib/runtime/components/react/context.ts +8 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +34 -31
- package/lib/runtime/components/react/dist/mpx-button.jsx +16 -44
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +93 -58
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +151 -127
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +38 -34
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +10 -11
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +11 -4
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +31 -8
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +670 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +15 -53
- package/lib/runtime/components/react/dist/pickerFaces.js +7 -6
- package/lib/runtime/components/react/dist/pickerVIewContext.js +14 -0
- package/lib/runtime/components/react/dist/pickerViewIndicator.jsx +23 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +20 -2
- package/lib/runtime/components/react/dist/utils.jsx +74 -11
- package/lib/runtime/components/react/getInnerListeners.ts +43 -32
- package/lib/runtime/components/react/mpx-button.tsx +20 -57
- package/lib/runtime/components/react/mpx-movable-view.tsx +119 -74
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +76 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +206 -183
- package/lib/runtime/components/react/mpx-picker-view.tsx +49 -48
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +12 -18
- package/lib/runtime/components/react/mpx-scroll-view.tsx +21 -10
- package/lib/runtime/components/react/mpx-swiper-item.tsx +45 -11
- package/lib/runtime/components/react/mpx-swiper.tsx +742 -0
- package/lib/runtime/components/react/mpx-view.tsx +18 -65
- package/lib/runtime/components/react/pickerFaces.ts +10 -7
- package/lib/runtime/components/react/pickerVIewContext.ts +27 -0
- package/lib/runtime/components/react/pickerViewIndicator.tsx +34 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/types/{getInnerListeners.ts → getInnerListeners.d.ts} +4 -5
- package/lib/runtime/components/react/types/global.d.ts +10 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +24 -3
- package/lib/runtime/components/react/utils.tsx +85 -12
- package/lib/runtime/components/web/mpx-checkbox.vue +1 -1
- package/lib/runtime/components/web/mpx-picker-view-column.vue +9 -4
- package/lib/template-compiler/compiler.js +61 -13
- package/lib/wxss/loader.js +15 -2
- package/package.json +3 -3
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -480
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/dist/pickerOverlay.jsx +0 -21
- package/lib/runtime/components/react/dist/types/common.js +0 -1
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +0 -1
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -527
- package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
- package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
- package/lib/runtime/components/react/pickerOverlay.tsx +0 -32
- /package/lib/runtime/components/react/types/{common.ts → common.d.ts} +0 -0
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* ✘ bindagreeprivacyauthorization
|
|
35
35
|
* ✔ bindtap
|
|
36
36
|
*/
|
|
37
|
-
import { createElement, useEffect, useRef,
|
|
37
|
+
import { createElement, useEffect, useRef, ReactNode, forwardRef, useContext, JSX } from 'react'
|
|
38
38
|
import {
|
|
39
39
|
View,
|
|
40
40
|
StyleSheet,
|
|
@@ -45,10 +45,12 @@ import {
|
|
|
45
45
|
NativeSyntheticEvent
|
|
46
46
|
} from 'react-native'
|
|
47
47
|
import { warn } from '@mpxjs/utils'
|
|
48
|
-
import {
|
|
48
|
+
import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
|
|
49
|
+
import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover } from './utils'
|
|
49
50
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
50
51
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
51
52
|
import { RouteContext, FormContext } from './context'
|
|
53
|
+
import type { ExtendedViewStyle } from './types/common'
|
|
52
54
|
|
|
53
55
|
export type Type = 'default' | 'primary' | 'warn'
|
|
54
56
|
|
|
@@ -68,7 +70,7 @@ export interface ButtonProps {
|
|
|
68
70
|
disabled?: boolean
|
|
69
71
|
loading?: boolean
|
|
70
72
|
'hover-class'?: string
|
|
71
|
-
'hover-style'?:
|
|
73
|
+
'hover-style'?: ExtendedViewStyle
|
|
72
74
|
'hover-start-time'?: number
|
|
73
75
|
'hover-stay-time'?: number
|
|
74
76
|
'open-type'?: OpenType
|
|
@@ -83,8 +85,6 @@ export interface ButtonProps {
|
|
|
83
85
|
children: ReactNode
|
|
84
86
|
bindgetuserinfo?: (userInfo: any) => void
|
|
85
87
|
bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
86
|
-
bindtouchstart?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
87
|
-
bindtouchend?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
const LOADING_IMAGE_URI =
|
|
@@ -216,15 +216,16 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
216
216
|
style = {},
|
|
217
217
|
children,
|
|
218
218
|
bindgetuserinfo,
|
|
219
|
-
bindtap
|
|
220
|
-
bindtouchstart,
|
|
221
|
-
bindtouchend
|
|
219
|
+
bindtap
|
|
222
220
|
} = props
|
|
223
221
|
|
|
224
222
|
const pageId = useContext(RouteContext)
|
|
225
223
|
|
|
226
224
|
const formContext = useContext(FormContext)
|
|
227
225
|
|
|
226
|
+
const enableHover = hoverClass !== 'none'
|
|
227
|
+
const { isHover, gesture } = useHover({ enableHover, hoverStartTime, hoverStayTime, disabled })
|
|
228
|
+
|
|
228
229
|
let submitFn: () => void | undefined
|
|
229
230
|
let resetFn: () => void | undefined
|
|
230
231
|
|
|
@@ -233,27 +234,15 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
233
234
|
resetFn = formContext.reset
|
|
234
235
|
}
|
|
235
236
|
|
|
236
|
-
const refs = useRef<{
|
|
237
|
-
hoverStartTimer: ReturnType<typeof setTimeout> | undefined
|
|
238
|
-
hoverStayTimer: ReturnType<typeof setTimeout> | undefined
|
|
239
|
-
}>({
|
|
240
|
-
hoverStartTimer: undefined,
|
|
241
|
-
hoverStayTimer: undefined
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
const [isHover, setIsHover] = useState(false)
|
|
245
|
-
|
|
246
237
|
const isMiniSize = size === 'mini'
|
|
247
238
|
|
|
248
|
-
const applyHoverEffect = isHover && hoverClass !== 'none'
|
|
249
|
-
|
|
250
239
|
const [color, hoverColor, plainColor, disabledColor] = TypeColorMap[type]
|
|
251
240
|
|
|
252
|
-
const normalBackgroundColor = disabled ? disabledColor :
|
|
241
|
+
const normalBackgroundColor = disabled ? disabledColor : isHover || loading ? hoverColor : color
|
|
253
242
|
|
|
254
243
|
const plainBorderColor = disabled
|
|
255
244
|
? 'rgba(0, 0, 0, .2)'
|
|
256
|
-
:
|
|
245
|
+
: isHover
|
|
257
246
|
? `rgba(${plainColor},.6)`
|
|
258
247
|
: `rgb(${plainColor})`
|
|
259
248
|
|
|
@@ -261,14 +250,14 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
261
250
|
|
|
262
251
|
const plainTextColor = disabled
|
|
263
252
|
? 'rgba(0, 0, 0, .2)'
|
|
264
|
-
:
|
|
253
|
+
: isHover
|
|
265
254
|
? `rgba(${plainColor}, .6)`
|
|
266
255
|
: `rgb(${plainColor})`
|
|
267
256
|
|
|
268
257
|
const normalTextColor =
|
|
269
258
|
type === 'default'
|
|
270
|
-
? `rgba(0, 0, 0, ${disabled ? 0.3 :
|
|
271
|
-
: `rgba(255 ,255 ,255 , ${disabled ||
|
|
259
|
+
? `rgba(0, 0, 0, ${disabled ? 0.3 : isHover || loading ? 0.6 : 1})`
|
|
260
|
+
: `rgba(255 ,255 ,255 , ${disabled || isHover || loading ? 0.6 : 1})`
|
|
272
261
|
|
|
273
262
|
const viewStyle = {
|
|
274
263
|
borderWidth: 1,
|
|
@@ -297,7 +286,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
297
286
|
{},
|
|
298
287
|
defaultStyle,
|
|
299
288
|
style,
|
|
300
|
-
|
|
289
|
+
isHover ? hoverStyle : {}
|
|
301
290
|
)
|
|
302
291
|
|
|
303
292
|
const {
|
|
@@ -366,34 +355,6 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
366
355
|
}
|
|
367
356
|
}
|
|
368
357
|
|
|
369
|
-
const setStayTimer = () => {
|
|
370
|
-
clearTimeout(refs.current.hoverStayTimer)
|
|
371
|
-
refs.current.hoverStayTimer = setTimeout(() => {
|
|
372
|
-
setIsHover(false)
|
|
373
|
-
clearTimeout(refs.current.hoverStayTimer)
|
|
374
|
-
}, hoverStayTime)
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const setStartTimer = () => {
|
|
378
|
-
clearTimeout(refs.current.hoverStartTimer)
|
|
379
|
-
refs.current.hoverStartTimer = setTimeout(() => {
|
|
380
|
-
setIsHover(true)
|
|
381
|
-
clearTimeout(refs.current.hoverStartTimer)
|
|
382
|
-
}, hoverStartTime)
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const onTouchStart = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
386
|
-
bindtouchstart && bindtouchstart(evt)
|
|
387
|
-
if (disabled) return
|
|
388
|
-
setStartTimer()
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const onTouchEnd = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
392
|
-
bindtouchend && bindtouchend(evt)
|
|
393
|
-
if (disabled) return
|
|
394
|
-
setStayTimer()
|
|
395
|
-
}
|
|
396
|
-
|
|
397
358
|
const handleFormTypeFn = () => {
|
|
398
359
|
if (formType === 'submit') {
|
|
399
360
|
submitFn && submitFn()
|
|
@@ -418,8 +379,6 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
418
379
|
},
|
|
419
380
|
layoutProps,
|
|
420
381
|
{
|
|
421
|
-
bindtouchstart: (bindtouchstart || !disabled) && onTouchStart,
|
|
422
|
-
bindtouchend: (bindtouchend || !disabled) && onTouchEnd,
|
|
423
382
|
bindtap: !disabled && onTap
|
|
424
383
|
}
|
|
425
384
|
),
|
|
@@ -442,7 +401,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
442
401
|
}
|
|
443
402
|
)
|
|
444
403
|
|
|
445
|
-
|
|
404
|
+
const baseButton = createElement(View, innerProps, loading && createElement(Loading, { alone: !children }),
|
|
446
405
|
wrapChildren(
|
|
447
406
|
props,
|
|
448
407
|
{
|
|
@@ -453,6 +412,10 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
453
412
|
}
|
|
454
413
|
)
|
|
455
414
|
)
|
|
415
|
+
|
|
416
|
+
return enableHover
|
|
417
|
+
? createElement(GestureDetector, { gesture: gesture as PanGesture }, baseButton)
|
|
418
|
+
: baseButton
|
|
456
419
|
})
|
|
457
420
|
|
|
458
421
|
Button.displayName = 'MpxButton'
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* ✘ scale-min
|
|
12
12
|
* ✘ scale-max
|
|
13
13
|
* ✘ scale-value
|
|
14
|
-
*
|
|
14
|
+
* ✔ animation
|
|
15
15
|
* ✔ bindchange
|
|
16
16
|
* ✘ bindscale
|
|
17
17
|
* ✔ htouchmove
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { useEffect, forwardRef, ReactNode, useContext, useCallback, useRef, useMemo, createElement } from 'react'
|
|
21
21
|
import { StyleSheet, NativeSyntheticEvent, View, LayoutChangeEvent } from 'react-native'
|
|
22
|
-
import { getCustomEvent } from './getInnerListeners'
|
|
22
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
23
23
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
24
24
|
import { MovableAreaContext } from './context'
|
|
25
|
-
import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, GestureHandler, flatGesture, extendObject } from './utils'
|
|
25
|
+
import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, GestureHandler, flatGesture, extendObject, omit } from './utils'
|
|
26
26
|
import { GestureDetector, Gesture, GestureTouchEvent, GestureStateChangeEvent, PanGestureHandlerEventPayload, PanGesture } from 'react-native-gesture-handler'
|
|
27
27
|
import Animated, {
|
|
28
28
|
useSharedValue,
|
|
@@ -33,6 +33,7 @@ import Animated, {
|
|
|
33
33
|
useAnimatedReaction,
|
|
34
34
|
withSpring
|
|
35
35
|
} from 'react-native-reanimated'
|
|
36
|
+
import { collectDataset, noop } from '@mpxjs/utils'
|
|
36
37
|
|
|
37
38
|
interface MovableViewProps {
|
|
38
39
|
children: ReactNode;
|
|
@@ -42,17 +43,22 @@ interface MovableViewProps {
|
|
|
42
43
|
y?: number;
|
|
43
44
|
disabled?: boolean;
|
|
44
45
|
animation?: boolean;
|
|
46
|
+
id?: string;
|
|
45
47
|
bindchange?: (event: unknown) => void;
|
|
46
|
-
bindtouchstart?: (event:
|
|
47
|
-
catchtouchstart?: (event:
|
|
48
|
-
bindtouchmove?: (event:
|
|
49
|
-
catchtouchmove?: (event:
|
|
50
|
-
catchtouchend?: (event:
|
|
51
|
-
bindtouchend?: (event:
|
|
52
|
-
bindhtouchmove?: (event:
|
|
53
|
-
bindvtouchmove?: (event:
|
|
54
|
-
catchhtouchmove?: (event:
|
|
55
|
-
catchvtouchmove?: (event:
|
|
48
|
+
bindtouchstart?: (event: GestureTouchEvent) => void;
|
|
49
|
+
catchtouchstart?: (event: GestureTouchEvent) => void;
|
|
50
|
+
bindtouchmove?: (event: GestureTouchEvent) => void;
|
|
51
|
+
catchtouchmove?: (event: GestureTouchEvent) => void;
|
|
52
|
+
catchtouchend?: (event: GestureTouchEvent) => void;
|
|
53
|
+
bindtouchend?: (event: GestureTouchEvent) => void;
|
|
54
|
+
bindhtouchmove?: (event: GestureTouchEvent) => void;
|
|
55
|
+
bindvtouchmove?: (event: GestureTouchEvent) => void;
|
|
56
|
+
catchhtouchmove?: (event: GestureTouchEvent) => void;
|
|
57
|
+
catchvtouchmove?: (event: GestureTouchEvent) => void;
|
|
58
|
+
bindlongpress?: (event: GestureTouchEvent) => void;
|
|
59
|
+
catchlongpress?: (event: GestureTouchEvent) => void;
|
|
60
|
+
bindtap?: (event: GestureTouchEvent) => void;
|
|
61
|
+
catchtap?: (event: GestureTouchEvent) => void;
|
|
56
62
|
onLayout?: (event: LayoutChangeEvent) => void;
|
|
57
63
|
'out-of-bounds'?: boolean;
|
|
58
64
|
'wait-for'?: Array<GestureHandler>;
|
|
@@ -153,10 +159,10 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
153
159
|
})
|
|
154
160
|
|
|
155
161
|
const hasSimultaneousHandlersChanged = prevSimultaneousHandlersRef.current.length !== (originSimultaneousHandlers?.length || 0) ||
|
|
156
|
-
|
|
162
|
+
(originSimultaneousHandlers || []).some((handler, index) => handler !== prevSimultaneousHandlersRef.current[index])
|
|
157
163
|
|
|
158
164
|
const hasWaitForHandlersChanged = prevWaitForHandlersRef.current.length !== (waitFor?.length || 0) ||
|
|
159
|
-
|
|
165
|
+
(waitFor || []).some((handler, index) => handler !== prevWaitForHandlersRef.current[index])
|
|
160
166
|
|
|
161
167
|
if (hasSimultaneousHandlersChanged || hasWaitForHandlersChanged) {
|
|
162
168
|
gestureSwitch.current = !gestureSwitch.current
|
|
@@ -333,8 +339,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
333
339
|
props.onLayout && props.onLayout(e)
|
|
334
340
|
}
|
|
335
341
|
|
|
336
|
-
const extendEvent = useCallback((e: any) => {
|
|
337
|
-
'worklet'
|
|
342
|
+
const extendEvent = useCallback((e: any, obj?: Record<string, any>) => {
|
|
338
343
|
const touchArr = [e.changedTouches, e.allTouches]
|
|
339
344
|
touchArr.forEach(touches => {
|
|
340
345
|
touches && touches.forEach((item: { absoluteX: number; absoluteY: number; pageX: number; pageY: number }) => {
|
|
@@ -342,48 +347,69 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
342
347
|
item.pageY = item.absoluteY
|
|
343
348
|
})
|
|
344
349
|
})
|
|
345
|
-
e
|
|
350
|
+
Object.assign(e, {
|
|
351
|
+
touches: e.allTouches,
|
|
352
|
+
detail: {
|
|
353
|
+
x: e.changedTouches[0].absoluteX,
|
|
354
|
+
y: e.changedTouches[0].absoluteY
|
|
355
|
+
},
|
|
356
|
+
currentTarget: {
|
|
357
|
+
id: props.id || '',
|
|
358
|
+
dataset: collectDataset(props),
|
|
359
|
+
offsetLeft: 0,
|
|
360
|
+
offsetTop: 0
|
|
361
|
+
}
|
|
362
|
+
}, obj)
|
|
346
363
|
}, [])
|
|
347
364
|
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
catchtouchstart && runOnJS(catchtouchstart)(e)
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const handleTriggerMove = (e: any) => {
|
|
357
|
-
'worklet'
|
|
358
|
-
extendEvent(e)
|
|
359
|
-
const hasTouchmove = !!bindhtouchmove || !!bindvtouchmove || !!bindtouchmove
|
|
360
|
-
const hasCatchTouchmove = !!catchhtouchmove || !!catchvtouchmove || !!catchtouchmove
|
|
365
|
+
const triggerStartOnJS = ({ e }: { e: GestureTouchEvent }) => {
|
|
366
|
+
extendEvent(e)
|
|
367
|
+
bindtouchstart && bindtouchstart(e)
|
|
368
|
+
catchtouchstart && catchtouchstart(e)
|
|
369
|
+
}
|
|
361
370
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
371
|
+
const triggerMoveOnJS = ({ e, hasTouchmove, hasCatchTouchmove, touchEvent }: { e: GestureTouchEvent; hasTouchmove: boolean; hasCatchTouchmove: boolean; touchEvent: string }) => {
|
|
372
|
+
extendEvent(e)
|
|
373
|
+
if (hasTouchmove) {
|
|
374
|
+
if (touchEvent === 'htouchmove') {
|
|
375
|
+
bindhtouchmove && bindhtouchmove(e)
|
|
376
|
+
} else if (touchEvent === 'vtouchmove') {
|
|
377
|
+
bindvtouchmove && bindvtouchmove(e)
|
|
369
378
|
}
|
|
379
|
+
bindtouchmove && bindtouchmove(e)
|
|
380
|
+
}
|
|
370
381
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
catchtouchmove && runOnJS(catchtouchmove)(e)
|
|
382
|
+
if (hasCatchTouchmove) {
|
|
383
|
+
if (touchEvent === 'htouchmove') {
|
|
384
|
+
catchhtouchmove && catchhtouchmove(e)
|
|
385
|
+
} else if (touchEvent === 'vtouchmove') {
|
|
386
|
+
catchvtouchmove && catchvtouchmove(e)
|
|
378
387
|
}
|
|
388
|
+
catchtouchmove && catchtouchmove(e)
|
|
379
389
|
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const triggerEndOnJS = ({ e }: { e: GestureTouchEvent }) => {
|
|
393
|
+
extendEvent(e)
|
|
394
|
+
bindtouchend && bindtouchend(e)
|
|
395
|
+
catchtouchend && catchtouchend(e)
|
|
396
|
+
}
|
|
380
397
|
|
|
381
|
-
|
|
398
|
+
const gesture = useMemo(() => {
|
|
399
|
+
const handleTriggerMove = (e: GestureTouchEvent) => {
|
|
382
400
|
'worklet'
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
401
|
+
const hasTouchmove = !!bindhtouchmove || !!bindvtouchmove || !!bindtouchmove
|
|
402
|
+
const hasCatchTouchmove = !!catchhtouchmove || !!catchvtouchmove || !!catchtouchmove
|
|
403
|
+
if (hasTouchmove || hasCatchTouchmove) {
|
|
404
|
+
runOnJS(triggerMoveOnJS)({
|
|
405
|
+
e,
|
|
406
|
+
touchEvent: touchEvent.value,
|
|
407
|
+
hasTouchmove,
|
|
408
|
+
hasCatchTouchmove
|
|
409
|
+
})
|
|
410
|
+
}
|
|
386
411
|
}
|
|
412
|
+
|
|
387
413
|
const gesturePan = Gesture.Pan()
|
|
388
414
|
.onTouchesDown((e: GestureTouchEvent) => {
|
|
389
415
|
'worklet'
|
|
@@ -393,12 +419,14 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
393
419
|
x: changedTouches.x,
|
|
394
420
|
y: changedTouches.y
|
|
395
421
|
}
|
|
396
|
-
|
|
422
|
+
if (bindtouchstart || catchtouchstart) {
|
|
423
|
+
runOnJS(triggerStartOnJS)({ e })
|
|
424
|
+
}
|
|
397
425
|
})
|
|
398
426
|
.onTouchesMove((e: GestureTouchEvent) => {
|
|
399
427
|
'worklet'
|
|
400
|
-
isMoving.value = true
|
|
401
428
|
const changedTouches = e.changedTouches[0] || { x: 0, y: 0 }
|
|
429
|
+
isMoving.value = true
|
|
402
430
|
if (isFirstTouch.value) {
|
|
403
431
|
touchEvent.value = Math.abs(changedTouches.x - startPosition.value.x) > Math.abs(changedTouches.y - startPosition.value.y) ? 'htouchmove' : 'vtouchmove'
|
|
404
432
|
isFirstTouch.value = false
|
|
@@ -430,7 +458,9 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
430
458
|
'worklet'
|
|
431
459
|
isFirstTouch.value = true
|
|
432
460
|
isMoving.value = false
|
|
433
|
-
|
|
461
|
+
if (bindtouchend || catchtouchend) {
|
|
462
|
+
runOnJS(triggerEndOnJS)({ e })
|
|
463
|
+
}
|
|
434
464
|
if (disabled) return
|
|
435
465
|
if (!inertia) {
|
|
436
466
|
const { x, y } = checkBoundaryPosition({ positionX: offsetX.value, positionY: offsetY.value })
|
|
@@ -454,8 +484,8 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
454
484
|
})
|
|
455
485
|
.onFinalize((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
|
456
486
|
'worklet'
|
|
457
|
-
if (!inertia || disabled || !animation) return
|
|
458
487
|
isMoving.value = false
|
|
488
|
+
if (!inertia || disabled || !animation) return
|
|
459
489
|
if (direction === 'horizontal' || direction === 'all') {
|
|
460
490
|
xInertialMotion.value = true
|
|
461
491
|
offsetX.value = withDecay({
|
|
@@ -497,35 +527,50 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
497
527
|
}
|
|
498
528
|
})
|
|
499
529
|
|
|
500
|
-
const
|
|
501
|
-
const
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
{
|
|
505
|
-
{
|
|
530
|
+
const rewriteCatchEvent = () => {
|
|
531
|
+
const handlers: Record<string, typeof noop> = {}
|
|
532
|
+
|
|
533
|
+
const events = [
|
|
534
|
+
{ type: 'touchstart' },
|
|
535
|
+
{ type: 'touchmove', alias: ['vtouchmove', 'htouchmove'] },
|
|
536
|
+
{ type: 'touchend' }
|
|
506
537
|
]
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
})
|
|
538
|
+
events.forEach(({ type, alias = [] }) => {
|
|
539
|
+
const hasCatchEvent =
|
|
540
|
+
props[`catch${type}` as keyof typeof props] ||
|
|
541
|
+
alias.some(name => props[`catch${name}` as keyof typeof props])
|
|
542
|
+
if (hasCatchEvent) handlers[`catch${type}`] = noop
|
|
515
543
|
})
|
|
516
|
-
|
|
544
|
+
|
|
545
|
+
return handlers
|
|
517
546
|
}
|
|
518
547
|
|
|
519
|
-
const catchEventHandlers = injectCatchEvent(props)
|
|
520
548
|
const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {}
|
|
521
549
|
|
|
550
|
+
// bind 相关 touch 事件直接由 gesture 触发,无须重复挂载
|
|
551
|
+
// catch 相关 touch 事件需要重写并通过 useInnerProps 注入阻止冒泡逻辑
|
|
552
|
+
const filterProps = omit(props, [
|
|
553
|
+
'bindtouchstart',
|
|
554
|
+
'bindtouchmove',
|
|
555
|
+
'bindvtouchmove',
|
|
556
|
+
'bindhtouchmove',
|
|
557
|
+
'bindtouchend',
|
|
558
|
+
'catchtouchstart',
|
|
559
|
+
'catchtouchmove',
|
|
560
|
+
'catchvtouchmove',
|
|
561
|
+
'catchhtouchmove',
|
|
562
|
+
'catchtouchend'
|
|
563
|
+
])
|
|
564
|
+
|
|
565
|
+
const innerProps = useInnerProps(filterProps, extendObject({
|
|
566
|
+
ref: nodeRef,
|
|
567
|
+
onLayout: onLayout,
|
|
568
|
+
style: [innerStyle, animatedStyles, layoutStyle]
|
|
569
|
+
}, rewriteCatchEvent()))
|
|
570
|
+
|
|
522
571
|
return createElement(GestureDetector, { gesture: gesture }, createElement(
|
|
523
572
|
Animated.View,
|
|
524
|
-
|
|
525
|
-
ref: nodeRef,
|
|
526
|
-
onLayout: onLayout,
|
|
527
|
-
style: [innerStyle, animatedStyles, layoutStyle]
|
|
528
|
-
}, catchEventHandlers),
|
|
573
|
+
innerProps,
|
|
529
574
|
wrapChildren(
|
|
530
575
|
props,
|
|
531
576
|
{
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
|
+
import { LayoutChangeEvent } from 'react-native'
|
|
3
|
+
import Reanimated, { Extrapolation, interpolate, useAnimatedStyle, useSharedValue } from 'react-native-reanimated'
|
|
4
|
+
import { wrapChildren, extendObject } from './utils'
|
|
5
|
+
import { createFaces } from './pickerFaces'
|
|
6
|
+
import { usePickerViewColumnAnimationContext, usePickerViewStyleContext } from './pickerVIewContext'
|
|
7
|
+
|
|
8
|
+
interface PickerColumnItemProps {
|
|
9
|
+
item: React.ReactElement
|
|
10
|
+
index: number
|
|
11
|
+
itemHeight: number
|
|
12
|
+
itemWidth?: number | '100%'
|
|
13
|
+
textStyle: Record<string, any>
|
|
14
|
+
visibleCount: number
|
|
15
|
+
textProps?: any
|
|
16
|
+
onItemLayout?: (e: LayoutChangeEvent) => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
|
|
20
|
+
item,
|
|
21
|
+
index,
|
|
22
|
+
itemHeight,
|
|
23
|
+
itemWidth = '100%',
|
|
24
|
+
textStyle,
|
|
25
|
+
textProps,
|
|
26
|
+
visibleCount,
|
|
27
|
+
onItemLayout
|
|
28
|
+
}) => {
|
|
29
|
+
const textStyleFromAncestor = usePickerViewStyleContext()
|
|
30
|
+
const offsetYShared = usePickerViewColumnAnimationContext()
|
|
31
|
+
const facesShared = useSharedValue(createFaces(itemHeight, visibleCount))
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
facesShared.value = createFaces(itemHeight, visibleCount)
|
|
35
|
+
}, [itemHeight])
|
|
36
|
+
|
|
37
|
+
const animatedStyles = useAnimatedStyle(() => {
|
|
38
|
+
const inputRange = facesShared.value.map((f) => itemHeight * (index + f.index))
|
|
39
|
+
return {
|
|
40
|
+
opacity: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.opacity), Extrapolation.CLAMP),
|
|
41
|
+
transform: [
|
|
42
|
+
{ translateY: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.offsetY), Extrapolation.EXTEND) },
|
|
43
|
+
{ rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
|
|
44
|
+
{ scale: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.scale), Extrapolation.EXTEND) }
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const strKey = `picker-column-item-${index}`
|
|
50
|
+
const restProps = index === 0 ? { onLayout: onItemLayout } : {}
|
|
51
|
+
const itemProps = extendObject(
|
|
52
|
+
{
|
|
53
|
+
style: extendObject(
|
|
54
|
+
{ height: itemHeight, width: '100%' },
|
|
55
|
+
textStyleFromAncestor,
|
|
56
|
+
textStyle,
|
|
57
|
+
item.props.style
|
|
58
|
+
)
|
|
59
|
+
},
|
|
60
|
+
textProps,
|
|
61
|
+
restProps
|
|
62
|
+
)
|
|
63
|
+
const realItem = React.cloneElement(item, itemProps)
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Reanimated.View
|
|
67
|
+
key={strKey}
|
|
68
|
+
style={[{ height: itemHeight, width: itemWidth }, animatedStyles]}
|
|
69
|
+
>
|
|
70
|
+
{realItem}
|
|
71
|
+
</Reanimated.View>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
PickerViewColumnItem.displayName = 'MpxPickerViewColumnItem'
|
|
76
|
+
export default PickerViewColumnItem
|