@mpxjs/webpack-plugin 2.10.4-beta.13 → 2.10.4-beta.15
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.
|
@@ -70,7 +70,7 @@ 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, 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], 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;
|
|
@@ -121,6 +121,10 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
121
121
|
const moveTranstion = useSharedValue(0);
|
|
122
122
|
// 记录从onBegin 到 onTouchesUp 的时间
|
|
123
123
|
const moveTime = useSharedValue(0);
|
|
124
|
+
// 记录从onBegin 到 onTouchesCancelled 另外一个方向移动的距离
|
|
125
|
+
const anotherDirectionMove = useSharedValue(0);
|
|
126
|
+
// 另一个方向的
|
|
127
|
+
const anotherAbso = 'absolute' + (dir === 'x' ? 'y' : 'x').toUpperCase();
|
|
124
128
|
const timerId = useRef(0);
|
|
125
129
|
const intervalTimer = props.interval || 500;
|
|
126
130
|
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
@@ -403,7 +407,11 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
403
407
|
}
|
|
404
408
|
}, [children.length]);
|
|
405
409
|
useEffect(() => {
|
|
406
|
-
|
|
410
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
|
|
411
|
+
// 2. 手指滑动过程中更新索引,外部会把current再穿进来,导致offset直接更新了
|
|
412
|
+
if (props.current !== currentIndex.value) {
|
|
413
|
+
updateCurrent(props.current || 0, step.value);
|
|
414
|
+
}
|
|
407
415
|
}, [props.current]);
|
|
408
416
|
useEffect(() => {
|
|
409
417
|
autoplayShared.value = autoplay;
|
|
@@ -466,20 +474,26 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
466
474
|
targetOffset: -moveToTargetPos
|
|
467
475
|
};
|
|
468
476
|
}
|
|
469
|
-
function
|
|
477
|
+
function checkUnCircular(eventData) {
|
|
470
478
|
'worklet';
|
|
471
479
|
const { translation } = eventData;
|
|
472
480
|
const currentOffset = Math.abs(offset.value);
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
481
|
+
// 向右滑动swiper
|
|
482
|
+
if (translation < 0) {
|
|
483
|
+
const boundaryOffset = step.value * (childrenLength.value - 1);
|
|
484
|
+
const gestureMovePos = Math.abs(translation) + currentOffset;
|
|
485
|
+
return {
|
|
486
|
+
// 防止快速连续向右滑动时,手势移动的距离 加 当前的offset超出边界
|
|
487
|
+
targetOffset: gestureMovePos > boundaryOffset ? -boundaryOffset : offset.value + translation,
|
|
488
|
+
canMove: currentOffset < boundaryOffset
|
|
489
|
+
};
|
|
480
490
|
}
|
|
481
491
|
else {
|
|
482
|
-
|
|
492
|
+
const gestureMovePos = currentOffset - translation;
|
|
493
|
+
return {
|
|
494
|
+
targetOffset: gestureMovePos < 0 ? 0 : offset.value + translation,
|
|
495
|
+
canMove: currentOffset > 0
|
|
496
|
+
};
|
|
483
497
|
}
|
|
484
498
|
}
|
|
485
499
|
function handleEnd(eventData) {
|
|
@@ -530,7 +544,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
530
544
|
}
|
|
531
545
|
});
|
|
532
546
|
}
|
|
533
|
-
function
|
|
547
|
+
function computeHalf() {
|
|
534
548
|
'worklet';
|
|
535
549
|
const currentOffset = Math.abs(offset.value);
|
|
536
550
|
let preOffset = (currentIndex.value + patchElmNumShared.value) * step.value;
|
|
@@ -540,6 +554,14 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
540
554
|
// 正常事件中拿到的transition值(正向滑动<0,倒着滑>0)
|
|
541
555
|
const diffOffset = preOffset - currentOffset;
|
|
542
556
|
const half = Math.abs(diffOffset) > step.value / 2;
|
|
557
|
+
return {
|
|
558
|
+
diffOffset,
|
|
559
|
+
half
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function handleLongPress() {
|
|
563
|
+
'worklet';
|
|
564
|
+
const { diffOffset, half } = computeHalf();
|
|
543
565
|
if (+diffOffset === 0) {
|
|
544
566
|
runOnJS(resumeLoop)();
|
|
545
567
|
}
|
|
@@ -599,19 +621,30 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
599
621
|
runOnJS(pauseLoop)();
|
|
600
622
|
preAbsolutePos.value = e[strAbso];
|
|
601
623
|
moveTranstion.value = e[strAbso];
|
|
624
|
+
anotherDirectionMove.value = e[anotherAbso];
|
|
602
625
|
moveTime.value = new Date().getTime();
|
|
603
626
|
})
|
|
604
|
-
.
|
|
627
|
+
.onUpdate((e) => {
|
|
605
628
|
'worklet';
|
|
606
629
|
if (touchfinish.value)
|
|
607
630
|
return;
|
|
608
|
-
const
|
|
609
|
-
const moveDistance = touchEventData[strAbso] - preAbsolutePos.value;
|
|
631
|
+
const moveDistance = e[strAbso] - preAbsolutePos.value;
|
|
610
632
|
const eventData = {
|
|
611
633
|
translation: moveDistance
|
|
612
634
|
};
|
|
613
|
-
//
|
|
614
|
-
|
|
635
|
+
// 1. 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
|
|
636
|
+
const { half } = computeHalf();
|
|
637
|
+
if (half) {
|
|
638
|
+
const { selectedIndex } = getTargetPosition(eventData);
|
|
639
|
+
currentIndex.value = selectedIndex;
|
|
640
|
+
}
|
|
641
|
+
// 2. 处理用户一直拖拽到临界点的场景, 不会执行onEnd
|
|
642
|
+
const { canMove, targetOffset } = checkUnCircular(eventData);
|
|
643
|
+
if (!circularShared.value) {
|
|
644
|
+
if (canMove) {
|
|
645
|
+
offset.value = targetOffset;
|
|
646
|
+
preAbsolutePos.value = e[strAbso];
|
|
647
|
+
}
|
|
615
648
|
return;
|
|
616
649
|
}
|
|
617
650
|
const { isBoundary, resetOffset } = reachBoundary(eventData);
|
|
@@ -621,36 +654,32 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
621
654
|
else {
|
|
622
655
|
offset.value = moveDistance + offset.value;
|
|
623
656
|
}
|
|
624
|
-
preAbsolutePos.value =
|
|
657
|
+
preAbsolutePos.value = e[strAbso];
|
|
625
658
|
})
|
|
626
|
-
.
|
|
659
|
+
.onFinalize((e) => {
|
|
627
660
|
'worklet';
|
|
628
661
|
if (touchfinish.value)
|
|
629
662
|
return;
|
|
630
|
-
const
|
|
631
|
-
const moveDistance = touchEventData[strAbso] - moveTranstion.value;
|
|
663
|
+
const moveDistance = e[strAbso] - moveTranstion.value;
|
|
632
664
|
touchfinish.value = true;
|
|
633
665
|
const eventData = {
|
|
634
666
|
translation: moveDistance
|
|
635
667
|
};
|
|
636
|
-
// 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
|
|
637
|
-
if (!circularShared.value && !canMove(eventData)) {
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
668
|
const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000;
|
|
641
669
|
if (Math.abs(strVelocity) < longPressRatio) {
|
|
642
670
|
handleLongPress();
|
|
643
671
|
}
|
|
644
672
|
else {
|
|
673
|
+
// 如果触发了onTouchesCancelled,不会触发onUpdate不会更新offset值, 索引不会变更
|
|
645
674
|
handleEnd(eventData);
|
|
646
675
|
}
|
|
647
676
|
}).withRef(swiperGestureRef);
|
|
648
677
|
// swiper横向,当y轴滑动5像素手势失效;swiper纵向只响应swiper的滑动事件
|
|
649
678
|
if (dir === 'x') {
|
|
650
|
-
gesturePan.activeOffsetX([-
|
|
679
|
+
gesturePan.activeOffsetX([-5, 5]).failOffsetY([-5, 5]);
|
|
651
680
|
}
|
|
652
681
|
else {
|
|
653
|
-
gesturePan.activeOffsetY([-
|
|
682
|
+
gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5]);
|
|
654
683
|
}
|
|
655
684
|
// 手势协同2.0
|
|
656
685
|
if (simultaneousHandlers && simultaneousHandlers.length) {
|
|
@@ -691,7 +720,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
691
720
|
{showsPagination && renderPagination()}
|
|
692
721
|
</View>);
|
|
693
722
|
}
|
|
694
|
-
if (children.length === 1) {
|
|
723
|
+
if (children.length === 1 || disableGesture) {
|
|
695
724
|
return renderSwiper();
|
|
696
725
|
}
|
|
697
726
|
else {
|
|
@@ -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'
|
|
@@ -57,6 +58,7 @@ interface SwiperProps {
|
|
|
57
58
|
'external-var-context'?: Record<string, any>
|
|
58
59
|
'wait-for'?: Array<GestureHandler>
|
|
59
60
|
'simultaneous-handlers'?: Array<GestureHandler>
|
|
61
|
+
disableGesture?: boolean
|
|
60
62
|
bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -140,7 +142,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
140
142
|
'wait-for': waitFor = [],
|
|
141
143
|
style = {},
|
|
142
144
|
autoplay = false,
|
|
143
|
-
circular = false
|
|
145
|
+
circular = false,
|
|
146
|
+
disableGesture = false
|
|
144
147
|
} = props
|
|
145
148
|
const easeingFunc = props['easing-function'] || 'default'
|
|
146
149
|
const easeDuration = props.duration || 500
|
|
@@ -199,6 +202,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
199
202
|
const moveTranstion = useSharedValue(0)
|
|
200
203
|
// 记录从onBegin 到 onTouchesUp 的时间
|
|
201
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
|
|
202
209
|
const timerId = useRef(0 as number | ReturnType<typeof setTimeout>)
|
|
203
210
|
const intervalTimer = props.interval || 500
|
|
204
211
|
const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
|
|
@@ -496,7 +503,11 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
496
503
|
}, [children.length])
|
|
497
504
|
|
|
498
505
|
useEffect(() => {
|
|
499
|
-
|
|
506
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
|
|
507
|
+
// 2. 手指滑动过程中更新索引,外部会把current再穿进来,导致offset直接更新了
|
|
508
|
+
if (props.current !== currentIndex.value) {
|
|
509
|
+
updateCurrent(props.current || 0, step.value)
|
|
510
|
+
}
|
|
500
511
|
}, [props.current])
|
|
501
512
|
|
|
502
513
|
useEffect(() => {
|
|
@@ -559,18 +570,25 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
559
570
|
targetOffset: -moveToTargetPos
|
|
560
571
|
}
|
|
561
572
|
}
|
|
562
|
-
function
|
|
573
|
+
function checkUnCircular (eventData: EventDataType) {
|
|
563
574
|
'worklet'
|
|
564
575
|
const { translation } = eventData
|
|
565
576
|
const currentOffset = Math.abs(offset.value)
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
577
|
+
// 向右滑动swiper
|
|
578
|
+
if (translation < 0) {
|
|
579
|
+
const boundaryOffset = step.value * (childrenLength.value - 1)
|
|
580
|
+
const gestureMovePos = Math.abs(translation) + currentOffset
|
|
581
|
+
return {
|
|
582
|
+
// 防止快速连续向右滑动时,手势移动的距离 加 当前的offset超出边界
|
|
583
|
+
targetOffset: gestureMovePos > boundaryOffset ? -boundaryOffset : offset.value + translation,
|
|
584
|
+
canMove: currentOffset < boundaryOffset
|
|
571
585
|
}
|
|
572
586
|
} else {
|
|
573
|
-
|
|
587
|
+
const gestureMovePos = currentOffset - translation
|
|
588
|
+
return {
|
|
589
|
+
targetOffset: gestureMovePos < 0 ? 0 : offset.value + translation,
|
|
590
|
+
canMove: currentOffset > 0
|
|
591
|
+
}
|
|
574
592
|
}
|
|
575
593
|
}
|
|
576
594
|
function handleEnd (eventData: EventDataType) {
|
|
@@ -620,7 +638,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
620
638
|
}
|
|
621
639
|
})
|
|
622
640
|
}
|
|
623
|
-
function
|
|
641
|
+
function computeHalf () {
|
|
624
642
|
'worklet'
|
|
625
643
|
const currentOffset = Math.abs(offset.value)
|
|
626
644
|
let preOffset = (currentIndex.value + patchElmNumShared.value) * step.value
|
|
@@ -630,6 +648,14 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
630
648
|
// 正常事件中拿到的transition值(正向滑动<0,倒着滑>0)
|
|
631
649
|
const diffOffset = preOffset - currentOffset
|
|
632
650
|
const half = Math.abs(diffOffset) > step.value / 2
|
|
651
|
+
return {
|
|
652
|
+
diffOffset,
|
|
653
|
+
half
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
function handleLongPress () {
|
|
657
|
+
'worklet'
|
|
658
|
+
const { diffOffset, half } = computeHalf()
|
|
633
659
|
if (+diffOffset === 0) {
|
|
634
660
|
runOnJS(resumeLoop)()
|
|
635
661
|
} else if (half) {
|
|
@@ -685,18 +711,29 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
685
711
|
runOnJS(pauseLoop)()
|
|
686
712
|
preAbsolutePos.value = e[strAbso]
|
|
687
713
|
moveTranstion.value = e[strAbso]
|
|
714
|
+
anotherDirectionMove.value = e[anotherAbso]
|
|
688
715
|
moveTime.value = new Date().getTime()
|
|
689
716
|
})
|
|
690
|
-
.
|
|
717
|
+
.onUpdate((e) => {
|
|
691
718
|
'worklet'
|
|
692
719
|
if (touchfinish.value) return
|
|
693
|
-
const
|
|
694
|
-
const moveDistance = touchEventData[strAbso] - preAbsolutePos.value
|
|
720
|
+
const moveDistance = e[strAbso] - preAbsolutePos.value
|
|
695
721
|
const eventData = {
|
|
696
722
|
translation: moveDistance
|
|
697
723
|
}
|
|
698
|
-
//
|
|
699
|
-
|
|
724
|
+
// 1. 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
|
|
725
|
+
const { half } = computeHalf()
|
|
726
|
+
if (half) {
|
|
727
|
+
const { selectedIndex } = getTargetPosition(eventData)
|
|
728
|
+
currentIndex.value = selectedIndex
|
|
729
|
+
}
|
|
730
|
+
// 2. 处理用户一直拖拽到临界点的场景, 不会执行onEnd
|
|
731
|
+
const { canMove, targetOffset } = checkUnCircular(eventData)
|
|
732
|
+
if (!circularShared.value) {
|
|
733
|
+
if (canMove) {
|
|
734
|
+
offset.value = targetOffset
|
|
735
|
+
preAbsolutePos.value = e[strAbso]
|
|
736
|
+
}
|
|
700
737
|
return
|
|
701
738
|
}
|
|
702
739
|
const { isBoundary, resetOffset } = reachBoundary(eventData)
|
|
@@ -705,33 +742,29 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
705
742
|
} else {
|
|
706
743
|
offset.value = moveDistance + offset.value
|
|
707
744
|
}
|
|
708
|
-
preAbsolutePos.value =
|
|
745
|
+
preAbsolutePos.value = e[strAbso]
|
|
709
746
|
})
|
|
710
|
-
.
|
|
747
|
+
.onFinalize((e) => {
|
|
711
748
|
'worklet'
|
|
712
749
|
if (touchfinish.value) return
|
|
713
|
-
const
|
|
714
|
-
const moveDistance = touchEventData[strAbso] - moveTranstion.value
|
|
750
|
+
const moveDistance = e[strAbso] - moveTranstion.value
|
|
715
751
|
touchfinish.value = true
|
|
716
752
|
const eventData = {
|
|
717
753
|
translation: moveDistance
|
|
718
754
|
}
|
|
719
|
-
// 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
|
|
720
|
-
if (!circularShared.value && !canMove(eventData)) {
|
|
721
|
-
return
|
|
722
|
-
}
|
|
723
755
|
const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000
|
|
724
756
|
if (Math.abs(strVelocity) < longPressRatio) {
|
|
725
757
|
handleLongPress()
|
|
726
758
|
} else {
|
|
759
|
+
// 如果触发了onTouchesCancelled,不会触发onUpdate不会更新offset值, 索引不会变更
|
|
727
760
|
handleEnd(eventData)
|
|
728
761
|
}
|
|
729
762
|
}).withRef(swiperGestureRef)
|
|
730
763
|
// swiper横向,当y轴滑动5像素手势失效;swiper纵向只响应swiper的滑动事件
|
|
731
764
|
if (dir === 'x') {
|
|
732
|
-
gesturePan.activeOffsetX([-
|
|
765
|
+
gesturePan.activeOffsetX([-5, 5]).failOffsetY([-5, 5])
|
|
733
766
|
} else {
|
|
734
|
-
gesturePan.activeOffsetY([-
|
|
767
|
+
gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5])
|
|
735
768
|
}
|
|
736
769
|
// 手势协同2.0
|
|
737
770
|
if (simultaneousHandlers && simultaneousHandlers.length) {
|
|
@@ -775,7 +808,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
775
808
|
</View>)
|
|
776
809
|
}
|
|
777
810
|
|
|
778
|
-
if (children.length === 1) {
|
|
811
|
+
if (children.length === 1 || disableGesture) {
|
|
779
812
|
return renderSwiper()
|
|
780
813
|
} else {
|
|
781
814
|
return (<GestureDetector gesture={gestureHandler}>
|