ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.09k stars 13.51k forks source link

ionic 2 beta.11 ion-silides options, still present in Ionic 2 RC4 #7595

Closed betaengine closed 7 years ago

betaengine commented 8 years ago

open this page,First show the first page, and then jump to the second page But I set second pages for the initial,beta.10 is Available


version: 2.0.0-beta.11

<ion-slides [options]="opts">
      <ion-slide>
    <h1>Slide 1</h1>
  </ion-slide>
  <ion-slide>
    <h1>Slide 2</h1>
  </ion-slide>
  <ion-slide>
    <h1>Slide 3</h1>
  </ion-slide>
</ion-slides>

export class test implements OnInit{
opts:any;
    ngOnInit() {
this.opts = {initialSlide: 2, pager: true}
}

}
jgw96 commented 8 years ago

Hello, thanks for opening an issue with us! Sorry, but i'm not understanding the issue fully. Would you mind creating a repo that i can use to test this issue? Thanks for using Ionic!

betaengine commented 8 years ago

@jgw96

-------------------test.html----------------------------

<ion-content>
  <div>
    <ion-slides [options]="opts">
      <ion-slide *ngFor="let test of tests">{{test}}</ion-slide>
    </ion-slides>
  </div>
</ion-content>

-------------------test.ts----------------------------

@Component({
    templateUrl: 'build/pages/test/test.html',
})
export class TestPage implements OnInit{
    tests = [1,2,3];
    opts: any;
    constructor() {}
    ngOnInit() {
            this.opts = {initialSlide: 1}
    }

}

I have set {initialSlide: 1}.The initial index of second pages, but in version beta. 11 can see first display the first page, and then automatically jump to page second.In version beta.10,show second pages at once.

szerner commented 8 years ago

I have that same issue with the { initialSlide = ...} option. After the page with the slides has loaded, you can see (for a short time) the first of all slides and then the desired 'initialSlide'.

I tried to work around that issue and implemented a slider.slideTo(initialSlide, 0, false) statement within the various page cycle events (ionViewLoaded, ionViewWillEnter, ionViewDidEnter). Only within the ionViewDidEnterevent the slideTo-statement works as expected and jumps to the 'initialSlide', but with the same tiny lag after showing the first of all slides. So no real workaround.

petermm commented 8 years ago

still flashes first slide in rc0, before showing initialSlide: x

axelauvinen commented 8 years ago

There are few bugs with initialSlide option:

1) Flickering of the view 2) After init with initialSlide option, you can't call getActiveIndex(), error: ORIGINAL EXCEPTION: Cannot read property 'activeIndex' of undefined.

I believe this is caused because the slide is changing to another one and ionDidChange is called

    this.horizontalSliderOptions = {
      loop: false,
      pager: false,
      direction: "horizontal",
      initialSlide: 1
    }

  (ionDidChange)="onSlideChanged()"

  onSlideChanged(e) {
    let activeHorizontal = this.horizontalSlider.getActiveIndex()
 }
martin-eberle commented 8 years ago

This bug is still present in Ionic 2 RC2. Maybe you can change the title of the issue?

martin-eberle commented 7 years ago

And also in RC3 :-/

AleFons commented 7 years ago

Still present on RC4; the shown slider is always the default at index 0 and then switches to whatever was set as initialSlide.

I have mentioned on another issue ( which I believe to be a duplicate of this one, #9138 ) and I've provided a repository to reproduce the issue that can be found here.

ericdude4 commented 7 years ago

Has anyone tested this issue on RC5 ? I used a workaround on RC4 and it works but I'd rather have a stable solution...

AleFons commented 7 years ago

@ericdude4 I'm using RC5 and while there are some slight differences in the implementation of ion-slides in it, it's working as intended. I believe the issue is now solved.

brandyscarney commented 7 years ago

Thanks @AleFons. I am going to close this then, but please let me know if anyone sees the problem with RC6 and I will reopen. :)

miguelmchavez commented 7 years ago

Hey @ericdude4 can you post some example?

ericdude4 commented 7 years ago

@miguelmchavez would you like the solution that I found previously? Recently I have updated to Ionic 2 stable release and the issue was resolved, however, I would be more that happy to explain my fix.

miguelmchavez commented 7 years ago

yes @ericdude4 , i like the solution that you found previously! Please.

ericdude4 commented 7 years ago

@miguelmchavez This was my solution on RC4, so if you are using an older one, the line where the code is may be different:

1) open node_modules > ionic-angular > components > slide > slide.js

2) locate the following (approx. line 262)

setTimeout(function () {
     var swiper = new Swiper(_this.getNativeElement().children[0], options);
     _this.slider = swiper;
 }, 300);

3) replace this code with:

setTimeout(function () {
     var swiper = new Swiper(_this.getNativeElement().children[0], options);
     _this.slider = swiper;

 });
miguelmchavez commented 7 years ago

@ericdude4 Great, can you post your final typescript page?

ericdude4 commented 7 years ago

@miguelmchavez the old typescript page you would have had with the initialSlide issue should work now. It will no longer flash the first slide before moving to the initialSlide.

ionitron-bot[bot] commented 6 years ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. 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.