Skip to content

Commit

Permalink
Omit react-native-viewpager to avoid bug (and reduce some UX)
Browse files Browse the repository at this point in the history
  • Loading branch information
imWildCat committed Oct 13, 2016
1 parent 5c0579e commit df3be5b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 37 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"react-native-root-toast": "^1.0.3",
"react-native-router-flux": "^3.35.0",
"react-native-vector-icons": "^2.0.3",
"react-native-viewpager": "^0.2.11",
"react-redux": "^4.4.5",
"redux": "^3.5.2",
"redux-thunk": "^2.1.0",
Expand Down
1 change: 0 additions & 1 deletion src/components/common/TopicList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class TopicListPage extends Component {
};

onFetch = (page = 1, callback, options) => {
console.log({options});
const { slug, isNode } = this.props;
const uri = isNode ? `/go/${slug}` : `?tab=${slug}`;
V2Networking.get(uri)
Expand Down
46 changes: 11 additions & 35 deletions src/components/pages/DiscoveryTab/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {Component, PropTypes} from 'react';
import {View, StyleSheet} from 'react-native';
import ViewPager from 'react-native-viewpager';
import {Actions} from 'react-native-router-flux';

import PageContainer from '../../common/PageContainer';
Expand All @@ -25,23 +24,10 @@ const tabData = [

class DiscoveryTabPage extends Component {

constructor(props) {
super(props);
// Use this flag to avoid the bug about that `react-native-scrollable-tab-view` could call onChangeTab() twice
this.currentIndex = 0;

this.segmentedControlTitles = [];

// Configure ViewPager
const dataSource = new ViewPager.DataSource({
pageHasChanged: (p1, p2) => p1.slug !== p2.slug,
});

this.state = {
dataSource: dataSource.cloneWithPages(tabData)
};
}

segmentedControlTitles = [];
state = {
index: 0,
};

componentWillMount() {
this._initViews();
Expand All @@ -55,7 +41,7 @@ class DiscoveryTabPage extends Component {
}

onSegmentedControlButtonPress(index) {
this.viewPager.goToPage(index);
this.setState({ index });
}

_initViews() {
Expand All @@ -78,33 +64,23 @@ class DiscoveryTabPage extends Component {
}}
onPress={this.onSegmentedControlButtonPress.bind(this)}
style={styles.segmentedControl} />
<ViewPager
ref={(ref) => {
this.viewPager = ref;
}}
style={{ flex: 1 }}
dataSource={this.state.dataSource}
renderPage={this._renderPage.bind(this)}
onChangePage={this._onChangePage.bind(this)}
isLoop={false}
autoPlay={false}
renderPageIndicator={false}
/>
{this.renderContent()}
</PageContainer>
);
}

_renderPage(data, pageID) {
renderContent = () => {
return this.renderPage(tabData[this.state.index]);
};

renderPage(data) {
return (
<TopicList
key={`tab_slug_${data.slug}`}
slug={data.slug} />
);
}

_onChangePage(i) {
this.segmentedControl.setIndex(i);
}

onNewTopicButtonPress = () => {
Actions.newTopic({ nodeSlug: this.props.slug });
Expand Down

0 comments on commit df3be5b

Please sign in to comment.