Skip to content

ionic2 ion-slides don't support well prepending to dynamic list of slides #6678

@antoineol

Description

@antoineol

Short description of the problem:

The issue is noticed when prepending new slides on willChange/didChange events. pushing to the end is okay, but prepending also shifts the displayed slide. When sliding to the left, it skips a slide and goes to the one after.

What behavior are you expecting?

When prepending a slide dynamically, it would have no impact on the slide currently displayed, and the one we are sliding to. Changing of slide differently than normal swipe would be the result of an explicit call to methods like slideTo().

Steps to reproduce:

  1. on a new Ionic 2 app, add an ion-slides, and a list of ion-slide with ngFor
  2. Add an event listener like willChange to capture a slide change by the user (similar effect with didChange)
  3. when sliding to the left, prepend a new slide to the list of slides
  4. the user goes 2 slides to the left instead of 1.
  5. the same thing when sliding to the right has no side-effect.

Template:

<ion-slides (willChange)="updateNumbers($event)" [options]="{initialSlide: 3}">
    <ion-slide *ngFor="let n of numbers">
        <h2>{{n}}</h2>
    </ion-slide>
</ion-slides>

In the component:

numbers = [-3, -2, -1, 0, 1];

updateNumbers(swiper:any) {
    let backward = swiper.swipeDirection === 'prev';
    if (backward) {

        // KO: it is shifting the displayed slide as well
        this.numbers.unshift(this.numbers[0] - 1);

    } else {
        // Pushing to the end is okay, no noticeable side-effect
        this.numbers.push(this.numbers[this.numbers.length - 1] + 1);
    }
}

Which Ionic Version? 2.0.0-beta.7

Plunker that shows an example of your issue

http://plnkr.co/edit/Lso4eq2d8z9KyulRAUsP?p=preview

Run ionic info from terminal/cmd prompt: (paste output below)

Cordova CLI: 6.2.0
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.7
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
OS: Windows 7 SP1
Node Version: v6.2.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions