@mpxjs/webpack-plugin 2.10.4-beta.14 → 2.10.4-beta.16

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.
@@ -2,7 +2,7 @@ import Animated, { useAnimatedStyle, interpolate } from 'react-native-reanimated
2
2
  import { forwardRef, useRef, useContext } from 'react';
3
3
  import useInnerProps from './getInnerListeners';
4
4
  import useNodesRef from './useNodesRef'; // 引入辅助函数
5
- import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout, extendObject } from './utils';
5
+ import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout, extendObject, isHarmony } from './utils';
6
6
  import { SwiperContext } from './context';
7
7
  const _SwiperItem = forwardRef((props, ref) => {
8
8
  const { 'enable-var': enableVar, 'external-var-context': externalVarContext, style, customStyle, itemIndex } = props;
@@ -29,7 +29,7 @@ const _SwiperItem = forwardRef((props, ref) => {
29
29
  'style'
30
30
  ], { layoutRef });
31
31
  const itemAnimatedStyle = useAnimatedStyle(() => {
32
- if (!step.value)
32
+ if (!step.value && !isHarmony)
33
33
  return {};
34
34
  const inputRange = [step.value, 0];
35
35
  const outputRange = [0.7, 1];
@@ -408,7 +408,10 @@ const SwiperWrapper = forwardRef((props, ref) => {
408
408
  }, [children.length]);
409
409
  useEffect(() => {
410
410
  // 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
411
- updateCurrent(props.current || 0, step.value);
411
+ // 2. 手指滑动过程中更新索引,外部会把current再穿进来,导致offset直接更新了
412
+ if (props.current !== currentIndex.value) {
413
+ updateCurrent(props.current || 0, step.value);
414
+ }
412
415
  }, [props.current]);
413
416
  useEffect(() => {
414
417
  autoplayShared.value = autoplay;
@@ -629,7 +632,13 @@ const SwiperWrapper = forwardRef((props, ref) => {
629
632
  const eventData = {
630
633
  translation: moveDistance
631
634
  };
632
- // 处理用户一直拖拽到临界点的场景, 不会执行onEnd
635
+ // 1. 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
636
+ const { half } = computeHalf();
637
+ if (half) {
638
+ const { selectedIndex } = getTargetPosition(eventData);
639
+ currentIndex.value = selectedIndex;
640
+ }
641
+ // 2. 处理用户一直拖拽到临界点的场景, 不会执行onEnd
633
642
  const { canMove, targetOffset } = checkUnCircular(eventData);
634
643
  if (!circularShared.value) {
635
644
  if (canMove) {
@@ -638,12 +647,6 @@ const SwiperWrapper = forwardRef((props, ref) => {
638
647
  }
639
648
  return;
640
649
  }
641
- const { half } = computeHalf();
642
- // 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
643
- if (half) {
644
- const { selectedIndex } = getTargetPosition(eventData);
645
- currentIndex.value = selectedIndex;
646
- }
647
650
  const { isBoundary, resetOffset } = reachBoundary(eventData);
648
651
  if (isBoundary && circularShared.value) {
649
652
  offset.value = resetOffset;
@@ -662,16 +665,12 @@ const SwiperWrapper = forwardRef((props, ref) => {
662
665
  const eventData = {
663
666
  translation: moveDistance
664
667
  };
665
- // 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
666
- const { canMove } = checkUnCircular(eventData);
667
- if (!circularShared.value && !canMove) {
668
- return;
669
- }
670
668
  const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000;
671
669
  if (Math.abs(strVelocity) < longPressRatio) {
672
670
  handleLongPress();
673
671
  }
674
672
  else {
673
+ // 如果触发了onTouchesCancelled,不会触发onUpdate不会更新offset值, 索引不会变更
675
674
  handleEnd(eventData);
676
675
  }
677
676
  }).withRef(swiperGestureRef);
@@ -3,7 +3,7 @@ import Animated, { useAnimatedStyle, interpolate, SharedValue } from 'react-nati
3
3
  import { ReactNode, forwardRef, useRef, useContext } from 'react'
4
4
  import useInnerProps from './getInnerListeners'
5
5
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
6
- import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout, extendObject } from './utils'
6
+ import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout, extendObject, isHarmony } from './utils'
7
7
  import { SwiperContext } from './context'
8
8
 
9
9
  interface SwiperItemProps {
@@ -80,7 +80,7 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
80
80
  ],
81
81
  { layoutRef })
82
82
  const itemAnimatedStyle = useAnimatedStyle(() => {
83
- if (!step.value) return {}
83
+ if (!step.value && !isHarmony) return {}
84
84
  const inputRange = [step.value, 0]
85
85
  const outputRange = [0.7, 1]
86
86
  // 实现元素的宽度跟随step从0到真实宽度,且不能触发重新渲染整个组件,通过AnimatedStyle的方式实现
@@ -504,7 +504,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
504
504
 
505
505
  useEffect(() => {
506
506
  // 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
507
- updateCurrent(props.current || 0, step.value)
507
+ // 2. 手指滑动过程中更新索引,外部会把current再穿进来,导致offset直接更新了
508
+ if (props.current !== currentIndex.value) {
509
+ updateCurrent(props.current || 0, step.value)
510
+ }
508
511
  }, [props.current])
509
512
 
510
513
  useEffect(() => {
@@ -718,7 +721,13 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
718
721
  const eventData = {
719
722
  translation: moveDistance
720
723
  }
721
- // 处理用户一直拖拽到临界点的场景, 不会执行onEnd
724
+ // 1. 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
725
+ const { half } = computeHalf()
726
+ if (half) {
727
+ const { selectedIndex } = getTargetPosition(eventData)
728
+ currentIndex.value = selectedIndex
729
+ }
730
+ // 2. 处理用户一直拖拽到临界点的场景, 不会执行onEnd
722
731
  const { canMove, targetOffset } = checkUnCircular(eventData)
723
732
  if (!circularShared.value) {
724
733
  if (canMove) {
@@ -727,12 +736,6 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
727
736
  }
728
737
  return
729
738
  }
730
- const { half } = computeHalf()
731
- // 在Move过程中,如果手指一直没抬起来,超过一半的话也会更新索引
732
- if (half) {
733
- const { selectedIndex } = getTargetPosition(eventData)
734
- currentIndex.value = selectedIndex
735
- }
736
739
  const { isBoundary, resetOffset } = reachBoundary(eventData)
737
740
  if (isBoundary && circularShared.value) {
738
741
  offset.value = resetOffset
@@ -749,15 +752,11 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
749
752
  const eventData = {
750
753
  translation: moveDistance
751
754
  }
752
- // 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
753
- const { canMove } = checkUnCircular(eventData)
754
- if (!circularShared.value && !canMove) {
755
- return
756
- }
757
755
  const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000
758
756
  if (Math.abs(strVelocity) < longPressRatio) {
759
757
  handleLongPress()
760
758
  } else {
759
+ // 如果触发了onTouchesCancelled,不会触发onUpdate不会更新offset值, 索引不会变更
761
760
  handleEnd(eventData)
762
761
  }
763
762
  }).withRef(swiperGestureRef)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.4-beta.14",
3
+ "version": "2.10.4-beta.16",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"