I have a list of 15 things in my app.
I can click on each and a DetailPage opens with the data of the clicked item.
Now I want to be able to swipe between these DetailPages - so that when I am on item 7 swiping left will show me item 8, and swiping right will show me item 6. How do I do that?
In the best case this swiping should seemlessly show the next page while swiping already, like if it was a “carousel” or “ribbon” of pages.
Ok, so instead of navigating to DetailPage with a parameter of item (which contains the one clicked item) I would navigate to SliderPage with a parameter of items (which contains all the items in the list) and selected (which is used to go to the correct start slide).
swipeEvent(e) {
if (e.direction == 2) {
this.navCtrl.push('Item2');
}
}
Swipe right to pop() is the default behavior but you can just set a second swipe event to push or setroot to a previous page if depending on how you want the nav-stack to look.
Thanks, good point. But this will probably not be “animated” or dynamic as in a slider? Will be more like clicking a button to navigate to the other page after swiping finished, right?
Yeah the push() event will act similar to a button, the swipe is performed and only at the end does the next page slide in via animation. The pop() event actually dynamically slides over the current top of the nav-stack though since that’s a native feature included in the framework.
Maybe you could specify another or a custom animation to the navCtrl.push and therefore simulate a slider effect while switching pages? In NavOption there is a parameter animation if I reckon correctly
Otherwise yes, you could refactor your code and use a slider. To do so, maybe the most straight forward way is to change your pages to components and use then them inside the slider (pay attention to the memory on older devices if you’ve got multiple complex pages…)