Skip to content

Commit

Permalink
Merge pull request phil-r#19 from elbstack/master
Browse files Browse the repository at this point in the history
New prop for listening to slide events
  • Loading branch information
phil-r committed Dec 27, 2015
2 parents 61fb789 + 064d3bf commit 2914d6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ var React = require('react-native');
var TimerMixin = require('react-timer-mixin');

var {
AppRegistry,
StyleSheet,
Image,
Text,
ScrollView,
View
Expand All @@ -26,7 +24,8 @@ var Carousel = React.createClass({
style: View.propTypes.style,
pageStyle: View.propTypes.style,
contentContainerStyle: View.propTypes.style,
autoplay: React.PropTypes.bool
autoplay: React.PropTypes.bool,
onAnimateNextPage: React.PropTypes.func
},
mixins: [TimerMixin],
getDefaultProps: function() {
Expand Down Expand Up @@ -96,14 +95,22 @@ var Carousel = React.createClass({
var size = this.state.size;
k++;

this.setState({currentPage: k});
this.setState({currentPage: k}, () => {
if (this.props.onAnimateNextPage) {
this.props.onAnimateNextPage(this.state.currentPage)
}
})
this.refs.scrollView.scrollTo(0, k*size.width);
this._setUpTimer();
},
_calculateCurrentPage: function(offset) {
var size = this.state.size;
var page = Math.floor((offset - size.width/2) / size.width) + 1;
this.setState({currentPage: page});
this.setState({currentPage: page}, () => {
if (this.props.onAnimateNextPage) {
this.props.onAnimateNextPage(this.state.currentPage)
}
});
},
//TODO: add optional `dots` for displaying current page (like pageControl)
render: function() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"license": "MIT",
"peerDependencies": {
"react-native": "^0.13.0 || ^0.14.0 || ^0.15.0"
"react-native": ">=0.13.0 <=0.17.0"
},
"dependencies": {
"react-timer-mixin": "^0.13.3"
Expand Down

0 comments on commit 2914d6b

Please sign in to comment.