Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/packages/tabs/tabs.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,9 @@ export const Tabs: FunctionComponent<Partial<TabsProps>> & {
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(() => {
Expand All @@ -190,14 +184,12 @@ export const Tabs: FunctionComponent<Partial<TabsProps>> & {
.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)
})
})
}
Expand Down Expand Up @@ -239,6 +231,7 @@ export const Tabs: FunctionComponent<Partial<TabsProps>> & {
scrollY={direction === 'vertical'}
scrollLeft={scrollLeft}
scrollTop={scrollTop}
enhanced
showScrollbar={false}
scrollWithAnimation={
rtl && Taro.getEnv() !== 'WEB' ? false : scrollWithAnimation.current
Expand Down Expand Up @@ -306,7 +299,7 @@ export const Tabs: FunctionComponent<Partial<TabsProps>> & {
autoHeightClassName:
autoHeight && String(value) !== String(child.props.value || idx)
? 'inactive'
: '',
: undefined,
})
})}
</View>
Expand Down