From 13bebb4a5411dd4744a2dd68d6e2afd170a41b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E5=9D=A4?= Date: Tue, 19 Sep 2023 18:51:35 +0800 Subject: [PATCH] fix: Tabs swipeable work(#1305) --- components/tabs/DefaultTabBar.tsx | 21 +++++++++++++-------- components/tabs/Tabs.tsx | 13 +++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/components/tabs/DefaultTabBar.tsx b/components/tabs/DefaultTabBar.tsx index 81a9c970..1fb4fee3 100644 --- a/components/tabs/DefaultTabBar.tsx +++ b/components/tabs/DefaultTabBar.tsx @@ -137,14 +137,19 @@ export class DefaultTabBar extends React.PureComponent { return } this._newLineLeft = newLineLeft - Animated.timing(this.state._leftTabUnderline, { - toValue: newLineLeft, - useNativeDriver: false, - }).start() - Animated.timing(this.state._widthTabUnderline, { - toValue: newLineRight - newLineLeft, - useNativeDriver: false, - }).start() + if (this.props.animated) { + Animated.timing(this.state._leftTabUnderline, { + toValue: newLineLeft, + useNativeDriver: false, + }).start() + Animated.timing(this.state._widthTabUnderline, { + toValue: newLineRight - newLineLeft, + useNativeDriver: false, + }).start() + } else { + this.state._leftTabUnderline.setValue(newLineLeft) + this.state._widthTabUnderline.setValue(newLineRight - newLineLeft) + } } } diff --git a/components/tabs/Tabs.tsx b/components/tabs/Tabs.tsx index 62d68c75..fa8b4d9b 100644 --- a/components/tabs/Tabs.tsx +++ b/components/tabs/Tabs.tsx @@ -65,7 +65,7 @@ export class Tabs extends React.PureComponent { } renderContent = (getSubElements = this.getSubElements()) => { - const { tabs, usePaged, destroyInactiveTab } = this.props + const { tabs, destroyInactiveTab } = this.props const { containerHeight = 0, containerWidth = 0, currentTab } = this.state const content = tabs.map((tab, index) => { const key = tab.key || `tab_${index}` @@ -103,7 +103,7 @@ export class Tabs extends React.PureComponent { this.state.scrollX.setValue(index * this.state.containerWidth) }) }} - scrollEnabled={this.props.swipeable || usePaged} + scrollEnabled={this.props.swipeable} style={{ height: containerHeight, width: containerWidth, @@ -219,12 +219,13 @@ export class Tabs extends React.PureComponent { direction === 'vertical' shouldRenderTab = (idx: number) => { - const { prerenderingSiblingsNumber = 0 } = this.props + const { prerenderingSiblingsNumber = 0, usePaged } = this.props const { currentTab = 0 } = this.state return ( - currentTab - prerenderingSiblingsNumber <= idx && - idx <= currentTab + prerenderingSiblingsNumber + !usePaged || + (currentTab - prerenderingSiblingsNumber <= idx && + idx <= currentTab + prerenderingSiblingsNumber) ) } @@ -258,7 +259,7 @@ export class Tabs extends React.PureComponent { goToTab(index: number) { if (this.carousel) { - this.carousel.goTo(index) + this.carousel.goTo(index, this.props.animated) } this.setState({ currentTab: index }, () => { this.state.scrollX.setValue(index * this.state.containerWidth)