question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Horizontal scrolling in nested component not working as expected

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • It might however be related to issue #33.

When putting a nested component with horizontal scrolling inside a swipeable view it is not scrollable when additionally nested in an element with overflow: hidden.

Expected Behavior

Scrolling in the nested element and swiping should both normally work

Current Behavior

Horizontally scrolling in the nested component does not work at all while the swiping between slides remains working as expected.

Steps to Reproduce (for bugs)

https://codesandbox.io/s/m7npp2rz78 And demo here: https://m7npp2rz78.codesandbox.io/

  1. Open dev tools and simulate a mobile device using the device selection toolbar
  2. swipe between separate slides (works as expected) [/]
  3. try scrolling horizontally in the long text in the first line of the first slide => [x] does not work

Also:

  1. Remove the overflow: hidden style from the component wrapping the text (id = overflowWrapper)
  2. Both swiping and scrolling work as expected again

Context

I have navigation entries on a page (i.e. a slide in the swipeable) that can grow wide. They usually fit horizontally on a page but might be cut off for narrow screen devices like an iPhone 5. Therefore I have them scrolling (I use overflow: 'auto') when they are wider than the screen so they remain accessible.

Your Environment

Tested with Chrome (63.0.3239.108 64bit) on Linux and macOS

I’ll happily provide more info if any is needed.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

18reactions
ephyscommented, Sep 14, 2018

I can’t understand why SwipeableViews is receiving the event since the stopPropagation for me means a real stop propagation.

I have the same issue. I think it’s because react-swipeable-views uses the native DOM event handlers instead of react’s synthetic events.

My solution was to do the same:

class MyComponentWhichMustBlockTouchEventsSoItsContentIsScrollableAgain extends React.Component {
  container = React.createRef();

  componentDidMount() {
    const containerNode = this.container.current;

    if (!containerNode) {
      return;
    }

    containerNode.addEventListener('touchstart', this.isolateTouch, { passive: true });
    containerNode.addEventListener('touchmove', this.isolateTouch, { passive: true });
    containerNode.addEventListener('touchend', this.isolateTouch, { passive: true });
  }

  componentWillUnmount() {
    const containerNode = this.container.current;

    if (!containerNode) {
      return;
    }

    containerNode.removeEventListener('touchstart', this.isolateTouch, { passive: true });
    containerNode.removeEventListener('touchmove', this.isolateTouch, { passive: true });
    containerNode.removeEventListener('touchend', this.isolateTouch, { passive: true });
  }

  isolateTouch(e) {
    e.stopPropagation();
  }

  render() {
    return (
      <div ref={this.container}>
        {this.props.children}
      </div>
    );
  }
}
0reactions
vanhoutenboscommented, Dec 11, 2019

The Answer is above 😃 Thank you Ephys!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested Listview not scrolling horizontally - Stack Overflow
I have commented the 3 types of scrolls you need. If anything is not as expected, please mention. Widget build(BuildContext context) { return ......
Read more >
Fixing RecyclerView nested scrolling in opposite direction
Horizontal scroll is expected, but vertical scroll kicks in instead. ... component is causing these problems: the parent RecyclerView .
Read more >
Horizontal Scroll With Multiple Nested Animations - GreenSock
This seems to work in the way you intend. Just remove some of the data-pin attributes and it seems to be dynamic enough:...
Read more >
How to set scrollbars for nested components - Telerik
Hello, I am trying, without success, to get the scroll bars to appear properly on my page. Here's the scenario,.
Read more >
Support nested scrolling elements with the same scroll direction.
Horizontal ViewPager2 not correctly working into a vertical RecyclerView ... With RecyclerView as scrollable component in ViewPager it works as expected.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found