Skip to content

Commit 2f374b3

Browse files
committed
Use getWidth() and wrapping children to have consistent width
1 parent cf8ca56 commit 2f374b3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Carousel.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var Carousel = React.createClass({
2929
indicatorSpace: 25,
3030
animate: true,
3131
delay: 1000,
32-
loop: true,
32+
loop: true
3333
};
3434
},
3535

@@ -135,12 +135,17 @@ var Carousel = React.createClass({
135135
},
136136

137137
render() {
138+
let width = this.getWidth()
139+
let style = {
140+
flex: 1,
141+
width: width
142+
}
143+
138144
return (
139-
<View style={{ flex: 1 }}>
145+
<View style={style}>
140146
<CarouselPager
141147
ref="pager"
142-
width={this.getWidth()}
143-
contentContainerStyle={styles.container}
148+
width={width}
144149
onBegin={this._onAnimationBeginPage}
145150
onEnd={this._onAnimationEnd}
146151
>

CarouselPager.ios.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var React = require('react');
22
var {
33
ScrollView,
4+
View
45
} = require('react-native');
56

67
var CarouselPager = React.createClass({
@@ -29,9 +30,13 @@ var CarouselPager = React.createClass({
2930
onMomentumScrollEnd={this._onMomentumScrollEnd}
3031
scrollsToTop={false}
3132
>
32-
{this.props.children}
33+
{React.Children.map(this.props.children, this.setWidth)}
3334
</ScrollView>;
3435
},
36+
37+
setWidth(child) {
38+
return (<View style={{ width: this.props.width }}>{child}</View>)
39+
}
3540
});
3641

3742
module.exports = CarouselPager;

0 commit comments

Comments
 (0)