Skip to content

Commit

Permalink
fix(picker): fix a bug that confirm event failure in iOS13.4 (didi#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
QiuShuiBai authored Apr 29, 2020
1 parent af4d610 commit 2e30850
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/components/picker/picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
}
for (let i = 0; i < length; i++) {
let index = this.wheels[i].getSelectedIndex()
let index = this._getSelectIndex(this.wheels[i])
this._indexes[i] = index
let value = null
Expand Down Expand Up @@ -236,21 +236,7 @@
useTransition: USE_TRANSITION
})
wheel.on('scrollEnd', () => {
let selectedIndex
if (USE_TRANSITION) {
selectedIndex = wheel.getSelectedIndex()
} else {
// fixed BScroll not calculating selectedIndex when setting useTransition to false
const y = wheel.y
if (y > wheel.minScrollY) {
selectedIndex = 0
} else if (y < wheel.maxScrollY) {
selectedIndex = wheel.items.length - 1
} else {
selectedIndex = Math.round(Math.abs(y / wheel.itemHeight))
}
}
this.$emit(EVENT_CHANGE, i, selectedIndex)
this.$emit(EVENT_CHANGE, i, this._getSelectIndex(wheel))
})
} else {
this.wheels[i].refresh()
Expand All @@ -276,6 +262,23 @@
return data[0][this.orderKey]
}
return 0
},
// fixed BScroll not calculating selectedIndex when setting useTransition to false
_getSelectIndex(wheel) {
const y = wheel.y
let selectedIndex
if (USE_TRANSITION) {
selectedIndex = wheel.getSelectedIndex()
} else {
if (y > wheel.minScrollY) {
selectedIndex = 0
} else if (y < wheel.maxScrollY) {
selectedIndex = wheel.items.length - 1
} else {
selectedIndex = Math.round(Math.abs(y / wheel.itemHeight))
}
}
return selectedIndex
}
},
beforeDestroy() {
Expand Down

0 comments on commit 2e30850

Please sign in to comment.