Skip to content

Commit 5d8aeb1

Browse files
committed
use ScrollView instead of ViewPager
1 parent e42ae5d commit 5d8aeb1

File tree

1 file changed

+26
-58
lines changed

1 file changed

+26
-58
lines changed

index.js

+26-58
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const {
99
View,
1010
Animated,
1111
ScrollView,
12-
Platform,
1312
StyleSheet,
14-
ViewPagerAndroid,
1513
InteractionManager,
1614
} = ReactNative;
1715
const TimerMixin = require('react-timer-mixin');
@@ -76,19 +74,9 @@ const ScrollableTabView = React.createClass({
7674
},
7775

7876
goToPage(pageNumber) {
79-
if (Platform.OS === 'ios') {
80-
const offset = pageNumber * this.state.containerWidth;
81-
if (this.scrollView) {
82-
this.scrollView.scrollTo({x: offset, y: 0, animated: !this.props.scrollWithoutAnimation, });
83-
}
84-
} else {
85-
if (this.scrollView) {
86-
if (this.props.scrollWithoutAnimation) {
87-
this.scrollView.setPageWithoutAnimation(pageNumber);
88-
} else {
89-
this.scrollView.setPage(pageNumber);
90-
}
91-
}
77+
const offset = pageNumber * this.state.containerWidth;
78+
if (this.scrollView) {
79+
this.scrollView.scrollTo({x: offset, y: 0, animated: !this.props.scrollWithoutAnimation, });
9280
}
9381

9482
const currentPage = this.state.currentPage;
@@ -140,50 +128,30 @@ const ScrollableTabView = React.createClass({
140128
},
141129

142130
renderScrollableContent() {
143-
if (Platform.OS === 'ios') {
144-
const scenes = this._composeScenes();
145-
return <ScrollView
146-
horizontal
147-
pagingEnabled
148-
automaticallyAdjustContentInsets={false}
149-
contentOffset={{ x: this.props.initialPage * this.state.containerWidth, }}
150-
ref={(scrollView) => { this.scrollView = scrollView; }}
151-
onScroll={(e) => {
152-
const offsetX = e.nativeEvent.contentOffset.x;
153-
this._updateScrollValue(offsetX / this.state.containerWidth);
154-
}}
155-
onMomentumScrollBegin={this._onMomentumScrollBeginAndEnd}
156-
onMomentumScrollEnd={this._onMomentumScrollBeginAndEnd}
157-
scrollEventThrottle={16}
158-
scrollsToTop={false}
159-
showsHorizontalScrollIndicator={false}
160-
scrollEnabled={!this.props.locked}
161-
directionalLockEnabled
162-
alwaysBounceVertical={false}
163-
keyboardDismissMode="on-drag"
164-
{...this.props.contentProps}
131+
const scenes = this._composeScenes();
132+
return <ScrollView
133+
horizontal
134+
pagingEnabled
135+
automaticallyAdjustContentInsets={false}
136+
contentOffset={{ x: this.props.initialPage * this.state.containerWidth, }}
137+
ref={(scrollView) => { this.scrollView = scrollView; }}
138+
onScroll={(e) => {
139+
const offsetX = e.nativeEvent.contentOffset.x;
140+
this._updateScrollValue(offsetX / this.state.containerWidth);
141+
}}
142+
onMomentumScrollBegin={this._onMomentumScrollBeginAndEnd}
143+
onMomentumScrollEnd={this._onMomentumScrollBeginAndEnd}
144+
scrollEventThrottle={16}
145+
scrollsToTop={false}
146+
showsHorizontalScrollIndicator={false}
147+
scrollEnabled={!this.props.locked}
148+
directionalLockEnabled
149+
alwaysBounceVertical={false}
150+
keyboardDismissMode="on-drag"
151+
{...this.props.contentProps}
165152
>
166-
{scenes}
167-
</ScrollView>;
168-
} else {
169-
const scenes = this._composeScenes();
170-
return <ViewPagerAndroid
171-
key={this._children().length}
172-
style={styles.scrollableContentAndroid}
173-
initialPage={this.props.initialPage}
174-
onPageSelected={this._updateSelectedPage}
175-
keyboardDismissMode="on-drag"
176-
scrollEnabled={!this.props.locked}
177-
onPageScroll={(e) => {
178-
const { offset, position, } = e.nativeEvent;
179-
this._updateScrollValue(position + offset);
180-
}}
181-
ref={(scrollView) => { this.scrollView = scrollView; }}
182-
{...this.props.contentProps}
183-
>
184-
{scenes}
185-
</ViewPagerAndroid>;
186-
}
153+
{scenes}
154+
</ScrollView>;
187155
},
188156

189157
_composeScenes() {

0 commit comments

Comments
 (0)