From 4f86efb1dbf4a981fed4387f0f19df8a5be2b1d3 Mon Sep 17 00:00:00 2001 From: leecade Date: Wed, 23 Dec 2015 02:57:43 +0800 Subject: [PATCH] Auto play issue when only a child view | fixes #19 --- dist/index.js | 4 ++-- examples/examples/index.js | 4 ++-- src/index.js | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index 792b5eb..4fd13fa 100644 --- a/dist/index.js +++ b/dist/index.js @@ -209,7 +209,7 @@ module.exports = _reactNative2.default.createClass({ autoplay: function autoplay() { var _this = this; - if (!this.props.autoplay || this.state.isScrolling || this.state.autoplayEnd) return; + if (!Array.isArray(this.props.children) || !this.props.autoplay || this.state.isScrolling || this.state.autoplayEnd) return; clearTimeout(this.autoplayTimer); @@ -302,7 +302,7 @@ module.exports = _reactNative2.default.createClass({ * @param {number} index offset index */ scrollTo: function scrollTo(index) { - if (this.state.isScrolling) return; + if (this.state.isScrolling || this.state.total < 2) return; var state = this.state; var diff = (this.props.loop ? 1 : 0) + index + this.state.index; var x = 0; diff --git a/examples/examples/index.js b/examples/examples/index.js index 0215101..737f77d 100644 --- a/examples/examples/index.js +++ b/examples/examples/index.js @@ -209,7 +209,7 @@ module.exports = _reactNative2.default.createClass({ autoplay: function autoplay() { var _this = this; - if (!this.props.autoplay || this.state.isScrolling || this.state.autoplayEnd) return; + if (!Array.isArray(this.props.children) || !this.props.autoplay || this.state.isScrolling || this.state.autoplayEnd) return; clearTimeout(this.autoplayTimer); @@ -302,7 +302,7 @@ module.exports = _reactNative2.default.createClass({ * @param {number} index offset index */ scrollTo: function scrollTo(index) { - if (this.state.isScrolling) return; + if (this.state.isScrolling || this.state.total < 2) return; var state = this.state; var diff = (this.props.loop ? 1 : 0) + index + this.state.index; var x = 0; diff --git a/src/index.js b/src/index.js index 196ba16..92fa652 100644 --- a/src/index.js +++ b/src/index.js @@ -206,7 +206,8 @@ module.exports = React.createClass({ * Automatic rolling */ autoplay() { - if(!this.props.autoplay + if(!Array.isArray(this.props.children) + || !this.props.autoplay || this.state.isScrolling || this.state.autoplayEnd) return @@ -301,7 +302,7 @@ module.exports = React.createClass({ * @param {number} index offset index */ scrollTo(index) { - if(this.state.isScrolling) return + if (this.state.isScrolling || this.state.total < 2) return let state = this.state let diff = (this.props.loop ? 1 : 0) + index + this.state.index let x = 0