I am currently facing an issue where the swipe to go back functionality flickers/flashes back to the “from page” (home page in this example) after the gesture before finally going back to the “to page” (restaurant page in this example). This is happening intermittently, and usually doesn’t happen if you swipe back slowly (not sure if thats just a coincidence). I’ve included some code, my project info, and a video of the broken animation. Any ideas why this is happening?
home.page.html Router Link <a routerLink="/restaurant/abc/123"><ion-button color="primary">Valid Restaurant</ion-button></a>
There are 2 issues I can see in the video provided:
There is jank when the page shown in the video is entering. I am assuming you are performing some work in ionViewWillEnter that causes your template to re-render. This triggers a bug in WebKit. The good news is that the issue was fixed by Apple and should be released in an upcoming version of iOS. The workaround for now is to move the logic to ionViewDidEnter (or avoid it altogether).
Swiping back appears to happen twice. What’s happening here is you are triggering the swipe to go back gesture that is built into Safari in addition to the swipe to go back gesture that is built into Ionic. The end result is you “swipe to go back” using the Safari gesture, and then Ionic’s gesture kicks in which results in a visible flicker. There is an open issue here: bug: ios, cannot disable Safari swipe to go back when running as PWA · Issue #22299 · ionic-team/ionic-framework · GitHub. While this is not a bug in Ionic, there is no good workaround at the moment other than disabling Ionic’s swipe to go back gesture. We have proposed an addition to the CSS pointer-events API to help account for this, but there has not been any movement on that front yet.
Ironically, I didn’t notice the first issue until I was recording the video for this post and was planning on digging into it after seeing it. Good news that Apple is planning to fix it…however my logic is currently in ionViewDidEnter. I built a global drawer component and I am reading one of the values from an injected service and setting the state of the drawer based on the value…do you see any reason why that would be causing an issue in ionViewDidEnter?
Does this mean if I disable Ionic’s swipe to go back, it won’t work at all? Or will only work in Safari because Safari’s functionality will still exist? Either way I’ll keep an eye out on that GitHub issue, thanks for sharing that.
I actually removed all of the code from ionViewDidEnter (and the lifecycle event altogether), and I am still seeing the issue. I do have a few things happening in my ngOnInit, including an async func to pull data from Firebase. Could that be the problem?
Is there a way to fix that issue? What would be the “best practice” to handle those network calls/set up subscriptions if doing them in ngOnInit is causing the flicker/pause effect when loading the view?
Something to note is that it only happens the 2nd time after navigating to the view when the view already has data (assume its cached?). When it loads the first time theres no animation issue, the page is just blank until the data loads.
The best way to avoid this issue is to ensure that the view does not get updated during the page animation. You could do this by caching or pre-fetching data prior to the animation starting.