Skip to content

Commit 2e9720f

Browse files
committed
Fix threshold name error & iOS scrolling spring-back bug
1 parent a69ce57 commit 2e9720f

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const VirtualList = Vue.component(NAME, {
5050
}, this.onRangeChanged)
5151

5252
// just for debug
53-
// window.virtual = this.virtual
53+
window.virtual = this.virtual
5454

5555
// also need sync initial range first.
5656
this.range = this.virtual.getRange()
@@ -108,8 +108,16 @@ const VirtualList = Vue.component(NAME, {
108108
}
109109

110110
const offset = root[this.directionKey]
111+
const offsetShape = root[this.isHorizontal ? 'clientWidth' : 'clientHeight']
112+
const scrollShape = root[this.isHorizontal ? 'scrollWidth' : 'scrollHeight']
113+
114+
// iOS scrolling spring-back behavior will make direction mistake.
115+
if (offset + offsetShape > scrollShape) {
116+
return
117+
}
118+
111119
this.virtual.handleScroll(offset)
112-
this.emitEvent(offset, evt)
120+
this.emitEvent(offset, offsetShape, scrollShape, evt)
113121
},
114122

115123
getUniqueIdFromDataSources () {
@@ -125,18 +133,14 @@ const VirtualList = Vue.component(NAME, {
125133
},
126134

127135
// emit event in special position.
128-
emitEvent (offset, evt) {
129-
// ref element is definitely available here.
130-
const { root } = this.$refs
136+
emitEvent (offset, offsetShape, scrollShape, evt) {
131137
const range = this.virtual.getRange()
132138
const isFront = this.virtual.isFront()
133139
const isBehind = this.virtual.isBehind()
134-
const offsetShape = root[this.isHorizontal ? 'clientWidth' : 'clientHeight']
135-
const scrollShape = root[this.isHorizontal ? 'scrollWidth' : 'scrollHeight']
136140

137-
if (isFront && !!this.dataSources.length && offset - this.upperThreshold <= 0) {
141+
if (isFront && !!this.dataSources.length && offset - this.topThreshold <= 0) {
138142
this.$emit('totop', evt, range)
139-
} else if (isBehind && offset + offsetShape + this.lowerThreshold >= scrollShape) {
143+
} else if (isBehind && offset + offsetShape + this.bottomThreshold >= scrollShape) {
140144
this.$emit('tobottom', evt, range)
141145
} else {
142146
this.$emit('scroll', evt, range)

src/props.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ export const VirtualProps = {
4545
type: String,
4646
default: 'vertical' // the other value is horizontal.
4747
},
48-
upperThreshold: {
48+
topThreshold: {
4949
type: Number,
5050
default: 0
5151
},
52-
lowerThreshold: {
52+
bottomThreshold: {
5353
type: Number,
5454
default: 0
5555
},

0 commit comments

Comments
 (0)