From c5b7b11e5a78cf8510e0204119bab522f0d31f25 Mon Sep 17 00:00:00 2001 From: Serge Nanaev Date: Sat, 24 Sep 2016 16:25:10 +0300 Subject: [PATCH 1/2] fix unwanted _setUpTimer --- Carousel.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Carousel.js b/Carousel.js index d1bca7a..ee9020e 100644 --- a/Carousel.js +++ b/Carousel.js @@ -30,9 +30,27 @@ var Carousel = React.createClass({ animate: true, delay: 1000, loop: true, + carouselActivePage: 0, }; }, + componentDidUpdate(prevProps, prevState) { + const { carouselActivePage } = this.props + + + + if (carouselActivePage != prevProps.carouselActivePage) { + var activePage = 0; + if (carouselActivePage <= (this.props.children.length - 1)) { + activePage = carouselActivePage; + } else { + return; + } + + this.indicatorPressed(activePage); + } + }, + getInitialState() { return { activePage: this.props.initialPage > 0 ? this.props.initialPage : 0, @@ -120,7 +138,10 @@ var Carousel = React.createClass({ } this.indicatorPressed(activePage); - this._setUpTimer(); + + if (this.props.animate){ + this._setUpTimer(); + } }, _onAnimationBegin() { From d61763f89fce62fedc0b26c256cd95314024a137 Mon Sep 17 00:00:00 2001 From: Serge Nanaev Date: Sat, 24 Sep 2016 16:27:27 +0300 Subject: [PATCH 2/2] old code deleted --- Carousel.js | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/Carousel.js b/Carousel.js index ee9020e..9d77b32 100644 --- a/Carousel.js +++ b/Carousel.js @@ -30,27 +30,9 @@ var Carousel = React.createClass({ animate: true, delay: 1000, loop: true, - carouselActivePage: 0, }; }, - - componentDidUpdate(prevProps, prevState) { - const { carouselActivePage } = this.props - - - - if (carouselActivePage != prevProps.carouselActivePage) { - var activePage = 0; - if (carouselActivePage <= (this.props.children.length - 1)) { - activePage = carouselActivePage; - } else { - return; - } - - this.indicatorPressed(activePage); - } - }, - + getInitialState() { return { activePage: this.props.initialPage > 0 ? this.props.initialPage : 0,