From b93bbb3967e366bdd01aeebb33fe5598659b8ad0 Mon Sep 17 00:00:00 2001 From: Maciek Pastuszka Date: Thu, 21 Feb 2019 21:21:51 +0100 Subject: [PATCH 1/2] Fix autoplay --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7e43c1e..055b1ac 100644 --- a/index.js +++ b/index.js @@ -90,7 +90,7 @@ export default class Rotation extends Component { this.setCurrentFrame(reverse ? current - 1 : current + 1) } - this.nextTimeout = setTimeout(() => { + this.nextTimeout = autoPlay && setTimeout(() => { this.nextFrame() }, playTimeout) } From 7b84b31ab72e560d655e49a480d78e3e9f0bc66d Mon Sep 17 00:00:00 2001 From: Maciek Pastuszka Date: Thu, 21 Feb 2019 21:50:46 +0100 Subject: [PATCH 2/2] Add initial frame prop --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 055b1ac..83f41d1 100644 --- a/index.js +++ b/index.js @@ -28,13 +28,14 @@ export default class Rotation extends Component { tabIndex: 0, autoPlay: false, pauseOnHover: false, - onChange: () => {} + onChange: () => {}, + initialFrame: 0 } hovered = false state = { - current: 0 + current: this.props.initialFrame } componentDidMount () { @@ -45,7 +46,7 @@ export default class Rotation extends Component { } } - componentWillReceiveProps ({autoPlay}) { + componentWillReceiveProps ({autoPlay, initialFrame}) { if (autoPlay !== this.props.autoPlay) { if (autoPlay) { this.nextFrame() @@ -53,6 +54,10 @@ export default class Rotation extends Component { this.stop() } } + + if (initialFrame !== this.props.initialFrame) { + this.setCurrentFrame(initialFrame) + } } componentWillUnmount () {