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

Frozen ion-range component

Open tcrespog opened this issue 10 years ago • 4 comments

Hi, I'm experiencing an issue while testing an Ionic 2 app in an Android 6 device/emulator.

In this sample application the problem can be reproduced: https://github.com/tcrespog/ion-range-issue

The problem happens when navigating to a page via navController.push as a result of clicking in a local notification. When the home page is loaded, the ion-range component present in it seems frozen, the slider keeps in the same place even though I try to move it. However, the view is updated accordingly if other kind of change is performed, like the one triggered when the "Increment" button is clicked.

The steps to reproduce are:

  1. Open the app.
  2. Click the "Schedule notification" button.
  3. Click the notification when it shows up, the "Page 2" is shown.
  4. Try to move the slider, note that the view is not updated.
  5. Click the "Increment counter" button, note that the view is updated this time including the move performed in the slider.

tcrespog avatar Nov 13 '16 17:11 tcrespog

@tcrespog I've found this bug as well and I believe the issue is that if the ion-range element is not visible at the beginning (issue with the component life cycle?) then the ion-range doesn't move.

This issue occurs, by the way, only on Android and not on the Chrome browser (ionic serve).

template:

<ion-header>
  <ion-navbar>
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <div text-right>
      <button ion-button clear (click)="toggleDistanceSlider()">
        <ion-icon name="pin"></ion-icon>
      </button>
    </div>
  </ion-navbar>
  <ion-item *ngIf="distanceSliderIsEnabled">
    <ion-range min="1" max="50" [(ngModel)]="distance" (ionChange)="changeDistance($event)">
      <ion-label range-left>1</ion-label>
      <ion-label range-right>50</ion-label>
    </ion-range>
  </ion-item>
</ion-header>
...

component:

@Component({
  selector:    'home',
  templateUrl: 'home.html'
})
export class HomePage implements OnInit {
  distanceSliderIsEnabled: boolean = false;
  distance:                number  = 25;
...

  toggleDistanceSlider() {
    this.distanceSliderIsEnabled = !this.distanceSliderIsEnabled;
  }

changeDistance(range) {
 console.log(`range, change, ratio: ${range.ratio}, value: ${range.value}`);
}

console output:

range, change, ratio: 0.4897959183673469, value: 25
range, change, ratio: 0.4897959183673469, value: 25
range, change, ratio: 0.4897959183673469, value: 25

gianpaj avatar Mar 14 '17 22:03 gianpaj

By the way the workaround is use to use [hidden] instead of *ngIf:

  <ion-item [hidden]="!distanceSliderIsEnabled">
    <ion-range min="1" max="50" [(ngModel)]="distance" (ionChange)="changeDistance($event)">
      <ion-label range-left>1</ion-label>
      <ion-label range-right>50</ion-label>
    </ion-range>

gianpaj avatar Mar 15 '17 15:03 gianpaj

I had this isue too, first it works very good, but then I added the ngIf statement, and the app seems like frozen untill I show a loading message for example, or switch the tabstrip. I tried with hidden, but I don't see any improvements.

henkverschoor1994 avatar Mar 29 '17 12:03 henkverschoor1994

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Thank you for using Ionic!

ionitron-bot[bot] avatar Mar 29 '18 13:03 ionitron-bot[bot]