I’m teaching a course that includes an introduction to Ionic and I’m sure the students are going to ask me to explain the default HTML that is provided in home.page.html – and I can’t explain it.
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title>
Blank
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content [fullscreen]="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">Blank</ion-title>
</ion-toolbar>
</ion-header>
<div id="container">
<strong>Ready to create an app?</strong>
<p>Start with Ionic <a target="_blank" rel="noopener noreferrer" href="https://ionicframework.com/docs/components">UI Components</a></p>
</div>
</ion-content>
I’m hoping someone can enlighten me on why there is an ion-header
with translucent
set to true and then inside ion-content
, another ion-header
with fullscreen
set to true and the header’s collapse="condense"
.
Are both ion-headers really needed? If so, why?
Thanks!
1 Like
The two headers are there to have the ios large header design.
When on iOS, the second header will be displayed, and the first header will only show when the users start to scroll. This follows the iOS design guidelines.
2 Likes
Thank you, Mike. On #2, I didn’t think “code duplication” was much of a personal opinion, but maybe when the app is fully fleshed it won’t look as duplicated as it does in the starter template.
Hi @mhartington ,
This is somewhat related with the issue I am having. I have an instance of ion-header inside my main view in App.vue that also holds ion-menu, code looks like this:
<ion-header>
<ion-toolbar>
<ion-buttons slot="end">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title>{{ $router.currentRoute.value.name }}</ion-title>
</ion-toolbar>
</ion-header>
But I’m still forced to have ion-header on every single view, otherwise all the content goes behind the header, even if fullscreen is set to false. I’d like to avoid duplicating ion-header code if possible from my view components. Is this possible?
Thank you.
This is by design, so you can have a customized header per page.
It’s not really duplicating, as you change the header on each page, and the router animates the content of those headers in an out as routes change.
What you are trying to do is not possible and should not be attempted.