Skip to content
Open
19 changes: 14 additions & 5 deletions Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var Carousel = React.createClass({
animate: true,
delay: 1000,
loop: true,
backgroundColor: 'transparent'
};
},

Expand All @@ -53,9 +54,14 @@ var Carousel = React.createClass({
}
},

syncCarouselLocation() {
var width = this.state.activePage * this.props.width;
this.refs.scrollView && this.refs.scrollView.scrollWithoutAnimationTo(0, width);
},

indicatorPressed(activePage){
this.setState({activePage});
this.refs.scrollView.scrollTo({y:0, x:activePage * width});
this.refs.scrollView.scrollTo({y:0, x:activePage * this.props.width});
},

renderPageIndicator() {
Expand All @@ -72,9 +78,11 @@ var Carousel = React.createClass({
};
position.left = (this.props.width - position.width) / 2;

for (var i = 0, l = this.props.children.length; i < l; i++) {
style = i === this.state.activePage ? { color: this.props.indicatorColor } : { color: this.props.inactiveIndicatorColor };
indicators.push(<Text style={[style, { fontSize: this.props.indicatorSize }]} key={i} onPress={this.indicatorPressed.bind(this,i)}>&bull;</Text>);
if (this.props.children.length > 1) {
for (var i = 0, l = this.props.children.length; i < l; i++) {
style = i === this.state.activePage ? { color: this.props.indicatorColor } : { color: this.props.inactiveIndicatorColor };
indicators.push(<Text style={[style, { fontSize: this.props.indicatorSize }]} key={i} onPress={this.indicatorPressed.bind(this,i)}>&bull;</Text>);
}
}

return (
Expand Down Expand Up @@ -123,7 +131,7 @@ var Carousel = React.createClass({
return (
<View style={{ flex: 1 }}>
<ScrollView ref="scrollView"
contentContainerStyle={styles.container}
contentContainerStyle={[styles.container, {backgroundColor: this.props.backgroundColor}]}
automaticallyAdjustContentInsets={false}
horizontal={true}
pagingEnabled={true}
Expand Down Expand Up @@ -156,6 +164,7 @@ var styles = StyleSheet.create({
position: 'absolute',
flexDirection: 'row',
flex: 1,
top: 190,
justifyContent: 'space-around',
alignItems: 'center',
alignSelf: 'center',
Expand Down