Skip to content

Commit f00abfb

Browse files
feat(vertical): partical support vertical scrolling (#1017)
1 parent 2cda5bd commit f00abfb

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"react-native",
66
"ios"
77
],
8-
"version": "1.6.0-nightly.2",
8+
"version": "1.6.0-nightly.4",
99
"description": "Swiper component for React Native.",
1010
"main": "index.js",
1111
"scripts": {

src/index.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,20 +435,38 @@ export default class extends Component {
435435
* @param {string} dir 'x' || 'y'
436436
*/
437437
updateIndex = (offset, dir, cb) => {
438+
const state = this.state
438439
// Android ScrollView will not scrollTo certain offset when props change
439-
const callback = () => {
440+
const callback = async () => {
440441
cb()
441442
if (Platform.OS === 'android') {
442-
this.state.index === 0 &&
443-
this.scrollView.scrollTo({ x: state.width, y: 0, animated: false })
444-
this.state.index === this.state.total - 1 &&
445-
this.scrollView.scrollTo({
446-
x: state.width * this.state.total,
447-
animated: false
448-
})
443+
if (this.state.index === 0) {
444+
this.props.horizontal
445+
? this.scrollView.scrollTo({
446+
x: state.width,
447+
y: 0,
448+
animated: false
449+
})
450+
: this.scrollView.scrollTo({
451+
x: 0,
452+
y: state.height,
453+
animated: false
454+
})
455+
} else if (this.state.index === this.state.total - 1) {
456+
this.props.horizontal
457+
? this.scrollView.scrollTo({
458+
x: state.width * this.state.total,
459+
y: 0,
460+
animated: false
461+
})
462+
: this.scrollView.scrollTo({
463+
x: 0,
464+
y: state.height * this.state.total,
465+
animated: false
466+
})
467+
}
449468
}
450469
}
451-
const state = this.state
452470
let index = state.index
453471
if (!this.internals.offset)
454472
// Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582

0 commit comments

Comments
 (0)