@mpxjs/webpack-plugin 2.10.4-beta.12 → 2.10.4-beta.14
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.
|
@@ -4,7 +4,7 @@ import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS
|
|
|
4
4
|
import React, { forwardRef, useRef, useEffect, useMemo } from 'react';
|
|
5
5
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
6
6
|
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
7
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject } from './utils';
|
|
7
|
+
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, flatGesture } from './utils';
|
|
8
8
|
import { SwiperContext } from './context';
|
|
9
9
|
/**
|
|
10
10
|
* 默认的Style类型
|
|
@@ -70,11 +70,13 @@ const easeMap = {
|
|
|
70
70
|
easeInOutCubic: Easing.inOut(Easing.cubic)
|
|
71
71
|
};
|
|
72
72
|
const SwiperWrapper = forwardRef((props, ref) => {
|
|
73
|
-
const { 'indicator-dots': showsPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, style = {}, autoplay = false, circular = false } = props;
|
|
73
|
+
const { 'indicator-dots': showsPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], style = {}, autoplay = false, circular = false, disableGesture = false } = props;
|
|
74
74
|
const easeingFunc = props['easing-function'] || 'default';
|
|
75
75
|
const easeDuration = props.duration || 500;
|
|
76
76
|
const horizontal = props.vertical !== undefined ? !props.vertical : true;
|
|
77
77
|
const nodeRef = useRef(null);
|
|
78
|
+
// 手势协同gesture 1.0
|
|
79
|
+
const swiperGestureRef = useRef();
|
|
78
80
|
useNodesRef(props, ref, nodeRef, {});
|
|
79
81
|
// 计算transfrom之类的
|
|
80
82
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, {
|
|
@@ -119,8 +121,29 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
119
121
|
const moveTranstion = useSharedValue(0);
|
|
120
122
|
// 记录从onBegin 到 onTouchesUp 的时间
|
|
121
123
|
const moveTime = useSharedValue(0);
|
|
124
|
+
// 记录从onBegin 到 onTouchesCancelled 另外一个方向移动的距离
|
|
125
|
+
const anotherDirectionMove = useSharedValue(0);
|
|
126
|
+
// 另一个方向的
|
|
127
|
+
const anotherAbso = 'absolute' + (dir === 'x' ? 'y' : 'x').toUpperCase();
|
|
122
128
|
const timerId = useRef(0);
|
|
123
129
|
const intervalTimer = props.interval || 500;
|
|
130
|
+
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
131
|
+
const waitForHandlers = flatGesture(waitFor);
|
|
132
|
+
// 判断gesture手势是否需要协同处理、等待手势失败响应
|
|
133
|
+
const gestureSwitch = useRef(false);
|
|
134
|
+
// 初始化上一次的手势
|
|
135
|
+
const prevSimultaneousHandlersRef = useRef(originSimultaneousHandlers || []);
|
|
136
|
+
const prevWaitForHandlersRef = useRef(waitFor || []);
|
|
137
|
+
const hasSimultaneousHandlersChanged = prevSimultaneousHandlersRef.current.length !== (originSimultaneousHandlers?.length || 0) ||
|
|
138
|
+
(originSimultaneousHandlers || []).some((handler, index) => handler !== prevSimultaneousHandlersRef.current[index]);
|
|
139
|
+
const hasWaitForHandlersChanged = prevWaitForHandlersRef.current.length !== (waitFor?.length || 0) ||
|
|
140
|
+
(waitFor || []).some((handler, index) => handler !== prevWaitForHandlersRef.current[index]);
|
|
141
|
+
if (hasSimultaneousHandlersChanged || hasWaitForHandlersChanged) {
|
|
142
|
+
gestureSwitch.current = !gestureSwitch.current;
|
|
143
|
+
}
|
|
144
|
+
// 存储上一次的手势
|
|
145
|
+
prevSimultaneousHandlersRef.current = originSimultaneousHandlers || [];
|
|
146
|
+
prevWaitForHandlersRef.current = waitFor || [];
|
|
124
147
|
const {
|
|
125
148
|
// 存储layout布局信息
|
|
126
149
|
layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout: onWrapperLayout });
|
|
@@ -384,6 +407,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
384
407
|
}
|
|
385
408
|
}, [children.length]);
|
|
386
409
|
useEffect(() => {
|
|
410
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
|
|
387
411
|
updateCurrent(props.current || 0, step.value);
|
|
388
412
|
}, [props.current]);
|
|
389
413
|
useEffect(() => {
|
|
@@ -447,20 +471,26 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
447
471
|
targetOffset: -moveToTargetPos
|
|
448
472
|
};
|
|
449
473
|
}
|
|
450
|
-
function
|
|
474
|
+
function checkUnCircular(eventData) {
|
|
451
475
|
'worklet';
|
|
452
476
|
const { translation } = eventData;
|
|
453
477
|
const currentOffset = Math.abs(offset.value);
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
478
|
+
// 向右滑动swiper
|
|
479
|
+
if (translation < 0) {
|
|
480
|
+
const boundaryOffset = step.value * (childrenLength.value - 1);
|
|
481
|
+
const gestureMovePos = Math.abs(translation) + currentOffset;
|
|
482
|
+
return {
|
|
483
|
+
// 防止快速连续向右滑动时,手势移动的距离 加 当前的offset超出边界
|
|
484
|
+
targetOffset: gestureMovePos > boundaryOffset ? -boundaryOffset : offset.value + translation,
|
|
485
|
+
canMove: currentOffset < boundaryOffset
|
|
486
|
+
};
|
|
461
487
|
}
|
|
462
488
|
else {
|
|
463
|
-
|
|
489
|
+
const gestureMovePos = currentOffset - translation;
|
|
490
|
+
return {
|
|
491
|
+
targetOffset: gestureMovePos < 0 ? 0 : offset.value + translation,
|
|
492
|
+
canMove: currentOffset > 0
|
|
493
|
+
};
|
|
464
494
|
}
|
|
465
495
|
}
|
|
466
496
|
function handleEnd(eventData) {
|
|
@@ -511,7 +541,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
511
541
|
}
|
|
512
542
|
});
|
|
513
543
|
}
|
|
514
|
-
function
|
|
544
|
+
function computeHalf() {
|
|
515
545
|
'worklet';
|
|
516
546
|
const currentOffset = Math.abs(offset.value);
|
|
517
547
|
let preOffset = (currentIndex.value + patchElmNumShared.value) * step.value;
|
|
@@ -521,6 +551,14 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
521
551
|
// 正常事件中拿到的transition值(正向滑动<0,倒着滑>0)
|
|
522
552
|
const diffOffset = preOffset - currentOffset;
|
|
523
553
|
const half = Math.abs(diffOffset) > step.value / 2;
|
|
554
|
+
return {
|
|
555
|
+
diffOffset,
|
|
556
|
+
half
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
function handleLongPress() {
|
|
560
|
+
'worklet';
|
|
561
|
+
const { diffOffset, half } = computeHalf();
|
|
524
562
|
if (+diffOffset === 0) {
|
|
525
563
|
runOnJS(resumeLoop)();
|
|
526
564
|
}
|
|
@@ -580,21 +618,32 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
580
618
|
runOnJS(pauseLoop)();
|
|
581
619
|
preAbsolutePos.value = e[strAbso];
|
|
582
620
|
moveTranstion.value = e[strAbso];
|
|
621
|
+
anotherDirectionMove.value = e[anotherAbso];
|
|
583
622
|
moveTime.value = new Date().getTime();
|
|
584
623
|
})
|
|
585
|
-
.
|
|
624
|
+
.onUpdate((e) => {
|
|
586
625
|
'worklet';
|
|
587
626
|
if (touchfinish.value)
|
|
588
627
|
return;
|
|
589
|
-
const
|
|
590
|
-
const moveDistance = touchEventData[strAbso] - preAbsolutePos.value;
|
|
628
|
+
const moveDistance = e[strAbso] - preAbsolutePos.value;
|
|
591
629
|
const eventData = {
|
|
592
630
|
translation: moveDistance
|
|
593
631
|
};
|
|
594
632
|
// 处理用户一直拖拽到临界点的场景, 不会执行onEnd
|
|
595
|
-
|
|
633
|
+
const { canMove, targetOffset } = checkUnCircular(eventData);
|
|
634
|
+
if (!circularShared.value) {
|
|
635
|
+
if (canMove) {
|
|
636
|
+
offset.value = targetOffset;
|
|
637
|
+
preAbsolutePos.value = e[strAbso];
|
|
638
|
+
}
|
|
596
639
|
return;
|
|
597
640
|
}
|
|
641
|
+
const { half } = computeHalf();
|
|
642
|
+
// 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
|
|
643
|
+
if (half) {
|
|
644
|
+
const { selectedIndex } = getTargetPosition(eventData);
|
|
645
|
+
currentIndex.value = selectedIndex;
|
|
646
|
+
}
|
|
598
647
|
const { isBoundary, resetOffset } = reachBoundary(eventData);
|
|
599
648
|
if (isBoundary && circularShared.value) {
|
|
600
649
|
offset.value = resetOffset;
|
|
@@ -602,20 +651,20 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
602
651
|
else {
|
|
603
652
|
offset.value = moveDistance + offset.value;
|
|
604
653
|
}
|
|
605
|
-
preAbsolutePos.value =
|
|
654
|
+
preAbsolutePos.value = e[strAbso];
|
|
606
655
|
})
|
|
607
|
-
.
|
|
656
|
+
.onFinalize((e) => {
|
|
608
657
|
'worklet';
|
|
609
658
|
if (touchfinish.value)
|
|
610
659
|
return;
|
|
611
|
-
const
|
|
612
|
-
const moveDistance = touchEventData[strAbso] - moveTranstion.value;
|
|
660
|
+
const moveDistance = e[strAbso] - moveTranstion.value;
|
|
613
661
|
touchfinish.value = true;
|
|
614
662
|
const eventData = {
|
|
615
663
|
translation: moveDistance
|
|
616
664
|
};
|
|
617
665
|
// 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
|
|
618
|
-
|
|
666
|
+
const { canMove } = checkUnCircular(eventData);
|
|
667
|
+
if (!circularShared.value && !canMove) {
|
|
619
668
|
return;
|
|
620
669
|
}
|
|
621
670
|
const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000;
|
|
@@ -625,11 +674,25 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
625
674
|
else {
|
|
626
675
|
handleEnd(eventData);
|
|
627
676
|
}
|
|
628
|
-
});
|
|
677
|
+
}).withRef(swiperGestureRef);
|
|
678
|
+
// swiper横向,当y轴滑动5像素手势失效;swiper纵向只响应swiper的滑动事件
|
|
679
|
+
if (dir === 'x') {
|
|
680
|
+
gesturePan.activeOffsetX([-5, 5]).failOffsetY([-5, 5]);
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5]);
|
|
684
|
+
}
|
|
685
|
+
// 手势协同2.0
|
|
686
|
+
if (simultaneousHandlers && simultaneousHandlers.length) {
|
|
687
|
+
gesturePan.simultaneousWithExternalGesture(...simultaneousHandlers);
|
|
688
|
+
}
|
|
689
|
+
if (waitForHandlers && waitForHandlers.length) {
|
|
690
|
+
gesturePan.requireExternalGestureToFail(...waitForHandlers);
|
|
691
|
+
}
|
|
629
692
|
return {
|
|
630
693
|
gestureHandler: gesturePan
|
|
631
694
|
};
|
|
632
|
-
}, []);
|
|
695
|
+
}, [gestureSwitch.current]);
|
|
633
696
|
const animatedStyles = useAnimatedStyle(() => {
|
|
634
697
|
if (dir === 'x') {
|
|
635
698
|
return { transform: [{ translateX: offset.value }], opacity: step.value > 0 ? 1 : 0 };
|
|
@@ -658,7 +721,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
658
721
|
{showsPagination && renderPagination()}
|
|
659
722
|
</View>);
|
|
660
723
|
}
|
|
661
|
-
if (children.length === 1) {
|
|
724
|
+
if (children.length === 1 || disableGesture) {
|
|
662
725
|
return renderSwiper();
|
|
663
726
|
}
|
|
664
727
|
else {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { View, NativeSyntheticEvent, LayoutChangeEvent } from 'react-native'
|
|
2
|
-
import { GestureDetector, Gesture } from 'react-native-gesture-handler'
|
|
2
|
+
import { GestureDetector, Gesture, PanGesture } from 'react-native-gesture-handler'
|
|
3
3
|
import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS, useAnimatedReaction, cancelAnimation } from 'react-native-reanimated'
|
|
4
4
|
|
|
5
5
|
import React, { JSX, forwardRef, useRef, useEffect, ReactNode, ReactElement, useMemo } from 'react'
|
|
6
6
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
8
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject } from './utils'
|
|
8
|
+
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, GestureHandler, flatGesture } from './utils'
|
|
9
9
|
import { SwiperContext } from './context'
|
|
10
10
|
/**
|
|
11
11
|
* ✔ indicator-dots
|
|
@@ -22,6 +22,7 @@ import { SwiperContext } from './context'
|
|
|
22
22
|
* ✔ easing-function ="easeOutCubic"
|
|
23
23
|
* ✘ display-multiple-items
|
|
24
24
|
* ✘ snap-to-edge
|
|
25
|
+
* ✔ disableGesture
|
|
25
26
|
*/
|
|
26
27
|
type EaseType = 'default' | 'linear' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'
|
|
27
28
|
type StrAbsoType = 'absoluteX' | 'absoluteY'
|
|
@@ -55,6 +56,9 @@ interface SwiperProps {
|
|
|
55
56
|
'parent-width'?: number
|
|
56
57
|
'parent-height'?: number
|
|
57
58
|
'external-var-context'?: Record<string, any>
|
|
59
|
+
'wait-for'?: Array<GestureHandler>
|
|
60
|
+
'simultaneous-handlers'?: Array<GestureHandler>
|
|
61
|
+
disableGesture?: boolean
|
|
58
62
|
bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
59
63
|
}
|
|
60
64
|
|
|
@@ -134,14 +138,19 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
134
138
|
'parent-width': parentWidth,
|
|
135
139
|
'parent-height': parentHeight,
|
|
136
140
|
'external-var-context': externalVarContext,
|
|
141
|
+
'simultaneous-handlers': originSimultaneousHandlers = [],
|
|
142
|
+
'wait-for': waitFor = [],
|
|
137
143
|
style = {},
|
|
138
144
|
autoplay = false,
|
|
139
|
-
circular = false
|
|
145
|
+
circular = false,
|
|
146
|
+
disableGesture = false
|
|
140
147
|
} = props
|
|
141
148
|
const easeingFunc = props['easing-function'] || 'default'
|
|
142
149
|
const easeDuration = props.duration || 500
|
|
143
150
|
const horizontal = props.vertical !== undefined ? !props.vertical : true
|
|
144
151
|
const nodeRef = useRef<View>(null)
|
|
152
|
+
// 手势协同gesture 1.0
|
|
153
|
+
const swiperGestureRef = useRef<PanGesture>()
|
|
145
154
|
useNodesRef<View, SwiperProps>(props, ref, nodeRef, {})
|
|
146
155
|
// 计算transfrom之类的
|
|
147
156
|
const {
|
|
@@ -193,8 +202,31 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
193
202
|
const moveTranstion = useSharedValue(0)
|
|
194
203
|
// 记录从onBegin 到 onTouchesUp 的时间
|
|
195
204
|
const moveTime = useSharedValue(0)
|
|
205
|
+
// 记录从onBegin 到 onTouchesCancelled 另外一个方向移动的距离
|
|
206
|
+
const anotherDirectionMove = useSharedValue(0)
|
|
207
|
+
// 另一个方向的
|
|
208
|
+
const anotherAbso = 'absolute' + (dir === 'x' ? 'y' : 'x').toUpperCase() as StrAbsoType
|
|
196
209
|
const timerId = useRef(0 as number | ReturnType<typeof setTimeout>)
|
|
197
210
|
const intervalTimer = props.interval || 500
|
|
211
|
+
const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
|
|
212
|
+
const waitForHandlers = flatGesture(waitFor)
|
|
213
|
+
// 判断gesture手势是否需要协同处理、等待手势失败响应
|
|
214
|
+
const gestureSwitch = useRef(false)
|
|
215
|
+
// 初始化上一次的手势
|
|
216
|
+
const prevSimultaneousHandlersRef = useRef<Array<GestureHandler>>(originSimultaneousHandlers || [])
|
|
217
|
+
const prevWaitForHandlersRef = useRef<Array<GestureHandler>>(waitFor || [])
|
|
218
|
+
const hasSimultaneousHandlersChanged = prevSimultaneousHandlersRef.current.length !== (originSimultaneousHandlers?.length || 0) ||
|
|
219
|
+
(originSimultaneousHandlers || []).some((handler, index) => handler !== prevSimultaneousHandlersRef.current[index])
|
|
220
|
+
|
|
221
|
+
const hasWaitForHandlersChanged = prevWaitForHandlersRef.current.length !== (waitFor?.length || 0) ||
|
|
222
|
+
(waitFor || []).some((handler, index) => handler !== prevWaitForHandlersRef.current[index])
|
|
223
|
+
|
|
224
|
+
if (hasSimultaneousHandlersChanged || hasWaitForHandlersChanged) {
|
|
225
|
+
gestureSwitch.current = !gestureSwitch.current
|
|
226
|
+
}
|
|
227
|
+
// 存储上一次的手势
|
|
228
|
+
prevSimultaneousHandlersRef.current = originSimultaneousHandlers || []
|
|
229
|
+
prevWaitForHandlersRef.current = waitFor || []
|
|
198
230
|
const {
|
|
199
231
|
// 存储layout布局信息
|
|
200
232
|
layoutRef,
|
|
@@ -471,6 +503,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
471
503
|
}, [children.length])
|
|
472
504
|
|
|
473
505
|
useEffect(() => {
|
|
506
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
|
|
474
507
|
updateCurrent(props.current || 0, step.value)
|
|
475
508
|
}, [props.current])
|
|
476
509
|
|
|
@@ -534,18 +567,25 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
534
567
|
targetOffset: -moveToTargetPos
|
|
535
568
|
}
|
|
536
569
|
}
|
|
537
|
-
function
|
|
570
|
+
function checkUnCircular (eventData: EventDataType) {
|
|
538
571
|
'worklet'
|
|
539
572
|
const { translation } = eventData
|
|
540
573
|
const currentOffset = Math.abs(offset.value)
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
574
|
+
// 向右滑动swiper
|
|
575
|
+
if (translation < 0) {
|
|
576
|
+
const boundaryOffset = step.value * (childrenLength.value - 1)
|
|
577
|
+
const gestureMovePos = Math.abs(translation) + currentOffset
|
|
578
|
+
return {
|
|
579
|
+
// 防止快速连续向右滑动时,手势移动的距离 加 当前的offset超出边界
|
|
580
|
+
targetOffset: gestureMovePos > boundaryOffset ? -boundaryOffset : offset.value + translation,
|
|
581
|
+
canMove: currentOffset < boundaryOffset
|
|
546
582
|
}
|
|
547
583
|
} else {
|
|
548
|
-
|
|
584
|
+
const gestureMovePos = currentOffset - translation
|
|
585
|
+
return {
|
|
586
|
+
targetOffset: gestureMovePos < 0 ? 0 : offset.value + translation,
|
|
587
|
+
canMove: currentOffset > 0
|
|
588
|
+
}
|
|
549
589
|
}
|
|
550
590
|
}
|
|
551
591
|
function handleEnd (eventData: EventDataType) {
|
|
@@ -595,7 +635,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
595
635
|
}
|
|
596
636
|
})
|
|
597
637
|
}
|
|
598
|
-
function
|
|
638
|
+
function computeHalf () {
|
|
599
639
|
'worklet'
|
|
600
640
|
const currentOffset = Math.abs(offset.value)
|
|
601
641
|
let preOffset = (currentIndex.value + patchElmNumShared.value) * step.value
|
|
@@ -605,6 +645,14 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
605
645
|
// 正常事件中拿到的transition值(正向滑动<0,倒着滑>0)
|
|
606
646
|
const diffOffset = preOffset - currentOffset
|
|
607
647
|
const half = Math.abs(diffOffset) > step.value / 2
|
|
648
|
+
return {
|
|
649
|
+
diffOffset,
|
|
650
|
+
half
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
function handleLongPress () {
|
|
654
|
+
'worklet'
|
|
655
|
+
const { diffOffset, half } = computeHalf()
|
|
608
656
|
if (+diffOffset === 0) {
|
|
609
657
|
runOnJS(resumeLoop)()
|
|
610
658
|
} else if (half) {
|
|
@@ -660,39 +708,50 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
660
708
|
runOnJS(pauseLoop)()
|
|
661
709
|
preAbsolutePos.value = e[strAbso]
|
|
662
710
|
moveTranstion.value = e[strAbso]
|
|
711
|
+
anotherDirectionMove.value = e[anotherAbso]
|
|
663
712
|
moveTime.value = new Date().getTime()
|
|
664
713
|
})
|
|
665
|
-
.
|
|
714
|
+
.onUpdate((e) => {
|
|
666
715
|
'worklet'
|
|
667
716
|
if (touchfinish.value) return
|
|
668
|
-
const
|
|
669
|
-
const moveDistance = touchEventData[strAbso] - preAbsolutePos.value
|
|
717
|
+
const moveDistance = e[strAbso] - preAbsolutePos.value
|
|
670
718
|
const eventData = {
|
|
671
719
|
translation: moveDistance
|
|
672
720
|
}
|
|
673
721
|
// 处理用户一直拖拽到临界点的场景, 不会执行onEnd
|
|
674
|
-
|
|
722
|
+
const { canMove, targetOffset } = checkUnCircular(eventData)
|
|
723
|
+
if (!circularShared.value) {
|
|
724
|
+
if (canMove) {
|
|
725
|
+
offset.value = targetOffset
|
|
726
|
+
preAbsolutePos.value = e[strAbso]
|
|
727
|
+
}
|
|
675
728
|
return
|
|
676
729
|
}
|
|
730
|
+
const { half } = computeHalf()
|
|
731
|
+
// 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
|
|
732
|
+
if (half) {
|
|
733
|
+
const { selectedIndex } = getTargetPosition(eventData)
|
|
734
|
+
currentIndex.value = selectedIndex
|
|
735
|
+
}
|
|
677
736
|
const { isBoundary, resetOffset } = reachBoundary(eventData)
|
|
678
737
|
if (isBoundary && circularShared.value) {
|
|
679
738
|
offset.value = resetOffset
|
|
680
739
|
} else {
|
|
681
740
|
offset.value = moveDistance + offset.value
|
|
682
741
|
}
|
|
683
|
-
preAbsolutePos.value =
|
|
742
|
+
preAbsolutePos.value = e[strAbso]
|
|
684
743
|
})
|
|
685
|
-
.
|
|
744
|
+
.onFinalize((e) => {
|
|
686
745
|
'worklet'
|
|
687
746
|
if (touchfinish.value) return
|
|
688
|
-
const
|
|
689
|
-
const moveDistance = touchEventData[strAbso] - moveTranstion.value
|
|
747
|
+
const moveDistance = e[strAbso] - moveTranstion.value
|
|
690
748
|
touchfinish.value = true
|
|
691
749
|
const eventData = {
|
|
692
750
|
translation: moveDistance
|
|
693
751
|
}
|
|
694
752
|
// 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
|
|
695
|
-
|
|
753
|
+
const { canMove } = checkUnCircular(eventData)
|
|
754
|
+
if (!circularShared.value && !canMove) {
|
|
696
755
|
return
|
|
697
756
|
}
|
|
698
757
|
const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000
|
|
@@ -701,11 +760,25 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
701
760
|
} else {
|
|
702
761
|
handleEnd(eventData)
|
|
703
762
|
}
|
|
704
|
-
})
|
|
763
|
+
}).withRef(swiperGestureRef)
|
|
764
|
+
// swiper横向,当y轴滑动5像素手势失效;swiper纵向只响应swiper的滑动事件
|
|
765
|
+
if (dir === 'x') {
|
|
766
|
+
gesturePan.activeOffsetX([-5, 5]).failOffsetY([-5, 5])
|
|
767
|
+
} else {
|
|
768
|
+
gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5])
|
|
769
|
+
}
|
|
770
|
+
// 手势协同2.0
|
|
771
|
+
if (simultaneousHandlers && simultaneousHandlers.length) {
|
|
772
|
+
gesturePan.simultaneousWithExternalGesture(...simultaneousHandlers)
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
if (waitForHandlers && waitForHandlers.length) {
|
|
776
|
+
gesturePan.requireExternalGestureToFail(...waitForHandlers)
|
|
777
|
+
}
|
|
705
778
|
return {
|
|
706
779
|
gestureHandler: gesturePan
|
|
707
780
|
}
|
|
708
|
-
}, [])
|
|
781
|
+
}, [gestureSwitch.current])
|
|
709
782
|
|
|
710
783
|
const animatedStyles = useAnimatedStyle(() => {
|
|
711
784
|
if (dir === 'x') {
|
|
@@ -736,7 +809,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
736
809
|
</View>)
|
|
737
810
|
}
|
|
738
811
|
|
|
739
|
-
if (children.length === 1) {
|
|
812
|
+
if (children.length === 1 || disableGesture) {
|
|
740
813
|
return renderSwiper()
|
|
741
814
|
} else {
|
|
742
815
|
return (<GestureDetector gesture={gestureHandler}>
|