From 376f691ee170612d5ea5ae45fc8b1b9582436bc3 Mon Sep 17 00:00:00 2001 From: mikasayw Date: Mon, 24 Feb 2025 19:13:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(tabs):=20=E4=BF=AE=E5=A4=8Dtabs=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E8=BF=87=E5=A4=9A=E6=97=B6=E7=9A=84=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E6=93=8D=E4=BD=9Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/tabs/tabs.taro.tsx | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/packages/tabs/tabs.taro.tsx b/src/packages/tabs/tabs.taro.tsx index e21dbff8de..48d5768bc8 100644 --- a/src/packages/tabs/tabs.taro.tsx +++ b/src/packages/tabs/tabs.taro.tsx @@ -160,15 +160,9 @@ export const Tabs: FunctionComponent> & { to: number, direction: 'horizontal' | 'vertical' ) => { - let count = 0 - const frames = 1 - - function animate() { - if (direction === 'horizontal') setScrollLeft(to) - else setScrollTop(to) - if (++count < frames) raf(animate) - } - animate() + // 使用ScrollView组件此处不需要手动raf scrollLeft + if (direction === 'horizontal') setScrollLeft(to) + else setScrollTop(to) } const scrollIntoView = (index: number) => { raf(() => { @@ -190,14 +184,12 @@ export const Tabs: FunctionComponent> & { .slice(0, index) .reduce((prev: number, curr: RectItem) => prev + curr.width, 0) to = left - (navRect.width - titleRect.width) / 2 - // to < 0 说明不需要进行滚动,页面元素已全部显示出来 - if (to < 0) return - to = rtl ? -to : to } + scrollDirection(to, direction) + nextTick(() => { scrollWithAnimation.current = true }) - scrollDirection(to, direction) }) }) }