@mpxjs/webpack-plugin 2.10.4-beta.13 → 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.
@@ -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,6 +407,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
403
407
  }
404
408
  }, [children.length]);
405
409
  useEffect(() => {
410
+ // 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
406
411
  updateCurrent(props.current || 0, step.value);
407
412
  }, [props.current]);
408
413
  useEffect(() => {
@@ -466,20 +471,26 @@ const SwiperWrapper = forwardRef((props, ref) => {
466
471
  targetOffset: -moveToTargetPos
467
472
  };
468
473
  }
469
- function canMove(eventData) {
474
+ function checkUnCircular(eventData) {
470
475
  'worklet';
471
476
  const { translation } = eventData;
472
477
  const currentOffset = Math.abs(offset.value);
473
- if (!circularShared.value) {
474
- if (translation < 0) {
475
- return currentOffset < step.value * (childrenLength.value - 1);
476
- }
477
- else {
478
- return currentOffset > 0;
479
- }
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
+ };
480
487
  }
481
488
  else {
482
- return true;
489
+ const gestureMovePos = currentOffset - translation;
490
+ return {
491
+ targetOffset: gestureMovePos < 0 ? 0 : offset.value + translation,
492
+ canMove: currentOffset > 0
493
+ };
483
494
  }
484
495
  }
485
496
  function handleEnd(eventData) {
@@ -530,7 +541,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
530
541
  }
531
542
  });
532
543
  }
