Comments (15)
@aeharding Yes! This is almost exactly our scenario. Thanks for posting! Love the timing :D
from ionic-framework.
We do have a private swipeHandler
API that we use in our routing integrations. This lets us know when to call router.back()
or not:
Your mileage may vary here, but that might be a possible workaround for now.
from ionic-framework.
Thanks for the report. Does using ionViewDidLeave
work for your use case? Your use case describes needing to roll back an action that happens on ionViewWillLeave
. However, if you perform that action in ionViewDidLeave
you remove the need to ever roll the action back because the user confirmed their navigation away from the page.
from ionic-framework.
Hey @liamdebeasi, unfortunately as stated in the description, this is not possible. It technically works but creates a situation for us where the user can momentarily see & interact with elements that need to be gone by the time the animation is started, but need to be restored when he gesture is aborted. We use Angular content portals to project content dynamically and it needs to be in the right place at the right time.
from ionic-framework.
Do you have an example of the elements that you need removed in your application?
from ionic-framework.
Huh, weird timing! I was also just experiencing trouble with the lack of published events for this scenario. Below is my use case:
- In my case, I have a singleton
<video>
element that I portal around the application so that playback is not interrupted. I use react-reverse-portal to accomplish this. - Observe video is pulled/pushed from pages as expected, listening to
ionViewWillEnter
event to "pull" the<video>
element into the correct place. - Observe at the end of the video, instead of fully swiping back, I stop swiping, and the page transition never completes.
- There is no event to catch this case.
willEnter
/didEnter
/willLeave
/didLeave
do not get called. I don't know if this is a bug (perhapswillEnter
anddidEnter
should be re-called if you don't complete the swipe back?), or as per OP, perhaps newionViewDidNotEnter
andionViewDidNotLeave
events should be published. Either of these solutions would work for my case.
If it helps, I would be happy to create a reproduction. But essentially, there are no Ionic events published to detect the situation where a swipe back does not fully complete.
Kapture.2024-02-04.at.14.49.52.mp4
from ionic-framework.
Would an IntersectionObserver work for the video use case? Unless the video sticks to the top of the screen as you scroll, I imagine you would want to pause the video when the video scrolls out of the viewport as well. Using IntersectionObserver would let you cover both cases.
from ionic-framework.
Would an IntersectionObserver work for the video use case? Unless the video sticks to the top of the screen as you scroll, I imagine you would want to pause the video when the video scrolls out of the viewport as well. Using IntersectionObserver would let you cover both cases.
I already use Intersection Observer for your mentioned case of play/pause while scrolling feed, but it is not well suited for detecting page navigations in my testing.
- I want to change video element location before the page animation starts to avoid stutters.
- Furthermore using an Intersection Observer for that introduces other unavoidable edge cases, due to the fact that you cannot discern the difference between page navigation intersections and feed scroll intersections. For example say trigger point = 50% or whatever. If you change pages while the video on the page you're navigating to is 40% scrolled off the feed, it does not fire. Unless you set the intersection observer to fire when 0.00001% of the element is visible, which has the same problem as this original issue (won't fire if you start swiping back, then don't fully swipe back.)
There's a few other DevEx reasons (there is a lot of extra code, and I need to use 2x the intersection observers due to reverse portals), but they're not blockers like the above.
Side note, on https://ionicframework.com/docs/angular/lifecycle it says,
ionViewWillLeave
- Can be used for cleanup, like unsubscribing from observables.
But, I don't think this is a good advice due to the original issue. If you were to cleanup observables on ionViewWillLeave
but then you don't actually complete the swipe back, your application on that page would be in a broken state, right?
from ionic-framework.
Furthermore using an Intersection Observer for that introduces other unavoidable edge cases, due to the fact that you cannot discern the difference between page navigation intersections and feed scroll intersections. For example say trigger point = 50% or whatever. If you change pages while the video on the page you're navigating to is 40% scrolled off the feed, it does not fire. Unless you set the intersection observer to fire when 0.00001% of the element is visible, which has the same problem as this original issue (won't fire if you start swiping back, then don't fully swipe back.)
Do you have an example of this issue that I can look at?
Native iOS doesn't have a standard way of detecting when a swipe gesture is cancelled, so it's possible there's another approach here that would solve the problem.
from ionic-framework.
Do you have an example of this issue that I can look at?
I can get you a repro example if it would help, but it may take a bit to set up. :)
Native iOS doesn't have a standard way of detecting when a swipe gesture is cancelled, so it's possible there's another approach here that would solve the problem.
This is interesting that you mentioned, so I decided to look and see what native iOS does. It turns out that native iOS re-triggers lifecycle events when you do not complete a swipe back. Please see the following Youtube video (linking to around 9:30):
https://youtu.be/wLS26PfQeAs?si=ZBBQ_irI444i24gm&t=562
As you can see, when he lifts his finger (and swipe back does not complete), the following lifecycle events in yellow are triggered. This is different than Ionic, which does not trigger any lifecycle events when you cancel the swipe back.
from ionic-framework.
Ah that's interesting. If the will/did events fired when cancelling the swipe gesture would that make it easier to implement the pattern you described above?
from ionic-framework.
Ah that's interesting. If the will/did events fired when cancelling the swipe gesture would that make it easier to implement the pattern you described above?
I can't speak for @lincolnthree, but firing those extra will/did events would fully address my edge case!
from ionic-framework.
Ah that's interesting. If the will/did events fired when cancelling the swipe gesture would that make it easier to implement the pattern you described above?
Yes 100%. Though it would be a potentially breaking change for many apps rather than a new feature. You'd have to review all of your existing event handlers and make sure nothing bad happens if they are called multiple times. That's why I opted to suggest the introduction of a new API rather than overload the existing one, but I can see it going both ways if you want to keep things minimal. It just means apps will break.
Additionally, while it would solve this specific case, there is some nuance to using separate events. E.g. the nature of the event is unknown if you call the same event handlers. You could do some complex state checking I guess, to determine what situation the DidEnter
handler is being called in (e.g.: first time means page loaded, second+ time means page leave started and aborted, but only if WillLeave
was called first).
from ionic-framework.
Thanks! There's some research we need to do as to what the best way of implementing this is. At the very least, the uses cases described here should be achievable within Ionic Framework so we should try and find a resolution.
from ionic-framework.
Thanks! There's some research we need to do as to what the best way of implementing this is. At the very least, the uses cases described here should be achievable within Ionic Framework so we should try and find a resolution.
Awesome! Glad we could help, and looking forward to doing even more fancy things with Ionic :D Do you know of any "secret" hooks / hacks we could tie into in the mean time? Anything we could overload or override?
from ionic-framework.
Related Issues (20)
- bug: ion-item slot end is shifted to the left HOT 5
- bug: item-sliding removes its border when there is an item in the list after it in an inset list
- bug: Refresher Content's icon on IOS won't show up properly unless the refresh's processing
- bug: datetime should clamp within the min/max when the min or max changes HOT 1
- bug: ion-item with ion-input firing 2 click events on iPhoneX HOT 1
- bug: IonModal focus trap does not allow other components to overlay HOT 2
- feat: localization calendar (`ion-datetime`) HOT 1
- bug: test
- feat: test
- feat: Ability to reorder horizontally in `ion-reorder ` HOT 3
- Ionic 7 Angular Standalone Component (Sidebar Menu Toggle not working in android device) HOT 2
- bug: IonInput has no placeholder text when type="time" HOT 4
- bug: Alert button handlers are executed outside the angular zone in certain cases HOT 3
- bug: input blurring utility causes non input and textarea elements to be blurred HOT 3
- bug: IonAert button get empty value from input HOT 3
- bug: ion-textarea Text Selection Not Persisting on Safari HOT 4
- bug: ion-toggle focus-visible doesnt work HOT 4
- IOS 17.4 will stop supporting PWA for Europe HOT 1
- feat: Webhook test - ignore HOT 1
- bug: item-sliding animation jumps when using multi touch HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ionic-framework.