Skip to content

Commit e7b563d

Browse files
author
Benoît Delmaire
authored
Merge pull request #590 from HelloCore/fix/autoplay-after-imperative
Fix autoplay stops after user interaction
2 parents 9587256 + b989fd0 commit e7b563d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/carousel/Carousel.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ export default class Carousel extends Component {
836836

837837
// `onTouchStart` is fired even when `scrollEnabled` is set to `false`
838838
if (this._getScrollEnabled() !== false && this._autoplaying) {
839-
this.stopAutoplay();
839+
this.pauseAutoPlay();
840840
}
841841

842842
if (onTouchStart) {
@@ -847,7 +847,7 @@ export default class Carousel extends Component {
847847
_onTouchEnd () {
848848
const { onTouchEnd } = this.props
849849

850-
if (this._getScrollEnabled() !== false && autoplay && !this._autoplaying) {
850+
if (this._getScrollEnabled() !== false && this._autoplay && !this._autoplaying) {
851851
// This event is buggy on Android, so a fallback is provided in _onScrollEnd()
852852
this.startAutoplay();
853853
}
@@ -902,7 +902,7 @@ export default class Carousel extends Component {
902902
}
903903

904904
_onScrollEnd (event) {
905-
const { autoplay, autoplayDelay, enableSnap } = this.props;
905+
const { autoplayDelay, enableSnap } = this.props;
906906

907907
if (this._ignoreNextMomentum) {
908908
// iOS fix
@@ -919,7 +919,7 @@ export default class Carousel extends Component {
919919

920920
// The touchEnd event is buggy on Android, so this will serve as a fallback whenever needed
921921
// https://github.com/facebook/react-native/issues/9439
922-
if (autoplay && !this._autoplaying) {
922+
if (this._autoplay && !this._autoplaying) {
923923
clearTimeout(this._enableAutoplayTimeout);
924924
this._enableAutoplayTimeout = setTimeout(() => {
925925
this.startAutoplay();
@@ -1081,6 +1081,7 @@ export default class Carousel extends Component {
10811081

10821082
startAutoplay () {
10831083
const { autoplayInterval, autoplayDelay } = this.props;
1084+
this._autoplay = true;
10841085

10851086
if (this._autoplaying) {
10861087
return;
@@ -1097,9 +1098,14 @@ export default class Carousel extends Component {
10971098
}, autoplayDelay);
10981099
}
10991100

1100-
stopAutoplay () {
1101+
pauseAutoPlay () {
11011102
this._autoplaying = false;
1102-
clearInterval(this._autoplayInterval);
1103+
clearInterval(this._autoplayInterval);
1104+
}
1105+
1106+
stopAutoplay () {
1107+
this._autoplay = false;
1108+
this.pauseAutoPlay();
11031109
}
11041110

11051111
snapToItem (index, animated = true, fireCallback = true) {

0 commit comments

Comments
 (0)