Skip to content

Commit

Permalink
feat(module): add temporary prop 'carouselHorizontalPadding'
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-arc committed Apr 24, 2017
1 parent 115b966 commit a0afcaf
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export default class Carousel extends Component {
* Delay until navigating to the next item
*/
autoplayInterval: PropTypes.number,
/**
* Override container's inner padding
* WARNING: current padding calculation is necessary for slide's centering
* Be aware that using this prop can mess with carousel's behavior
*/
carouselHorizontalPadding: PropTypes.number,
/**
* Global wrapper's style
*/
Expand Down Expand Up @@ -114,6 +120,7 @@ export default class Carousel extends Component {
autoplay: false,
autoplayDelay: 5000,
autoplayInterval: 3000,
carouselHorizontalPadding: null,
containerCustomStyle: {},
contentContainerCustomStyle: {},
enableMomentum: false,
Expand Down Expand Up @@ -429,7 +436,7 @@ export default class Carousel extends Component {
if (this._scrollview) {
this._scrollview.scrollTo({ x: snapX, y: 0, animated });
this.props.onSnapToItem && fireCallback && this.props.onSnapToItem(index);
this.setState({oldItemIndex: index});
this.setState({ oldItemIndex: index });

// iOS fix, check the note in the constructor
if (!initial && Platform.OS === 'ios') {
Expand Down Expand Up @@ -495,9 +502,16 @@ export default class Carousel extends Component {
}

render () {
const { sliderWidth, itemWidth, containerCustomStyle, contentContainerCustomStyle, enableMomentum } = this.props;

const containerSideMargin = (sliderWidth - itemWidth) / 2;
const {
sliderWidth,
itemWidth,
containerCustomStyle,
contentContainerCustomStyle,
enableMomentum,
carouselHorizontalPadding
} = this.props;

const containerSideMargin = carouselHorizontalPadding || (sliderWidth - itemWidth) / 2;

const style = [
containerCustomStyle || {},
Expand Down

0 comments on commit a0afcaf

Please sign in to comment.