0

Is there a slide event that triggers just before the start of a slide transition?
I’ve already tried ionSlideNextStart and ionSlideWillChange but none of them work the way I need it.

What I want is to lock the swipe based on a condition. For example, I want to lock the swipe if the image is zoomed in and unlock it if the image is zoomed out.

alecsam
  • 566
  • 3
  • 10
  • IMO, you are looking at the wrong event. If you want to lock slide on the event such as zoom-in on an image, lock the slide in that event and unlock in the restore... trying to evaluate the state and apply lock on slides seems like heading down the path of confusion – Aragorn Nov 06 '18 at 14:59

2 Answers2

0

As per my comment, better way IMO to do this is to lock the slide on proper events. Such as in your zoom-in example, lock the slide when zoom-in occurs and unlock on restore of the image.

However, is you want to head down the path of locking on the start of slide, using ionSlideNextStart or ionSlideWillChange, you might be able to do it in two steps.

On the event, you'll have to go back to the previous slide, because the slide event has started and I'm not sure if there's a way to stop that: Pseudo code:

slide.slider.slideTo(indexOfPrevSlide, 2000)

And then, apply the lock using shouldLockSwipeToNext and shouldLockSwipeToPrevg

Aragorn
  • 5,021
  • 5
  • 26
  • 37
0

Thank you for your idea. I chose the first option. I thought myself about it but I'm new to Ionic and I'm still learning.
The zooming functionality is in fact a directive (zoom-pan) and it has not occurred to me that it is possible to access the component from the directive.

<ion-slides zoom-pan>
    <ion-slide *ngFor="let page of pages;">
        [...]
    </ion-slide>
</ion-slides>

But, I did some more research and thanks to this I injected ViewContainerRef in the constructor of the directive.
With this.hostComponent = this.viewContainerRef["_data"].componentView.component I have access to the slides and I have locked/unlocked the swipe when zoom-in/zoom-out occurs.

alecsam
  • 566
  • 3
  • 10