Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Binary file added .DS_Store
Binary file not shown.
15 changes: 14 additions & 1 deletion library/ViewPager.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ export default class ViewPager extends Component {
}
}

componentWillReceiveProps(nextProps) {
if (nextProps.initialPage !== this.props.initialPage) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if initialPage changed , then scroll to nextProps.initialPage.
this code should be put in componentWillReceiveProps not in componentDidUpdate

if (typeof nextProps.initialPage === 'number') {
if (Platform.OS === 'ios') {
this.scrollToPage(nextProps.initialPage, true);
} else {
//A trick to solve bugs on Android. Delay a little
setTimeout(this.scrollToPage.bind(this, nextProps.initialPage, true), 0);
}
}
};
}

componentDidUpdate(prevProps, prevState) {
if (!this.initialPageSettled) {
this.initialPageSettled = true;
Expand All @@ -187,7 +200,7 @@ export default class ViewPager extends Component {
//A trick to solve bugs on Android. Delay a little
setTimeout(this.scrollToPage.bind(this, this.props.initialPage, true), 0);
}
} else if (this.layoutChanged || prevProps.pageDataArray.length !== this.props.pageDataArray.length) {
} else if (this.layoutChanged) {
this.layoutChanged = false;
if (typeof this.currentPage === 'number') {
if (Platform.OS === 'ios') {
Expand Down