@mpxjs/webpack-plugin 2.10.15-2 → 2.10.15-3
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.
|
@@ -120,6 +120,8 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
120
120
|
const strVelocity = 'velocity' + dir.toUpperCase();
|
|
121
121
|
// 标识手指触摸和抬起, 起点在onBegin
|
|
122
122
|
const touchfinish = useSharedValue(true);
|
|
123
|
+
// 记录onUpdate时的方向,用于进行onFinalize中的值修正
|
|
124
|
+
const preUpdateTransDir = useSharedValue(0);
|
|
123
125
|
// 记录上一帧的绝对定位坐标
|
|
124
126
|
const preAbsolutePos = useSharedValue(0);
|
|
125
127
|
// 记录从onBegin 到 onTouchesUp 时移动的距离
|
|
@@ -325,11 +327,9 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
325
327
|
resumeLoop
|
|
326
328
|
};
|
|
327
329
|
}, []);
|
|
328
|
-
function handleSwiperChange(current
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
bindchange && bindchange(eventData);
|
|
332
|
-
}
|
|
330
|
+
function handleSwiperChange(current) {
|
|
331
|
+
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
|
|
332
|
+
bindchange && bindchange(eventData);
|
|
333
333
|
}
|
|
334
334
|
const runOnJSCallbackRef = useRef({
|
|
335
335
|
loop,
|
|
@@ -379,7 +379,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
379
379
|
// 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
|
|
380
380
|
useAnimatedReaction(() => currentIndex.value, (newIndex, preIndex) => {
|
|
381
381
|
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
382
|
-
if (newIndex !== preIndex && bindchange) {
|
|
382
|
+
if (newIndex !== preIndex && preIndex !== null && preIndex !== undefined && bindchange) {
|
|
383
383
|
runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent);
|
|
384
384
|
}
|
|
385
385
|
});
|
|
@@ -411,9 +411,9 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
411
411
|
}
|
|
412
412
|
}, [children.length]);
|
|
413
413
|
useEffect(() => {
|
|
414
|
-
// 1. 如果用户在touch的过程中, 外部更新了current
|
|
414
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以内部为准(小程序表现)
|
|
415
415
|
// 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
|
|
416
|
-
if (propCurrent !== currentIndex.value) {
|
|
416
|
+
if (propCurrent !== currentIndex.value && touchfinish.value) {
|
|
417
417
|
updateCurrent(propCurrent, step.value);
|
|
418
418
|
}
|
|
419
419
|
}, [propCurrent]);
|
|
@@ -662,6 +662,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
662
662
|
translation: moveDistance,
|
|
663
663
|
transdir: moveDistance
|
|
664
664
|
};
|
|
665
|
+
preUpdateTransDir.value = moveDistance;
|
|
665
666
|
// 1. 支持滑动中超出一半更新索引的能力:只更新索引并不会影响onFinalize依据当前offset计算的索引
|
|
666
667
|
const { half } = computeHalf(eventData);
|
|
667
668
|
if (childrenLength.value > 1 && half) {
|
|
@@ -702,11 +703,17 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
702
703
|
if (touchfinish.value)
|
|
703
704
|
return;
|
|
704
705
|
touchfinish.value = true;
|
|
706
|
+
/**
|
|
707
|
+
* 安卓修正
|
|
708
|
+
* 问题:部分安卓机型onFinalize中拿到的absoluteX 有问题
|
|
709
|
+
* 案例:比如手指从右向左滑的时候,onUpdate拿到的是241.64346313476562, 而onFinalize中拿到的是241.81817626953125,理论上onFinalize中应该比onUpdate小才对吧
|
|
710
|
+
* 解决方式:修正
|
|
711
|
+
*/
|
|
705
712
|
// 触发过onUpdate正常情况下e[strAbso] - preAbsolutePos.value=0; 未触发过onUpdate的情况下e[strAbso] - preAbsolutePos.value 不为0
|
|
706
713
|
const moveDistance = e[strAbso] - preAbsolutePos.value;
|
|
707
714
|
const eventData = {
|
|
708
715
|
translation: moveDistance,
|
|
709
|
-
transdir: moveDistance
|
|
716
|
+
transdir: Math.abs(moveDistance) > 1 ? moveDistance : preUpdateTransDir.value
|
|
710
717
|
};
|
|
711
718
|
// 1. 只有一个元素:循环 和 非循环状态,都走回弹效果
|
|
712
719
|
if (childrenLength.value === 1) {
|
|
@@ -207,6 +207,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
207
207
|
const strVelocity = 'velocity' + dir.toUpperCase() as StrVelocityType
|
|
208
208
|
// 标识手指触摸和抬起, 起点在onBegin
|
|
209
209
|
const touchfinish = useSharedValue(true)
|
|
210
|
+
// 记录onUpdate时的方向,用于进行onFinalize中的值修正
|
|
211
|
+
const preUpdateTransDir = useSharedValue(0)
|
|
210
212
|
// 记录上一帧的绝对定位坐标
|
|
211
213
|
const preAbsolutePos = useSharedValue(0)
|
|
212
214
|
// 记录从onBegin 到 onTouchesUp 时移动的距离
|
|
@@ -429,11 +431,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
429
431
|
}
|
|
430
432
|
}, [])
|
|
431
433
|
|
|
432
|
-
function handleSwiperChange (current: number
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
bindchange && bindchange(eventData)
|
|
436
|
-
}
|
|
434
|
+
function handleSwiperChange (current: number) {
|
|
435
|
+
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
|
|
436
|
+
bindchange && bindchange(eventData)
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
const runOnJSCallbackRef = useRef({
|
|
@@ -482,7 +482,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
482
482
|
// 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
|
|
483
483
|
useAnimatedReaction(() => currentIndex.value, (newIndex: number, preIndex: number) => {
|
|
484
484
|
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
485
|
-
if (newIndex !== preIndex && bindchange) {
|
|
485
|
+
if (newIndex !== preIndex && preIndex !== null && preIndex !== undefined && bindchange) {
|
|
486
486
|
runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent)
|
|
487
487
|
}
|
|
488
488
|
})
|
|
@@ -517,9 +517,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
517
517
|
}, [children.length])
|
|
518
518
|
|
|
519
519
|
useEffect(() => {
|
|
520
|
-
// 1. 如果用户在touch的过程中, 外部更新了current
|
|
520
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以内部为准(小程序表现)
|
|
521
521
|
// 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
|
|
522
|
-
if (propCurrent !== currentIndex.value) {
|
|
522
|
+
if (propCurrent !== currentIndex.value && touchfinish.value) {
|
|
523
523
|
updateCurrent(propCurrent, step.value)
|
|
524
524
|
}
|
|
525
525
|
}, [propCurrent])
|
|
@@ -757,6 +757,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
757
757
|
translation: moveDistance,
|
|
758
758
|
transdir: moveDistance
|
|
759
759
|
}
|
|
760
|
+
preUpdateTransDir.value = moveDistance
|
|
760
761
|
// 1. 支持滑动中超出一半更新索引的能力:只更新索引并不会影响onFinalize依据当前offset计算的索引
|
|
761
762
|
const { half } = computeHalf(eventData)
|
|
762
763
|
if (childrenLength.value > 1 && half) {
|
|
@@ -794,11 +795,17 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
794
795
|
'worklet'
|
|
795
796
|
if (touchfinish.value) return
|
|
796
797
|
touchfinish.value = true
|
|
798
|
+
/**
|
|
799
|
+
* 安卓修正
|
|
800
|
+
* 问题:部分安卓机型onFinalize中拿到的absoluteX 有问题
|
|
801
|
+
* 案例:比如手指从右向左滑的时候,onUpdate拿到的是241.64346313476562, 而onFinalize中拿到的是241.81817626953125,理论上onFinalize中应该比onUpdate小才对吧
|
|
802
|
+
* 解决方式:修正
|
|
803
|
+
*/
|
|
797
804
|
// 触发过onUpdate正常情况下e[strAbso] - preAbsolutePos.value=0; 未触发过onUpdate的情况下e[strAbso] - preAbsolutePos.value 不为0
|
|
798
805
|
const moveDistance = e[strAbso] - preAbsolutePos.value
|
|
799
806
|
const eventData = {
|
|
800
807
|
translation: moveDistance,
|
|
801
|
-
transdir: moveDistance
|
|
808
|
+
transdir: Math.abs(moveDistance) > 1 ? moveDistance : preUpdateTransDir.value
|
|
802
809
|
}
|
|
803
810
|
// 1. 只有一个元素:循环 和 非循环状态,都走回弹效果
|
|
804
811
|
if (childrenLength.value === 1) {
|