Skip to content

fix(VSlideGroup): detect horizontal/vertical swipe intent #13005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

yuwu9145
Copy link
Member

@yuwu9145 yuwu9145 commented Jan 24, 2021

fixes #12293

partically fixes #10673

Description

As per suggestions in #10673, VSlideGroup should determine swipe intent (horizontal or vertical) first, then using swipe intent to only allow one of horizontal/vertical swipe gestures between each onTouchStart and onTouchEnd session

fixes #12293

partically fixes #10673

Motivation and Context

fixes #12293

partically fixes #10673

How Has This Been Tested?

visually

Markup:

// Paste your FULL Playground.vue here
<template>
  <v-container>
    <v-slide-group>
      <v-slide-item v-for="i in 10" :key="i" class="ma-5">
        <v-card color="#eeeeee" elevation="10" max-width="300px">
          <v-img
            src="https://cdn.vuetifyjs.com/images/cards/sunshine.jpg"
            height="200px"
          ></v-img>
          <v-card-text>
            SWITCH TO MOBILE
            <v-divider></v-divider>
            Try swiping up/down while still keeping finger on these slides
          </v-card-text>
          <v-card-actions>
            <v-spacer />
            <v-btn text> Go </v-btn>
          </v-card-actions>
        </v-card>
      </v-slide-item>
    </v-slide-group>
    <v-card class="ma-2 pa-5" v-for="i in 40" :key="i">
      <v-content>You cannot scroll past the above slides on mobile</v-content>
    </v-card>
  </v-container>
</template>

<script>
export default {
  data() {
    return {
    };
  },
};
</script>

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement/refactoring (non-breaking change that doesn't add any features but makes things better)

Checklist:

  • The PR title is no longer than 64 characters.
  • The PR is submitted to the correct branch (master for bug fixes and documentation updates, dev for new features and backwards compatible changes and next for non-backwards compatible changes).
  • My code follows the code style of this project.
  • I've added relevant changes to the documentation (applies to new features and breaking changes in core library)

Sorry, something went wrong.

@yuwu9145 yuwu9145 marked this pull request as ready for review January 24, 2021 01:47
@yuwu9145 yuwu9145 marked this pull request as draft January 24, 2021 02:01
// sliding horizontally
this.scrollOffset = this.startX - e.touchmoveX
// temporarily disable window vertical scrolling
document.documentElement.style.overflowY = 'hidden'
Copy link
Member Author

@yuwu9145 yuwu9145 Jan 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When swiping horizontally, I tried to achieve disabling vertical scrolling or touch swipe via css by setting touch-action to pan-x. However, touch-action only takes effect from next touch swipe, therefore changing touch-action to pan-x during onTouchMove will not restrict current touch move to "horizontal only" but has to wait until next touch action starts.

Hence I use a javascript way that disables whole page's vertical scroll if swiping horizontally is determined. (And remove this style in touchEnd event triggered in same component VSlideGroup). Please advice if there is a better way to disable vertical scroll passthrough once horizontal swipe intent is detected

@yuwu9145 yuwu9145 marked this pull request as ready for review January 24, 2021 03:35
@johnleider johnleider requested a review from a team February 9, 2021 20:00
@johnleider johnleider added C: VSlideGroup T: bug Functionality that does not work as intended/expected labels Feb 9, 2021
@johnleider johnleider added this to the v2.4.x milestone Feb 9, 2021
@johnleider
Copy link
Member

@babyraging can you reproduce your issue in #11571 with this?

@KaelWD KaelWD force-pushed the master branch 12 times, most recently from ddbea7b to c7a93f7 Compare February 19, 2021 14:19
@yuwu9145
Copy link
Member Author

yuwu9145 commented Mar 3, 2021

@babyraging can you reproduce your issue in #11571 with this?

Hi @johnleider , I did a test simulating @babyraging issue in #11571, this pull request does resolve it.

This is the mock that I used to test:

<template>
  <v-container>
      <v-chip-group
          mandatory
          column
          active-class="primary--text"
        >
          <v-chip
            v-for="tag in tags"
            :key="tag"
          >
            {{ tag }}
          </v-chip>
        </v-chip-group>

  </v-container>
</template>

<script>
export default {
  data() {
    return {
    tags: [
        'Work',
        'Home Improvement',
        'Vacation',
        'Food',
        'Drawers',
        'Shopping',
        'Art',
        'Tech',
        'Creative Writing',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Work',
        'Home Improvement',
        'Vacation',
        'Food',
        'Drawers',
        'Shopping',
        'Art',
        'Tech',
        'Creative Writing',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Work',
        'Home Improvement',
        'Vacation',
        'Food',
        'Drawers',
        'Shopping',
        'Art',
        'Tech',
        'Creative Writing',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Work',
        'Home Improvement',
        'Vacation',
        'Food',
        'Drawers',
        'Shopping',
        'Art',
        'Tech',
        'Creative Writing',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Work',
        'Home Improvement',
        'Vacation',
        'Food',
        'Drawers',
        'Shopping',
        'Art',
        'Tech',
        'Creative Writing',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Work',
        'Home Improvement',
        'Vacation',
        'Food',
        'Drawers',
        'Shopping',
        'Art',
        'Tech',
        'Creative Writing',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
        'Shopping',
        'Art',
        'Tech',
      ],
    };
  }
};
</script>

Also, @babyraging please feel free to leave any comments

@HammerMeetNail
Copy link

Eagerly awaiting this fix 🙏

Recently deployed a few slides on a single page and it’s very difficult to scroll the page on mobile. If you need someone to try this out to confirm it fixes vertical scroll on mobile I should be able to verify on my site tomorrow night.

Copy link
Member

@johnleider johnleider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look at the globals issue. You won't be able to import using the @ syntax.

@yuwu9145
Copy link
Member Author

yuwu9145 commented Mar 11, 2021

I'll take a look at the globals issue. You won't be able to import using the @ syntax.

Hi @johnleider , just want to clarify, should I add import { IN_BROWSER } from '../../../../docs/src/util/globals' into VSliderGroup? Feeling it is pretty hecky though (no component currently does this)

@HammerMeetNail
Copy link

Hi all - super appreciative of the work you're all doing. Looking to give this a bump cause it should make our site a lot more usable on mobile.

@yuwu9145
Copy link
Member Author

Hi all - super appreciative of the work you're all doing. Looking to give this a bump cause it should make our site a lot more usable on mobile.

Would you mind helping to verify if this fix resolves your website issue? I am happy to give you a guidance of how to do it if you need help ;)

