Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,47 @@ export default class extends Component {
}
}

/**
* Scroll to index
* @param {number} index page
* @param {bool} animated
*/

scrollTo = (index, animated = true) => {
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)

let x = 0
let y = 0
if (state.dir === 'x') x = diff * state.width
if (state.dir === 'y') y = diff * state.height

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

// update scroll state
this.internals.isScrolling = true
this.setState({
autoplayEnd: false
})

// trigger onScrollEnd manually in android
if (!animated || Platform.OS !== 'ios') {
setImmediate(() => {
this.onScrollEnd({
nativeEvent: {
position: diff
}
})
})
}
}

scrollViewPropOverrides = () => {
const props = this.props
let overrides = {}
Expand Down