533
- function handleLongPress() {
544
+ function computeHalf() {
534
545
  'worklet';
535
546
  const currentOffset = Math.abs(offset.value);
536
547
  let preOffset = (currentIndex.value + patchElmNumShared.value) * step.value;
@@ -540,6 +551,14 @@ const SwiperWrapper = forwardRef((props, ref) => {
540
551
  // 正常事件中拿到的transition值(正向滑动<0,倒着滑>0)
541
552
  const diffOffset = preOffset - currentOffset;
542
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();
543
562
  if (+diffOffset === 0) {
544
563
  runOnJS(resumeLoop)();
545
564
  }
@@ -599,21 +618,32 @@ const SwiperWrapper = forwardRef((props, ref) => {
599
618
  runOnJS(pauseLoop)();
600
619
  preAbsolutePos.value = e[strAbso];
601
620
  moveTranstion.value = e[strAbso];
621
+ anotherDirectionMove.value = e[anotherAbso];
602
622
  moveTime.value = new Date().getTime();
603
623
  })
604
- .onTouchesMove((e) => {
624
+ .onUpdate((e) => {
605
625
  'worklet';
606
626
  if (touchfinish.value)
607
627
  return;
608
- const touchEventData = e.changedTouches[0];
609
- const moveDistance = touchEventData[strAbso] - preAbsolutePos.value;
628
+ const moveDistance = e[strAbso] - preAbsolutePos.value;
610
629
  const eventData = {
611
630
  translation: moveDistance
612
631
  };
613
632
  // 处理用户一直拖拽到临界点的场景, 不会执行onEnd
614
- if (!circularShared.value && !canMove(eventData)) {
633
+ const { canMove, targetOffset } = checkUnCircular(eventData);
634
+ if (!circularShared.value) {
635
+ if (canMove) {
636
+ offset.value = targetOffset;
637
+ preAbsolutePos.value = e[strAbso];
638
+ }
615
639
  return;
616
640
  }
641
+ const { half } = computeHalf();
642
+ // 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
643
+ if (half) {
644
+ const { selectedIndex } = getTargetPosition(eventData);
645
+ currentIndex.value = selectedIndex;
646
+ }
617
647
  const { isBoundary, resetOffset } = reachBoundary(eventData);
618
648
  if (isBoundary && circularShared.value) {
619
649
  offset.value = resetOffset;
@@ -621,20 +651,20 @@ const SwiperWrapper = forwardRef((props, ref) => {
621
651
  else {
622
652
  offset.value = moveDistance + offset.value;
623
653
  }
624
- preAbsolutePos.value = touchEventData[strAbso];
654
+ preAbsolutePos.value = e[strAbso];
625
655
  })
626
- .onTouchesUp((e) => {
656
+ .onFinalize((e) => {
627
657
  'worklet';
628
658
  if (touchfinish.value)
629
659
  return;
630
- const touchEventData = e.changedTouches[0];
631
- const moveDistance = touchEventData[strAbso] - moveTranstion.value;
660
+ const moveDistance = e[strAbso] - moveTranstion.value;
632
661
  touchfinish.value = true;
633
662
  const eventData = {
634
663
  translation: moveDistance
635
664
  };
636
665
  // 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
637
- if (!circularShared.value && !canMove(eventData)) {
666
+ const { canMove } = checkUnCircular(eventData);
667
+ if (!circularShared.value && !canMove) {
638
668
  return;
639
669
  }
640
670
  const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000;
@@ -647,10 +677,10 @@ const SwiperWrapper = forwardRef((props, ref) => {
647
677
  }).withRef(swiperGestureRef);
648
678
  // swiper横向,当y轴滑动5像素手势失效;swiper纵向只响应swiper的滑动事件
649
679
  if (dir === 'x') {
650
- gesturePan.activeOffsetX([-1, 1]).failOffsetY([-5, 5]);
680
+ gesturePan.activeOffsetX([-5, 5]).failOffsetY([-5, 5]);
651
681
  }
652
682
  else {
653
- gesturePan.activeOffsetY([-1, 1]).failOffsetX([-5, 5]);
683
+ gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5]);
654
684
  }
655
685
  // 手势协同2.0
656
686
  if (simultaneousHandlers && simultaneousHandlers.length) {
@@ -691,7 +721,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
691
721
  {showsPagination && renderPagination()}
692
722
  </View>);
693
723
  }
694
- if (children.length === 1) {
724
+ if (children.length === 1 || disableGesture) {
695
725
  return renderSwiper();
696
726
  }
697
727
  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,6 +503,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
496
503
  }, [children.length])
497
504
 
498
505
  useEffect(() => {
506
+ // 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
499
507
  updateCurrent(props.current || 0, step.value)
500
508
  }, [props.current])
501
509
 
@@ -559,18 +567,25 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
559
567
  targetOffset: -moveToTargetPos
560
568
  }
561
569
  }
562
- function canMove (eventData: EventDataType) {
570
+ function checkUnCircular (eventData: EventDataType) {
563
571
  'worklet'
564
572
  const { translation } = eventData
565
573
  const currentOffset = Math.abs(offset.value)
566
- if (!circularShared.value) {
567
- if (translation < 0) {
568
- return currentOffset < step.value * (childrenLength.value - 1)
569
- } else {
570
- return currentOffset > 0
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
571
582
  }
572
583
  } else {
573
- return true
584
+ const gestureMovePos = currentOffset - translation
585
+ return {
586
+ targetOffset: gestureMovePos < 0 ? 0 : offset.value + translation,
587
+ canMove: currentOffset > 0
588
+ }
574
589
  }
575
590
  }
576
591
  function handleEnd (eventData: EventDataType) {
@@ -620,7 +635,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
620
635
  }
621
636
  })
622
637
  }
623
- function handleLongPress () {
638
+ function computeHalf () {
624
639
  'worklet'
625
640
  const currentOffset = Math.abs(offset.value)
626
641
  let preOffset = (currentIndex.value + patchElmNumShared.value) * step.value
@@ -630,6 +645,14 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
630
645
  // 正常事件中拿到的transition值(正向滑动<0,倒着滑>0)
631
646
  const diffOffset = preOffset - currentOffset
632
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()
633
656
  if (+diffOffset === 0) {
634
657
  runOnJS(resumeLoop)()
635
658
  } else if (half) {
@@ -685,39 +708,50 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
685
708
  runOnJS(pauseLoop)()
686
709
  preAbsolutePos.value = e[strAbso]
687
710
  moveTranstion.value = e[strAbso]
711
+ anotherDirectionMove.value = e[anotherAbso]
688
712
  moveTime.value = new Date().getTime()
689
713
  })
690
- .onTouchesMove((e) => {
714
+ .onUpdate((e) => {
691
715
  'worklet'
692
716
  if (touchfinish.value) return
693
- const touchEventData = e.changedTouches[0]
694
- const moveDistance = touchEventData[strAbso] - preAbsolutePos.value
717
+ const moveDistance = e[strAbso] - preAbsolutePos.value
695
718
  const eventData = {
696
719
  translation: moveDistance
697
720
  }
698
721
  // 处理用户一直拖拽到临界点的场景, 不会执行onEnd
699
- if (!circularShared.value && !canMove(eventData)) {
722
+ const { canMove, targetOffset } = checkUnCircular(eventData)
723
+ if (!circularShared.value) {
724
+ if (canMove) {
725
+ offset.value = targetOffset
726
+ preAbsolutePos.value = e[strAbso]
727
+ }
700
728
  return
701
729
  }
730
+ const { half } = computeHalf()
731
+ // 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
732
+ if (half) {
733
+ const { selectedIndex } = getTargetPosition(eventData)
734
+ currentIndex.value = selectedIndex
735
+ }
702
736
  const { isBoundary, resetOffset } = reachBoundary(eventData)
703
737
  if (isBoundary && circularShared.value) {
704
738
  offset.value = resetOffset
705
739
  } else {
706
740
  offset.value = moveDistance + offset.value
707
741
  }
708
- preAbsolutePos.value = touchEventData[strAbso]
742
+ preAbsolutePos.value = e[strAbso]
709
743
  })
710
- .onTouchesUp((e) => {
744
+ .onFinalize((e) => {
711
745
  'worklet'
712
746
  if (touchfinish.value) return
713
- const touchEventData = e.changedTouches[0]
714
- const moveDistance = touchEventData[strAbso] - moveTranstion.value
747
+ const moveDistance = e[strAbso] - moveTranstion.value
715
748
  touchfinish.value = true
716
749
  const eventData = {
717
750
  translation: moveDistance
718
751
  }
719
752
  // 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
720
- if (!circularShared.value && !canMove(eventData)) {
753
+ const { canMove } = checkUnCircular(eventData)
754
+ if (!circularShared.value && !canMove) {
721
755
  return
722
756
  }
723
757
  const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000
@@ -729,9 +763,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
729
763
  }).withRef(swiperGestureRef)
730
764
  // swiper横向,当y轴滑动5像素手势失效;swiper纵向只响应swiper的滑动事件
731
765
  if (dir === 'x') {
732
- gesturePan.activeOffsetX([-1, 1]).failOffsetY([-5, 5])
766
+ gesturePan.activeOffsetX([-5, 5]).failOffsetY([-5, 5])
733
767
  } else {
734
- gesturePan.activeOffsetY([-1, 1]).failOffsetX([-5, 5])
768
+ gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5])
735
769
  }
736
770
  // 手势协同2.0
737
771
  if (simultaneousHandlers && simultaneousHandlers.length) {
@@ -775,7 +809,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
775
809
  </View>)
776
810
  }
777
811
 
778
- if (children.length === 1) {
812
+ if (children.length === 1 || disableGesture) {
779
813
  return renderSwiper()
780
814
  } else {
781
815
  return (<GestureDetector gesture={gestureHandler}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.4-beta.13",
3
+ "version": "2.10.4-beta.14",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"