diff --git a/package.json b/package.json index b3cc3732..85f922bd 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "react-native", "ios" ], - "version": "1.6.0-nightly.2", + "version": "1.6.0-nightly.4", "description": "Swiper component for React Native.", "main": "index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 893fbf99..b50c4ce7 100644 --- a/src/index.js +++ b/src/index.js @@ -435,20 +435,38 @@ export default class extends Component { * @param {string} dir 'x' || 'y' */ updateIndex = (offset, dir, cb) => { + const state = this.state // Android ScrollView will not scrollTo certain offset when props change - const callback = () => { + const callback = async () => { cb() if (Platform.OS === 'android') { - this.state.index === 0 && - this.scrollView.scrollTo({ x: state.width, y: 0, animated: false }) - this.state.index === this.state.total - 1 && - this.scrollView.scrollTo({ - x: state.width * this.state.total, - animated: false - }) + if (this.state.index === 0) { + this.props.horizontal + ? this.scrollView.scrollTo({ + x: state.width, + y: 0, + animated: false + }) + : this.scrollView.scrollTo({ + x: 0, + y: state.height, + animated: false + }) + } else if (this.state.index === this.state.total - 1) { + this.props.horizontal + ? this.scrollView.scrollTo({ + x: state.width * this.state.total, + y: 0, + animated: false + }) + : this.scrollView.scrollTo({ + x: 0, + y: state.height * this.state.total, + animated: false + }) + } } } - const state = this.state let index = state.index if (!this.internals.offset) // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582