ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Feature request: introduce setting to allow vertical scroll from a child scroll to affect parent

Open bra1n opened this issue 12 years ago • 37 comments

Hi,

in issue #1462 there was a feature request to allow "bubbling" of scroll events from a child container to its parent container. Let's look at an example:

<ion-content>
  Here be lots of text
  <ion-scroll direction="x">
    Here be a really long line of text, to allow horizontal scrolling...
  </ion-scroll>
  Here be even more text and some dragons.
</ion-content>

Demo: http://codepen.io/anon/pen/BoGkA

Scrolling the ion-scroll horizontally works fine, but as soon as you (accidentally) start your touchDown/mouseDown inside the ion-scroll, you will no longer be able to vertically scroll the ion-content. Sometimes, you have a screen with a really big horizontal scroll element that also needs to be vertically scrollable, which will make scrolling that screen up and down really difficulty, since you mustn't start your scroll motion inside the horizontal scrolling element. In the aforementioned ticket, the cause for this was found in tap.js Line 154. If I remove the (e.defaultPrevented) condition, I'm able to scroll both the child and the parent at the same time. Since this doesn't seem to cause any other behaviour problems (I tested it on native Android, iOS browser, desktop browser), it would be great if this specific condition could be turned into a flag that I could set either on the general Ionic Framework or (even better) on each child scroll container. What do you think?

Example: <ion-scroll direction="x" scroll-outside="true">

bra1n avatar Nov 04 '14 14:11 bra1n

There is a temporary fix for this according to @bra1n

For some reason, the only way to fix it there was to monkey-patch a line in the ionic.bundle.js:

ignoreScrollStart: function(e) { return //(e.defaultPrevented) || // <-- comment out this first condition to have scroll events bubble up

sshakeel avatar Nov 13 '14 03:11 sshakeel

+1

85lele avatar Nov 13 '14 14:11 85lele

if comment e.preventDefault() here: https://github.com/driftyco/ionic/blob/b69cad8b845596fdd162a4910fb73e239505760b/js/views/scrollView.js#L732 and here: https://github.com/driftyco/ionic/blob/b69cad8b845596fdd162a4910fb73e239505760b/js/views/scrollView.js#L822

Then two scroll work fine.

But need add check: has ancestor node scroll with different direction.

Ti-webdev avatar Nov 20 '14 05:11 Ti-webdev

@Ti-webdev I also tried that fix, however it seems to not be compatible with the native Android app. Scrolling stopped working there altogether for me, if I applied that fix.

bra1n avatar Nov 20 '14 15:11 bra1n

@bra1n My way work with native Android app.

Ti-webdev avatar Nov 21 '14 03:11 Ti-webdev

On emulator does not work too :(

Ti-webdev avatar Nov 21 '14 12:11 Ti-webdev

I'm having trouble with Android too.

I have a list of horizontally scrollable divs inside a vertically scrollable content container. It works fine in the browser with Ti-webdev's fix, I can scroll in both directions and the scroll event bubbles correctly.

But on the Android device (4.4.4), the divs only scroll horizontally when I swipe vertically on them! They don't pick up the horizontal swipe gesture. I use the side menu template and I wonder if this can be the source of the confusion as it is listening for the swipe left to right event.

Are you guys having this issue too ?

pm-desjonqueresg avatar Nov 24 '14 19:11 pm-desjonqueresg

Try https://github.com/driftyco/ionic/pull/2606

Ti-webdev avatar Nov 25 '14 14:11 Ti-webdev

@Ti-webdev Thanks, It works!

I had to copy paste the code you added in the ionScroll directive (adding scroll-x|y classes) to ionContent to make it work in my case (ion-content is my parent scroll container).

pm-desjonqueresg avatar Nov 26 '14 20:11 pm-desjonqueresg

Plunker at bottom of this comment demonstrating the "monkey patch" solution

http://forum.ionicframework.com/t/when-using-horizontal-scroll-ion-scroll-page-cant-be-scrolled-down-in-y-direction/3833/22?u=andmar8

andmar8 avatar Dec 02 '14 13:12 andmar8

Unfortunately I run into the same issue. It would be helpful to know whether you plan to fix this issue in the near feature. If so, until when do you think you are going to release the fix?

marcelrassinger avatar Jan 29 '15 15:01 marcelrassinger

This one is tricky since we have to determine a direction before we decide to start preventing default. Doing that smoothly can be problematic. We should address it though.

Horizontal scrolls should not break vertical scrolling.

perrygovier avatar Feb 09 '15 21:02 perrygovier

@perrygovier You can apply my PR and improve the smoothness of the future.

Ti-webdev avatar Feb 10 '15 06:02 Ti-webdev

@perrygovier @Ti-webdev I was able to make it work as expected. My solution is to lock the scrolling to one direction at a time, horizontal or vertical, no diagonal scrolling. In the doTouchMove function, I simply calculate which move is the greatest between X and Y, and allow scrolling accordingly.

      var mX = Math.abs(moveX * self.options.speedMultiplier),
            mY = Math.abs(moveY * self.options.speedMultiplier);

      if (self.__enableScrollX && mX >= mY) {

        scrollLeft -= moveX * self.options.speedMultiplier;
        var maxScrollLeft = self.__maxScrollLeft;

        if (scrollLeft > maxScrollLeft || scrollLeft < 0) {

          // Slow down on the edges
          if (self.options.bouncing) {

            scrollLeft += (moveX / 2  * self.options.speedMultiplier);

          } else if (scrollLeft > maxScrollLeft) {

            scrollLeft = maxScrollLeft;

          } else {

            scrollLeft = 0;

          }
        }
      }

      // Compute new vertical scroll position
      if (self.__enableScrollY && mY > mX) {
         ...

pm-desjonqueresg avatar Feb 10 '15 20:02 pm-desjonqueresg

@pm-desjonqueresg How do you clear out direction. I developed a similar approach but I couldn't find a better solution than using a timer to clear the direction. It also doesn't make sense to change the direction while you have tracking touches and it starts as a horizontal.

mkoosej avatar Feb 13 '15 04:02 mkoosej

@mkoosej This solution is very simple and is clearly a hack for now as it completely disable diagonal scrolling. But in my application I don't have a use for it, so I'm fine with it. I guess it should check for a flag to see if scrolling is locked or not. I didn't dive much into Ionic code to really understand the whole logic, I can't say if should be done like this, but it works pretty well for me. Not sure why you will need to clear out direction... :)

pm-desjonqueresg avatar Feb 13 '15 23:02 pm-desjonqueresg

This bug has already been fixed? I have an ion-content with 5 ion-scroll (X direction only), so the user can't scroll down.

@bra1n's solution works, but I can't scroll down without accidentally scroll some ion-scroll to left.

BTW, @bra1n thanks for the temporary solution, you saved me =D

afsadilson avatar May 20 '15 21:05 afsadilson

@bra1n This solution doesn't work for android native scrolling. is there any solution for that?

manishiitg avatar May 30 '15 06:05 manishiitg

If using "ion-scroll" then just set its "Height" as per need and it its "direction" attribute as per convenience it will also work gre8.

ShindePrasad avatar Jul 01 '15 12:07 ShindePrasad

Is there any news on this issue ?

geekuillaume avatar Jul 30 '15 14:07 geekuillaume