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

bug: Android native scrolling strange behaviour #4022

Closed
CheetahDev opened this issue Jul 1, 2015 · 11 comments
Closed

bug: Android native scrolling strange behaviour #4022

CheetahDev opened this issue Jul 1, 2015 · 11 comments
Labels
needs: reply the issue needs a response from the user
Milestone

Comments

@CheetahDev
Copy link

Type: bug

Platform: android 4.4 webview

Hi,

I've been using Ionic' native scrolling since it has been released, but I disabled it in the last version due to #3727.
I saw the 1.0.1 update yesterday and I tried it as soon as I arrived at work. I re-enabled native scrolling and... boom... huge bug/strange behaviour.

Sometimes scroll is working, sometimes not (depending on the touched element, etc.).

Easiest way to reproduce:

  1. ionic start whatever sidemenu
  2. cd whatever
  3. ionic platform add android
  4. Edit playlists.html as follow:
<ion-view view-title="Playlists">
  <ion-content>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
    <div class="card">
      <div class="item item-text-wrap">
        This is a basic Card which contains an item that has wrapping text.
      </div>
    </div>
  </ion-content>
</ion-view>
  1. Edit app.js (replace ".config" line) as follow:
.config(function($ionicConfigProvider, $stateProvider, $urlRouterProvider) {

  if(ionic.Platform.isAndroid()) {
    $ionicConfigProvider.scrolling.jsScrolling(false);
  }
  1. ionic run android

Infos:

  • LG G3
  • Stock Android 4.4.2

J.

@CheetahDev CheetahDev changed the title Android native scrolling strange behaviour [ionic 1.0.1] bug: Android native scrolling strange behaviour Jul 1, 2015
@jskrzypek
Copy link

@CheetahDev, this might also partly be coming from the same problem as what we're seeing in ios in #4008.
The fix for it would be to add the following code to your app in order to override the wonky drag handler. Can you try it out and let me know what happens?

.run(function() {
    ionic.Gestures.gestures.Drag.handler = function dragGesture(ev, inst) {
        if(ev.srcEvent.type == 'touchstart' || ev.srcEvent.type == 'touchend') {
            this.preventedFirstMove = false;

        } else if(!this.preventedFirstMove && ev.srcEvent.type == 'touchmove') {
            // Prevent gestures that are not intended for this event handler from firing subsequent times
            if(inst.options.prevent_default_directions.length > 0 && inst.options.prevent_default_directions.indexOf(ev.direction) != -1) {
                ev.srcEvent.preventDefault();
            }
            this.preventedFirstMove = true;
        }

        // current gesture isnt drag, but dragged is true
        // this means an other gesture is busy. now call dragend
        if(ionic.Gestures.detection.current.name != this.name && this.triggered) {
            inst.trigger(this.name + 'end', ev);
            this.triggered = false;
            return;
        }

        // max touches
        if(inst.options.drag_max_touches > 0 &&
            ev.touches.length > inst.options.drag_max_touches) {
            return;
        }

        switch(ev.eventType) {
            case ionic.Gestures.EVENT_START:
                this.triggered = false;
                break;

            case ionic.Gestures.EVENT_MOVE:
                // when the distance we moved is too small we skip this gesture
                // or we can be already in dragging
                if(ev.distance < inst.options.drag_min_distance &&
                    ionic.Gestures.detection.current.name != this.name) {
                    return;
                }

                // we are dragging!
                if(ionic.Gestures.detection.current.name != this.name) {
                    ionic.Gestures.detection.current.name = this.name;
                    if(inst.options.correct_for_drag_min_distance) {
                        // When a drag is triggered, set the event center to drag_min_distance pixels from the original event center.
                        // Without this correction, the dragged distance would jumpstart at drag_min_distance pixels instead of at 0.
                        // It might be useful to save the original start point somewhere
                        var factor = Math.abs(inst.options.drag_min_distance / ev.distance);
                        ionic.Gestures.detection.current.startEvent.center.pageX += ev.deltaX * factor;
                        ionic.Gestures.detection.current.startEvent.center.pageY += ev.deltaY * factor;

                        // recalculate event data using new start point
                        ev = ionic.Gestures.detection.extendEventData(ev);
                    }
                }

                // lock drag to axis?
                if(ionic.Gestures.detection.current.lastEvent.drag_locked_to_axis || (inst.options.drag_lock_to_axis && inst.options.drag_lock_min_distance <= ev.distance)) {
                    ev.drag_locked_to_axis = true;
                }
                var last_direction = ionic.Gestures.detection.current.lastEvent.direction;
                if(ev.drag_locked_to_axis && last_direction !== ev.direction) {
                    // keep direction on the axis that the drag gesture started on
                    if(ionic.Gestures.utils.isVertical(last_direction)) {
                        ev.direction = (ev.deltaY < 0) ? ionic.Gestures.DIRECTION_UP : ionic.Gestures.DIRECTION_DOWN;
                    } else {
                        ev.direction = (ev.deltaX < 0) ? ionic.Gestures.DIRECTION_LEFT : ionic.Gestures.DIRECTION_RIGHT;
                    }
                }

                // first time, trigger dragstart event
                if(!this.triggered) {
                    inst.trigger(this.name + 'start', ev);
                    this.triggered = true;
                }

                // trigger normal event
                inst.trigger(this.name, ev);

                // direction event, like dragdown
                inst.trigger(this.name + ev.direction, ev);

                // block the browser events
                if((inst.options.drag_block_vertical && ionic.Gestures.utils.isVertical(ev.direction)) ||
                    (inst.options.drag_block_horizontal && !ionic.Gestures.utils.isVertical(ev.direction))) {
                    ev.preventDefault();
                }
                break;

            case ionic.Gestures.EVENT_END:
                // trigger dragend
                if(this.triggered) {
                    inst.trigger(this.name + 'end', ev);
                }

                this.triggered = false;
                break;
        }
    };
})

@CheetahDev
Copy link
Author

@jskrzypek your fix seems to work well! Waiting for a response from Ionic' team. Sad to see that native scrolling doesn't work properly in two consecutive releases. 😞

@jskrzypek
Copy link

Awesome! Should we merge this issue with #4008?

@mhartington
Copy link
Contributor

Moving this over to #4008

@krlwlfrt
Copy link

krlwlfrt commented Jul 9, 2015

@jskrzypek, your code fixed it for me on android 4.4. but with the side effect that I can now scroll vertical lists a few pixels left and right.

@mlynch
Copy link
Contributor

mlynch commented Dec 24, 2015

Review revert fix in #3695 for 1.2.2

@mlynch mlynch reopened this Dec 24, 2015
@mlynch mlynch added this to the 1.2.2 milestone Dec 24, 2015
@mlynch
Copy link
Contributor

mlynch commented Dec 29, 2015

This appears to be an issue with the side menu content area specifically. The drag handler on the side menu interacts with the content touch events

@mlynch mlynch closed this as completed in d3d2c14 Dec 29, 2015
@mlynch
Copy link
Contributor

mlynch commented Dec 29, 2015

Fixed. Will be out in 1.2.2

@mlynch
Copy link
Contributor

mlynch commented Dec 31, 2015

Reopening, need a slightly different approach to ensure no issues with iOS

@mlynch mlynch reopened this Dec 31, 2015
@mlynch mlynch modified the milestones: 1.2.3, 1.2.2 Dec 31, 2015
@danbucholtz
Copy link
Contributor

Hi @CheetahDev,

Are you still seeing an issue here? What am I supposed to be seeing on my device when I follow your steps? Everything seems fine on my device. Is there a particular action I should be taking?

Please let me know.

Thanks,
Dan

@danbucholtz danbucholtz added the needs: reply the issue needs a response from the user label May 6, 2016
@jgw96
Copy link
Contributor

jgw96 commented May 11, 2016

Hello all! As it seems it has been a while since there was any activity on this issue i will be closing it for now. Feel free to comment if you are still running into this issue. Thanks for using Ionic!

@jgw96 jgw96 closed this as completed May 11, 2016
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: reply the issue needs a response from the user
Projects
None yet
Development

No branches or pull requests

8 participants