From 0f63766949b2aad205a7819b491de9a690b663e1 Mon Sep 17 00:00:00 2001 From: sailplaneTW Date: Tue, 7 Feb 2017 10:03:55 +0800 Subject: [PATCH] Support autoplay pause -> resume In original codebase, only support autoplay run -> pause, support pause -> resume for performance --- package.json | 2 +- src/index.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a6bc0659..78a1aeb7 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "react-native", "ios" ], - "version": "1.5.4", + "version": "1.5.6", "description": "Swiper component for React Native.", "main": "index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 94509495..013a9ab3 100644 --- a/src/index.js +++ b/src/index.js @@ -167,6 +167,9 @@ export default class extends Component { const sizeChanged = (nextProps.width || width) !== this.state.width || (nextProps.height || height) !== this.state.height if (!nextProps.autoplay && this.autoplayTimer) clearTimeout(this.autoplayTimer) + + if (nextProps.autoplay) this.autoplay(true); + this.setState(this.initState(nextProps, sizeChanged)) } @@ -245,11 +248,11 @@ export default class extends Component { /** * Automatic rolling */ - autoplay = () => { - if (!Array.isArray(this.props.children) || + autoplay = (forceAutoPlay=false) => { + if (!forceAutoPlay && (!Array.isArray(this.props.children) || !this.props.autoplay || this.internals.isScrolling || - this.state.autoplayEnd) return + this.state.autoplayEnd)) return this.autoplayTimer && clearTimeout(this.autoplayTimer) this.autoplayTimer = setTimeout(() => {