Skip to content

Commit

Permalink
fix(autoplay): replay when autoplay is setted to true
Browse files Browse the repository at this point in the history
  • Loading branch information
李宜东 committed Jun 27, 2019
1 parent c90de7b commit a4c06c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"react-native",
"ios"
],
"version": "1.6.0-dev",
"version": "1.6.0-nightly.1",
"description": "Swiper component for React Native.",
"main": "index.js",
"scripts": {
Expand Down
17 changes: 15 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ export default class extends Component {
this.props.onIndexChanged(nextState.index)
}

componentDidUpdate(prevProps) {
// If autoplay props updated to true, autoplay immediately
if (this.props.autoplay && !prevProps.autoplay) {
this.autoplay()
}
}

initState(props, updateIndex = false) {
// set the current state
const state = this.state || { width: 0, height: 0, offset: { x: 0, y: 0 } }
Expand Down Expand Up @@ -511,7 +518,12 @@ export default class extends Component {
*/

scrollTo = (index, animated = true) => {
if (this.internals.isScrolling || this.state.total < 2 || index == this.state.index) return
if (
this.internals.isScrolling ||
this.state.total < 2 ||
index == this.state.index
)
return

const state = this.state
const diff = this.state.index + (index - this.state.index)
Expand All @@ -522,7 +534,8 @@ export default class extends Component {
if (state.dir === 'y') y = diff * state.height

if (Platform.OS !== 'ios') {
this.scrollView && this.scrollView[animated ? 'setPage' : 'setPageWithoutAnimation'](diff)
this.scrollView &&
this.scrollView[animated ? 'setPage' : 'setPageWithoutAnimation'](diff)
} else {
this.scrollView && this.scrollView.scrollTo({ x, y, animated })
}
Expand Down

0 comments on commit a4c06c5

Please sign in to comment.