From 3e3ce64bcf2e2715df83aac708e9619c2e6bb36c Mon Sep 17 00:00:00 2001 From: xuegan Date: Mon, 14 Sep 2026 17:18:09 +0800 Subject: [PATCH] fix(rn): reset swiper offset when items shrink --- .../lib/runtime/components/react/mpx-swiper.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-swiper.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-swiper.tsx index 8067e798b1..2dd33ec7c2 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-swiper.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-swiper.tsx @@ -584,8 +584,9 @@ const SwiperWrapper = forwardRef, SwiperProps>((pr childrenLength.value = children.length if (children.length <= 1 || maxIndex < currentIndex.value) { pauseLoop() - currentIndex.value = circular ? 0 : maxIndex - offset.value = getOffset(currentIndex.value, step.value) + const nextIndex = circular ? 0 : maxIndex + currentIndex.value = nextIndex + offset.value = getOffset(nextIndex, step.value) if (autoplay && children.length > 1) { loop() } @@ -613,7 +614,9 @@ const SwiperWrapper = forwardRef, SwiperProps>((pr if (circular !== circularShared.value || patchElmNum !== patchElmNumShared.value) { circularShared.value = circular patchElmNumShared.value = patchElmNum - offset.value = getOffset(currentIndex.value, step.value) + if (children.length > 1 && currentIndex.value <= maxIndex) { + offset.value = getOffset(currentIndex.value, step.value) + } } }, [circular, patchElmNum]) const { gestureHandler } = useMemo(() => {