@HammerMeetNail
Copy link

Absolutely, I'll have time tomorrow night EDT. I'll give you a shout if I have any trouble.

@HammerMeetNail
Copy link

@yuwu9145 I can confirm this fixes our slide group issue. Our page looks roughly like this:

<template>
  <div class="d-flex flex-grow-1 flex-column">

    <!-- First Slide Group-->
    <header>Header1</header>
    <v-row class="flex-grow-0" dense>
      <v-col cols="12">
        <slide :stuff="stuff"></slide>
      </v-col>
    </v-row>
    
    <!-- Second Slide Group-->
    <header>Header2</header>
    <v-row class="flex-grow-0" dense>
      <v-col cols="12">
        <slide :stuff="stuff"></slide>
      </v-col>
    </v-row>
    
    <!-- Third Slide Group-->
    <header>Header3</header>
    <v-row class="flex-grow-0" dense>
      <v-col cols="12">
        <slide :stuff="stuff"></slide>
      </v-col>
    </v-row>

  </div>
</template>

Before your fix we'd be able to recreate the issue in Chrome dev tools with the following steps:

  • Open inspector
  • Switch to mobile view
  • Try and click an item in the slide group and drag (just like you'd do if you were using touch)

This normally would prevent vertical scroll. With your fix, we can click any item in the slide group and scroll vertically.

Very eager to see this PR touched up and merged :)

@yuwu9145
Copy link
Member Author

@HammerMeetNail Thanks a lot!

@yuwu9145

This comment has been minimized.

@johnleider johnleider requested review from KaelWD and nekosaur March 31, 2021 21:19
@johnleider johnleider merged commit f6124be into vuetifyjs:master Apr 6, 2021
Malachi-M pushed a commit to kapost/vuetify that referenced this pull request Apr 22, 2021
@vuetifyjs vuetifyjs deleted a comment Apr 30, 2021
@vuetifyjs vuetifyjs deleted a comment Apr 30, 2021
@vuetifyjs vuetifyjs deleted a comment Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VSlideGroup T: bug Functionality that does not work as intended/expected
Projects
None yet
3 participants