Swipe through segment tabs - Ionic 3

狂风中的少年 提交于 2020-06-26 11:19:30

问题


The code below uses segments from ionic 3. docs show the use of ngSwitch, ngModel. but I would like to simply swipe on the segment and switch to another segment tab. How can I achieve this?

I am not interested in swiping the tabs at the top but by swiping on the content i would like to change the segment tab.

<ion-content padding>

  <div>
    <ion-segment [(ngModel)]="abc">
      <ion-segment-button value="Segment1">
        Segment Title
      </ion-segment-button>
      <ion-segment-button value="segment2">
        Segment Title
      </ion-segment-button>
    </ion-segment>
  </div>

  <div [ngSwitch]="abc">
    <ion-list *ngSwitchCase="'segment2'" class="list-fixed">
      <ion-item>
        <ion-thumbnail item-start>
          <img src="assets/imgs/1.jpg">
        </ion-thumbnail>
        <h2>List Item 1</h2>
        <p>List Item Subtitle</p>
        <button ion-button clear item-end>View</button>
      </ion-item>
    </ion-list>

    <ion-list *ngSwitchCase="'segment1'" class="list-fixed">
      <ion-item>
        <ion-thumbnail item-start>
          <img src="assets/imgs/3.png">
        </ion-thumbnail>
        <h2>List Item Title 1</h2>
        <p>Subheading</p>
        <button ion-button clear item-end>View</button>
      </ion-item>
    </ion-list>
  </div>

回答1:


My Solution was to Add :

.html file

//Add below code where you would like to detect the swipe from users input
// When user makes a swipe simply check and do the switch between Tabs.

(pan)='swipeEvent($event)' 

.ts file

pages: string = "pageA";

swipeEvent($e) {
    console.log($e.deltaX+", "+$e.deltaY);
    if($e.deltaX > 0){
      console.log("Swipe from Left to Right");
      this.pages = "pageB";
    }else{
      console.log("Swipe from Right to Left");
      this.pages = "pageA";
    }
}

Thanks to David's Comment



来源:https://stackoverflow.com/questions/46973693/swipe-through-segment-tabs-ionic-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!