diff --git a/index.js b/index.js index c2801cd..5e8c228 100644 --- a/index.js +++ b/index.js @@ -24,13 +24,20 @@ var Carousel = React.createClass({ pageStyle: View.propTypes.style, contentContainerStyle: View.propTypes.style, autoplay: React.PropTypes.bool, + pageInfo: React.PropTypes.bool, + pageInfoBackgroundColor: React.PropTypes.string, + pageInfoTextStyle: Text.propTypes.style, + pageInfoTextSeparator: React.PropTypes.string, onAnimateNextPage: React.PropTypes.func }, mixins: [TimerMixin], getDefaultProps() { return { delay: PAGE_CHANGE_DELAY, - autoplay: true + autoplay: true, + pageInfo: false, + pageInfoBackgroundColor: 'rgba(0, 0, 0, 0.25)', + pageInfoTextSeparator: ' / ', }; }, getInitialState() { @@ -99,7 +106,7 @@ var Carousel = React.createClass({ this.props.onAnimateNextPage(this.state.currentPage) } }) - this.refs.scrollView.scrollTo(0, k*size.width); + this.refs.scrollView.scrollTo({ y: 0, x: k*size.width }); this._setUpTimer(); }, _calculateCurrentPage(offset) { @@ -111,6 +118,17 @@ var Carousel = React.createClass({ } }); }, + _renderPageInfo(pageLength) { + return ( + + + + {`${this.state.currentPage}${this.props.pageInfoTextSeparator}${pageLength}`} + + + + ); + }, //TODO: add optional `dots` for displaying current page (like pageControl) render() { var pages = [], @@ -152,9 +170,8 @@ var Carousel = React.createClass({ } pages = pages.map((page, i) => - {page} + + {page} ); @@ -186,6 +203,7 @@ var Carousel = React.createClass({ return ( {contents} + {this.props.pageInfo && this._renderPageInfo(children.length)} ); }, @@ -193,7 +211,29 @@ var Carousel = React.createClass({ var styles = StyleSheet.create({ horizontalScroll: { - position:'absolute' + position:'absolute', + }, + pageInfoBottomContainer: { + position: 'absolute', + bottom: 20, + left: 0, + right: 0, + backgroundColor: 'transparent', + }, + pageInfoContainer: { + alignItems: 'center', + justifyContent: 'center', + backgroundColor: 'transparent' + }, + pageInfoPill: { + width: 80, + height: 20, + borderRadius: 10, + alignItems: 'center', + justifyContent: 'center', + }, + pageInfoText: { + textAlign: 'center', } }); diff --git a/package.json b/package.json index e496d42..b5e3531 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ ], "license": "MIT", "peerDependencies": { - "react-native": ">=0.16.0 <=0.17.0" + "react-native": ">=0.16.0 <=0.21.0" }, "dependencies": { "react-timer-mixin": "^0.13.3"