@ldn0x7dc/react-native-view-pager
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -43,2 +43,8 @@ import React, { PropTypes, Component } from 'react'; | ||
currentPage = undefined; //Do not initialize to make onPageSelected(0) be dispatched | ||
layoutChanged = false; | ||
initialPageSettled = false; | ||
layoutChanged = false; | ||
activeGesture = false; | ||
constructor(props) { | ||
@@ -48,16 +54,11 @@ super(props); | ||
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); | ||
this.dataSource = ds.cloneWithRows([]); | ||
this.state = { | ||
width: 0, | ||
height: 0 | ||
height: 0, | ||
dataSource: ds.cloneWithRows([]) | ||
} | ||
this.currentPage; //Do not initialize to make onPageSelected(0) be dispatched | ||
this.pageCount = 0; | ||
this.initialPageSettled = false; | ||
this.activeGesture = false; | ||
this.scroller = new Scroller(true, (dx, dy, scroller) => { | ||
if (dx === 0 && dy === 0 && scroller.isFinished()) { | ||
if(!this.activeGesture) { | ||
if (!this.activeGesture) { | ||
this.changePageScrollState('idle'); | ||
@@ -73,3 +74,3 @@ } | ||
let fraction = (curX - this.getScrollOffsetOfPage(position) - this.props.pageMargin) / this.state.width; | ||
if(fraction < 0) { | ||
if (fraction < 0) { | ||
fraction = 0; | ||
@@ -107,3 +108,3 @@ } | ||
this.changePageScrollState('settling'); | ||
if(!disableSettle) { | ||
if (!disableSettle) { | ||
this.settlePage(gestureState.vx); | ||
@@ -114,8 +115,9 @@ } | ||
render() { | ||
if(this.state.width && this.state.height) { | ||
let dataSource = this.state.dataSource; | ||
if (this.state.width && this.state.height) { | ||
let list = this.props.pageDataArray; | ||
if(!list) { | ||
if (!list) { | ||
list = []; | ||
} | ||
this.dataSource = this.dataSource.cloneWithRows(list); | ||
dataSource = dataSource.cloneWithRows(list); | ||
this.pageCount = list.length; | ||
@@ -125,3 +127,3 @@ } | ||
let gestureResponder = this.gestureResponder; | ||
if(!this.props.scrollEnabled || this.pageCount <= 0) { | ||
if (!this.props.scrollEnabled || this.pageCount <= 0) { | ||
gestureResponder = {}; | ||
@@ -141,3 +143,3 @@ } | ||
enableEmptySections={true} | ||
dataSource={this.dataSource} | ||
dataSource={dataSource} | ||
renderRow={this.renderRow.bind(this)} | ||
@@ -166,3 +168,3 @@ onLayout={this.onLayout.bind(this)} | ||
if(this.props.pageMargin > 0 && rowID > 0) { | ||
if (this.props.pageMargin > 0 && rowID > 0) { | ||
//Do not using margin style to implement pageMargin. The ListView seems calculate a wrong width for children views with margin. | ||
@@ -183,4 +185,7 @@ return ( | ||
if (width && height && sizeChanged) { | ||
//if layout changed, create a new DataSource instance to trigger renderRow | ||
this.layoutChanged = true; | ||
this.setState({ | ||
width, height | ||
width, height, | ||
dataSource: (new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})).cloneWithRows([]) | ||
}); | ||
@@ -194,3 +199,3 @@ } | ||
if(Platform.OS === 'ios') { | ||
if (Platform.OS === 'ios') { | ||
this.scrollToPage(this.props.initialPage, true); | ||
@@ -201,2 +206,13 @@ } else { | ||
} | ||
} else if (this.layoutChanged) { | ||
this.layoutChanged = false; | ||
if (typeof this.currentPage === 'number') { | ||
if (Platform.OS === 'ios') { | ||
this.scrollToPage(this.currentPage, true); | ||
} else { | ||
//A trick to solve bugs on Android. Delay a little | ||
setTimeout(this.scrollToPage.bind(this, this.currentPage, true), 0); | ||
} | ||
} | ||
} | ||
@@ -251,3 +267,3 @@ } | ||
const finalX = this.getScrollOffsetOfPage(page); | ||
if(immediate) { | ||
if (immediate) { | ||
this.scroller.startScroll(this.scroller.getCurrX(), 0, finalX - this.scroller.getCurrX(), 0, 0); | ||
@@ -261,3 +277,3 @@ } else { | ||
changePage(page) { | ||
if(this.currentPage !== page) { | ||
if (this.currentPage !== page) { | ||
this.currentPage = page; | ||
@@ -264,0 +280,0 @@ this.props.onPageSelected && this.props.onPageSelected(page); |
{ | ||
"name": "@ldn0x7dc/react-native-view-pager", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "library/ViewPager.js", |
11810
259