Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Last active January 29, 2019 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ihsanberahim/b48f2bf659aafc55f629dac6c32dd52a to your computer and use it in GitHub Desktop.
Save ihsanberahim/b48f2bf659aafc55f629dac6c32dd52a to your computer and use it in GitHub Desktop.
IONIC3 - Trigger IonItemSliding using click event
<!--
Generated template for the EventListingPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<ion-title>My Page</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item-sliding #slidingItem *ngFor="...">
<ion-item #item (click)="openOption(slidingItem, item)">
Item
</ion-item>
<ion-item-options side="right" (click)="closeOption()">
<a [href]="..." icon-left clear ion-button item-right>
<ion-icon name="call"></ion-icon>
Open Url
</a>
</ion-item-options>
</ion-item-sliding>
</ion-list>
</ion-content>
import { Component } from '@angular/core';
import { ..., Item, ItemSliding } from 'ionic-angular';
/**
* Generated class for the EventListingPage page.
*
* See http://ionicframework.com/docs/components/#navigation for more info
* on Ionic pages and navigation.
*/
@IonicPage()
@Component({
...
})
export class MyPage {
...
activeItemSliding: ItemSliding = null;
constructor(...) {
...
}
ionViewDidLoad() {
...
}
...
openOption(itemSlide: ItemSliding, item: Item) {
console.log('opening item slide..');
if(this.activeItemSliding!==null) //use this if only one active sliding item allowed
this.closeOption();
this.activeItemSliding = itemSlide;
let swipeAmount = 194; //set your required swipe amount
itemSlide.startSliding(swipeAmount);
itemSlide.moveSliding(swipeAmount);
itemSlide.setElementClass('active-options-right', true);
itemSlide.setElementClass('active-swipe-right', true);
item.setElementStyle('transition', null);
item.setElementStyle('transform', 'translate3d(-'+swipeAmount+'px, 0px, 0px)');
}
closeOption() {
console.log('closing item slide..');
if(this.activeItemSliding) {
this.activeItemSliding.close();
this.activeItemSliding = null;
}
}
...
}
@heshaShawky
Copy link

please update this with ionic 4.0.0 now!

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment