Skip to content

Commit

Permalink
fix(VSlideGroup): detect horizontal/vertical swipe intent
Browse files Browse the repository at this point in the history
fixes vuetifyjs#12293/npartically fixes vuetifyjs#10673
  • Loading branch information
yuwu9145 committed Jan 24, 2021
1 parent 7b2e19f commit 9bd7087
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/vuetify/src/components/VSlideGroup/VSlideGroup.sass
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
display: flex
flex: 1 1 auto
overflow: hidden
touch-action: none

&--disable-swipe-horizonal
touch-action: pan-y

// Modifiers
.v-slide-group__next,
Expand Down
22 changes: 21 additions & 1 deletion packages/vuetify/src/components/VSlideGroup/VSlideGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import Vue, { VNode } from 'vue'

interface TouchEvent {
touchstartX: number
touchstartY: number
touchmoveX: number
touchmoveY: number
stopPropagation: Function
}

Expand Down Expand Up @@ -89,6 +91,8 @@ export const BaseSlideGroup = mixins<options &
isOverflowing: false,
resizeTimeout: 0,
startX: 0,
disableSwipeHorizontal: false,
isSwiping: false,
scrollOffset: 0,
widths: {
content: 0,
Expand Down Expand Up @@ -250,6 +254,9 @@ export const BaseSlideGroup = mixins<options &
genWrapper (): VNode {
return this.$createElement('div', {
staticClass: 'v-slide-group__wrapper',
class: {
'v-slide-group__wrapper--disable-swipe-horizonal': this.disableSwipeHorizontal,
},
directives: [{
name: 'touch',
value: {
Expand Down Expand Up @@ -287,7 +294,18 @@ export const BaseSlideGroup = mixins<options &
content.style.setProperty('willChange', 'transform')
},
onTouchMove (e: TouchEvent) {
this.scrollOffset = this.startX - e.touchmoveX
if (!this.isSwiping) {
// only calculate disableSwipeHorizontal during the first onTouchMove invoke
// in order to ensure disableSwipeHorizontal value is consistent between onTouchStart and onTouchEnd
const diffX = e.touchmoveX - e.touchstartX
const diffY = e.touchmoveY - e.touchstartY
this.disableSwipeHorizontal = Math.abs(diffX) <= Math.abs(diffY)
this.isSwiping = true
}
if (!this.disableSwipeHorizontal) {
// sliding horizontally
this.scrollOffset = this.startX - e.touchmoveX
}
},
onTouchEnd () {
const { content, wrapper } = this.$refs
Expand All @@ -311,6 +329,8 @@ export const BaseSlideGroup = mixins<options &
this.scrollOffset = maxScrollOffset
}
}

this.isSwiping = false
},
overflowCheck (e: TouchEvent, fn: (e: TouchEvent) => void) {
e.stopPropagation()
Expand Down

0 comments on commit 9bd7087

Please sign in to comment.