diff --git a/src/packages/tabs/tabs.taro.tsx b/src/packages/tabs/tabs.taro.tsx index 1c2ebb80c0..ba82bf18cc 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) }) }) } @@ -239,6 +231,7 @@ export const Tabs: FunctionComponent> & { scrollY={direction === 'vertical'} scrollLeft={scrollLeft} scrollTop={scrollTop} + enhanced showScrollbar={false} scrollWithAnimation={ rtl && Taro.getEnv() !== 'WEB' ? false : scrollWithAnimation.current @@ -306,7 +299,7 @@ export const Tabs: FunctionComponent> & { autoHeightClassName: autoHeight && String(value) !== String(child.props.value || idx) ? 'inactive' - : '', + : undefined, }) })}