Skip to content

Commit

Permalink
set offset in state when loop jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
nemophrost committed Oct 11, 2016
1 parent fa4202b commit b3fbff5
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/index.js
Expand Up @@ -344,11 +344,34 @@ export default class extends Component {
}
}

const newState = {}
newState.index = index
newState.loopJump = loopJump

this.internals.offset = offset
this.setState({
index: index,
loopJump: loopJump
}, cb)

// only update offset in state if loopJump is true
if (loopJump) {
// when swiping to the beginning of a looping set for the third time,
// the new offset will be the same as the last one set in state.
// Setting the offset to the same thing will not do anything,
// so we increment it by 1 then immediately set it to what it should be,
// after render.
if (offset[dir] === this.state.offset[dir]) {
newState.offset = { x: 0, y: 0 }
newState.offset[dir] = offset[dir] + 1
this.setState(newState, () => {
this.setState({ offset: offset }, cb)
})
}
else {
newState.offset = offset
this.setState(newState, cb)
}
}
else {
this.setState(newState, cb)
}
}

/**
Expand Down

0 comments on commit b3fbff5

Please sign in to comment.