Skip to content
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

Swiping through images in a gallery getting an error #128

Closed
AndreyKuleb opened this issue Mar 5, 2019 · 9 comments · Fixed by xiaolin/react-image-gallery#399
Closed

Comments

@AndreyKuleb
Copy link

AndreyKuleb commented Mar 5, 2019

Describe the bug
I use a react-image-gallery, that use react-swipeable. When i am swiping gallery, an error in console appears (see image). There are the same bug1 and bug2 reports in react-image-gallery.

Expected behavior
In bug1 a decision was offered

** Device/Browser **
MacBook Pro (Retina, 15-inch, Mid 2015)
MacOS Mojave 10.14.11
Google Chrome ver 72.0.3626.119

Additional context
2019-03-05 17 39 03
2019-03-05 17 39 11

@hartzis
Copy link
Collaborator

hartzis commented Mar 6, 2019

@AndreyKuleb thanks for creating the issue.

  • Appears to be related to v4 react-swipeable and i have made a PR to that repo before to update the version.
  • I think the best approach may be for react-image-gallery to call e.preventDefault() itself when it deems it appropriate
    • also possibly update to v5 😸

I may be able to work on a PR for the above sometime over the next couple of weeks, but feel free to attempt if you'd like.

PS As a side note those errors are more like warnings, since Calling preventDefault() for a non-cancelable event has no effect, MDN web docs - preventDefault#Notes

@13806
Copy link

13806 commented Mar 27, 2019

Can confirm this appears when { preventDefaultTouchmoveEvent: true } in v5

@hartzis
Copy link
Collaborator

hartzis commented Mar 28, 2019

@13806 is your issue also related to https://github.com/xiaolin/react-image-gallery ?

We just released 5.1.0 that also addressed this issue a bit mainly for safari browsers, but should have helped with this warning.

@13806
Copy link

13806 commented Mar 30, 2019

@hartzis no, I'm using it standalone. Simply passing handlers into a div, like so:


  const handlers = useSwipeable({
    preventDefaultTouchmoveEvent: true,
    onSwiping: handleSwiping
    // ...
  })

 <div
     {...{
         ...handlers,
     }}
 >
     // ...
  </div>

When setting preventDefaultTouchmoveEvent to false, error does not occur.

edit:
Updated to 5.1.0, the error went away but now touch stopped working, will investigate further...

@hartzis
Copy link
Collaborator

hartzis commented Mar 30, 2019

@13806 sorry to hear the 5.1.0 update broke touch.

It may be related to the new ref prop in the handlers object, https://github.com/dogfessional/react-swipeable#hook-details

In 5.1.0, we added a ref to the useSwipeable handlers and maybe you have another ref you're attaching to your div?

If you are also attaching a ref to the dom node that ...handlers is being spread on you can update it like this:

function SwipeableUsingHook(props) {
  const handlers = useSwipeable(props)
  // your custom use for ref
  const customRef = ( el ) => {
    handlers.ref(el); // call the hanlders ref for useSwipeable to work correctly
    // do whatever custom stuff you need with el
    // ...
  }
  return (
    <div {...handlers} ref={customRef}>
      // ...
    </div>
  )
}

@13806
Copy link

13806 commented Apr 1, 2019

@13806 yes that seems to be it, I'm passing refs. However, your solution won't work for me since the main component needs to be able to take ref externally as a prop (and that other component passing down the ref doesn't know what handlers the useSwipeable main component would need, so I can't define handlers there). I wonder if there's a workaround.

@hartzis
Copy link
Collaborator

hartzis commented Apr 2, 2019

@13806 I'm really curious about how you're using useSwipeable and would love to help if I can.

Any way you can either post some code or create a codesandbox.io example?

@hartzis
Copy link
Collaborator

hartzis commented May 14, 2019

PR created to address in react-image-gallery xiaolin/react-image-gallery#399

This was referenced May 20, 2019
@hartzis
Copy link
Collaborator

hartzis commented May 23, 2019

Closed for react-swipeable with #145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants