Skip to content

Commit e87d7ab

Browse files
committed
lock tab controller scroll if content is not longer than screen width
1 parent 2f43158 commit e87d7ab

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/incubator/TabController/TabBar.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class TabBar extends PureComponent {
9898
};
9999

100100
this.state = {
101+
scrollEnabled: false,
101102
itemsWidths: undefined,
102103
};
103104

@@ -119,6 +120,12 @@ class TabBar extends PureComponent {
119120
}
120121
};
121122

123+
onContentSizeChange = width => {
124+
if (width > Constants.screenWidth) {
125+
this.setState({scrollEnabled: true});
126+
}
127+
};
128+
122129
runTiming(targetValue, prevValue, duration) {
123130
const clock = new Clock();
124131
const state = {
@@ -149,19 +156,10 @@ class TabBar extends PureComponent {
149156
}
150157

151158
renderSelectedIndicator() {
152-
// return null;
153159
const {itemsWidths} = this.state;
154160
const {indicatorStyle} = this.props;
155161
if (itemsWidths) {
156-
// const transitionStyle = {
157-
// width: this.runTiming(this._indicatorWidth, this._prevIndicatorWidth, 300),
158-
// left: this.runTiming(this._offset, this._prevOffset, 400),
159-
// };
160-
return (
161-
<Reanimated.View
162-
style={[styles.selectedIndicator, indicatorStyle /* , transitionStyle */, this._indicatorTransitionStyle]}
163-
/>
164-
);
162+
return <Reanimated.View style={[styles.selectedIndicator, indicatorStyle, this._indicatorTransitionStyle]} />;
165163
}
166164
}
167165

@@ -177,7 +175,6 @@ class TabBar extends PureComponent {
177175
activeBackgroundColor,
178176
} = this.props;
179177
if (!_.isEmpty(itemStates)) {
180-
181178
if (this.tabBarItems) {
182179
return this.tabBarItems;
183180
}
@@ -205,7 +202,7 @@ class TabBar extends PureComponent {
205202
render() {
206203
const {currentPage} = this.context;
207204
const {containerWidth, height, enableShadow} = this.props;
208-
const {itemsWidths, itemsOffsets} = this.state;
205+
const {itemsWidths, itemsOffsets, scrollEnabled} = this.state;
209206
return (
210207
<View style={enableShadow && styles.containerShadow}>
211208
<ScrollView
@@ -214,6 +211,8 @@ class TabBar extends PureComponent {
214211
showsHorizontalScrollIndicator={false}
215212
style={styles.tabBarScroll}
216213
contentContainerStyle={styles.tabBarScrollContent}
214+
scrollEnabled={scrollEnabled}
215+
onContentSizeChange={this.onContentSizeChange}
217216
>
218217
<View style={[styles.tabBar, height && {height}]}>{this.renderTabBarItems()}</View>
219218
{this.renderSelectedIndicator()}

0 commit comments

Comments
 (0)