I'm using Ionic with Angular to develop an App. I intruduced dynamic theming adding two .scss
files into my theme
folder. I've got app.scss
where I define only the layout of my components without colors. All colors are in the theme-*.scss
files. To apply a theme I use a class over <ion-nav>
element into my app.html
. Something like this:
<div [class]="selectedTheme">
<ion-nav [root]="rootPage" ></ion-nav>
</div>
The selectedTheme
is a string that assume the name of my theme so when I change it with an event such (click)
or (ionChange)
I can change the colours of my app.
A file theme-*.scss
has the following structure:
.dark-theme {
ion-header {
//colors
}
ion-content {
//colors
}
}
This way works like a charm, but I've got a little issue I want to avoid. I set the default theme in constructor
of app-components.ts
file, before the famous platform.ready().then(...)
that hides the splashscreen. My issue is that when the splashscreen hides I can see my app with its layout but without the correct theme applied. I see all white backgrounds and all black colors for a small amount of time, then the default theme is applied. I'm importing my custom themes in variables.scss
, I tried to import them also in app.scss
but the behaviour remain the same. It seem that before import the themes it applies the layout in app.scss
and only after it applies the imported theme with all its colours. Someone has already see something like this?