When navigating to a new screen by calling NavController.navigateForward(\'/url\')
you get a free native animation which slides the screen in to view. This work
The reason why that's happening is because Ionic expects the ion-title
to be in a certain place for it to be animated. You can see that by inspecting the the source code of the iOS page transition.
As you can see here Ionic gets the entering ion-toolbar
like this:
const enteringToolBarEls = enteringEl.querySelectorAll(':scope > ion-header > ion-toolbar');
And here it gets the ion-title
like this:
enteringTitle.addElement(enteringToolBarEl.querySelector('ion-title'));
That won't work since the structure of the HTML code will be different if you use a custom component in your ion-header
:
ion-header > your-component > ion-toolbar
It's recommended not to use a custom component in the ion-header
because Ionic expects it to be in a specific way in order to animate it properly.
That being said, if you really need to use a custom component there, you can crate your own custom page transition like this:
myAwesomeTransitionAnimation.ts
with the content of the source code of the iOS page transition.app.module.ts
file to use that transition instead of the default:imports: [
...
IonicModule.forRoot({
navAnimation: myAwesomeTransitionAnimation,
}),
],
Please keep in mind that doing so would override the default "animation" of all ion-nav
and ion-router-outlet
across the whole application.
If you just want to override it for iOS (using the default for Android), please take a look at this comment:
let ionic = [
IonicModule.forRoot()
];
const platform = new Platform();
if (platform.is('ios')) {
ionic = [
IonicModule.forRoot({
navAnimation: myAwesomeTransitionAnimation,
})
]
}
And in module imports:
imports: [ ...ionic, ]