Ion-item-sliding to automatically trigger a button

I was wondering if there is a way to automatically trigger the buttons when using the ion-item-sliding component?

For example, I have the following code:

 <ion-list>
    <ion-item-sliding *ngFor="let cnt of contacts">

      <ion-item (click)="openInvite(cnt)">
        <p>{{cnt.getFullName()}}</p>
      </ion-item>

      <ion-item-options side="left">
        <button favorite (click)="acceptInvite(cnt)">Accept</button>
      </ion-item-options>

      <ion-item-options side="right">
        <button danger (click)="dismissInvite(cnt)">Dismiss</button>
      </ion-item-options>

    </ion-item-sliding>
  </ion-list>

Could I trigger the acceptInvite(cnt) or dismissInvite(cnt) automatically when a user swipes the row to appropriate side?

I’m aware of the ionDrag event, and the getSlidingPercent() method, and that I could trigger a function if, for example, item.getSlidingPercent() > 1. However, that doesn’t handle the case if the user changed his mind and decided to slide the item back to position, if you know what I mean…

In essence, I could use the getSlidingPercent() method only if I could also deduct somehow if the user stopped the drag when the getSlidingPercent() > 1. So is there a way to do this?

2 Likes

Have you find out solution? What version of Ionic 2 do you use?

I belive there is a bug, since getSlidingPercent() returns infinity, not a real number. If it would return number, this could be easily done by executing function just after percent reaches >50 or so. (or I don’t know exact units used)