react-responsive-carousel icon indicating copy to clipboard operation
react-responsive-carousel copied to clipboard

autoplay doesn't work when start, only work when i click nev/prev one time

Open 6thpath opened this issue 7 years ago • 14 comments

here are my option: autoPlay={true} interval={2000} infiniteLoop={true} and it seems doesn't work correctly, please help!

6thpath avatar Jan 01 '19 17:01 6thpath

Im having the same error the only fix atm is install an older version and works like a charm.

Downgraded from ^3.1.45 to 3.1.33

bernagl avatar Jan 04 '19 21:01 bernagl

Im having the same error the only fix atm is install an older version and works like a charm.

Downgraded from ^3.1.45 to 3.1.33

it works, thank you.

6thpath avatar Jan 07 '19 02:01 6thpath

It was fixed in the latest version. Feel free to update to 3.1.46

leandrowd avatar Jan 23 '19 11:01 leandrowd

I have the same issue where the carousel does not start rotating on page load. Is this fixed ? What's the workaround for this? i am using 3.1.47 version

Sujithkumara avatar Apr 08 '19 18:04 Sujithkumara

I am also facing the same issue. autoplay not working even in latest release which is 3.1.49 and yes, autoplay works in version 3.1.33 but when it comes to the last slide, it flips to the first one , scrolling backwards, navigating all the slides in between, which is not a very good user experience. Not sure, how it is working fine in Demos. :( Am I missing something here? please advise.

here are the options, I am using: autoPlay={true} infiniteLoop={true}

deepalijain1 avatar May 02 '19 07:05 deepalijain1

Same problem on ^3.1.50

leognmotta avatar Sep 18 '19 23:09 leognmotta

This issue still happens and is replicable in the project examples. @leandrowd

(It specifically happens on updating the state, not on initial render)

If I understand the workflow correctly this below piece or smth similar should also be implemented in the UNSAFE_componentWillReceiveProps or wherever in future React versions (17.x) will have to setupAutoPlay at earliest possible time right when props change:

https://github.com/leandrowd/react-responsive-carousel/blob/master/src/components/Carousel.tsx#L212

if (nextProps.autoPlay !== this.props.autoPlay) {
	if (this.props.autoPlay) {
		this.setupAutoPlay();
	} else {
		this.destroyAutoPlay();
	}

	this.setState({ autoPlay: this.props.autoPlay });
}

or may be use memoization to achieve that... Not quite sure it seems there have been a few re-implementations which eventually made this issue regressed and react lifecycle methods deprecation is not helping either.

FTR: https://github.com/leandrowd/react-responsive-carousel/issues/72

hiradyazdan avatar May 18 '20 09:05 hiradyazdan

@leandrowd I had some time to work on above mentioned issue and I realized my comment was not quite spot on, and discovered that the actual problem is that in componentDidUpdate, setupAutoPlay uses the state before autoplay is set, so it won't recognize the autoplay changed and as a result it won't call the increment method on autoPlay function. So, setupAutoPlay needs to be invoked on a callback in setState.

Also second issue is autoPlay won't work on a time interval if it's not reseted in moveTo function, unless isMouseEntered: false state was set, so that resetAutoPlay method can be reached and called in moveTo function.

So, to wrap up this issue can be resolved by modifying the componentDidUpdate to the following:

....
...
..
.
if (prevProps.autoPlay !== this.props.autoPlay) {
	if (this.props.autoPlay) {

		this.setState({ autoPlay: this.props.autoPlay, isMouseEntered: false }, () => {
			this.setupAutoPlay()
		})
	} else {
		this.destroyAutoPlay()

		this.setState({ autoPlay: this.props.autoPlay })
	}
}

I have patched the method on my end and it works fine when I need to stop the autoplay on opening a modal and start again as normal once the modal is closed.

hiradyazdan avatar Jul 27 '20 20:07 hiradyazdan

Still doesn't work on the latest version so far (3.2.10).

A workaround that worked for me was not to render the Carousel until the slides are loaded:

return (
    <>
      {slides.length > 0 && (
        <Carousel
          infiniteLoop
          autoPlay
          stopOnHover
          interval={5000}
        >
          {slides}
        </Carousel>
      )}
    </>
  );

fredsvanelli avatar Oct 27 '20 01:10 fredsvanelli

just add autoFocus={true} solved the issue

johnsonfash avatar Sep 20 '21 04:09 johnsonfash

{slides.length > 0 &&

Thanks it works fine

siddhesh1051 avatar Dec 28 '22 15:12 siddhesh1051

just add autoFocus={true} solved the issue

This worked, Thanks

ghost avatar Jun 16 '23 14:06 ghost

It doesn't work on the last version 3.2.23 @fredsvanelli Thanks it works well for me

gahette avatar Nov 11 '23 16:11 gahette

Still doesn't work on the latest version so far (3.2.10).

A workaround that worked for me was not to render the Carousel until the slides are loaded:

return (
    <>
      {slides.length > 0 && (
        <Carousel
          infiniteLoop
          autoPlay
          stopOnHover
          interval={5000}
        >
          {slides}
        </Carousel>
      )}
    </>
  );

this worked for me also, Thanks 👍 :)

jinay-kothari avatar Dec 13 '23 18:12 jinay-kothari