Issue with Dynamic Theming in Ionic Framework

Currently, I am using Ionic in combination with Angular to create an App. I have introduced dynamic theming by adding two .scss files into my theme folder. In my app.scss file, I define the layout of components without colors, while all color styles are stored in the theme-*.scss files. To implement a theme change, I utilize a class on the ion-nav element within my app.html file, as shown below:

<div [class]="selectedTheme">
  <ion-nav [root]="rootPage" ></ion-nav>
</div>

The selectedTheme variable is a string that corresponds to the name of the theme. By triggering an event like (click) or (ionChange), I can seamlessly switch the color scheme of my app.

A typical theme-*.scss file has the structure depicted below:

.dark-theme {
  ion-header {
    //colors
  }
  ion-content {
    //colors
  }
}

This method works effectively, but there is a minor issue that I would like to resolve. I set the default theme in the constructor function of app-components.ts prior to the execution of platform.ready().then(...) function, which conceals the splashscreen. The problem arises when the splashscreen disappears and for a brief moment, I observe my app's layout with white backgrounds and black colors before the correct theme is applied. Despite attempting to import the custom themes in variables.scss and app.scss, the behavior remains consistent. It appears that the layout defined in app.scss is being applied first, followed by the imported theme along with its colors. Has anyone encountered a similar situation?

Answer №1

It seems like the issue you're facing is related to the timing of the first paint attribute in browsers. The webview that ionic operates within can be thought of as a type of browser, hence why the same issue arises.

For more information on why first paint occurs before DOMContentLoaded, check out this helpful explanation: why-first-paint-is-happening-before-domcontentloaded.

This resource discusses how the first paint can actually begin before the DOM is completely loaded.

The following excerpt from the link perfectly describes the phenomenon you're encountering within your app:

For example, the parser may not be able to emit Element nodes until all attributes have been processed, but it can still emit the node while continuing to process its child tree. As a result, the renderer may render the node without its children or with incomplete styles, leading to potential reflows later on when additional style sheets are inserted by JavaScript or when child nodes yet to be inserted impact rendering.

In essence, there's no guarantee that the DOM will be fully loaded before painting begins. A practical solution would be to delay hiding your splash screen until a little later in the process.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Delete auto-generated list using handlebars JS

I have successfully created a dynamic list using Handlebars.js and its template. However, I am now facing confusion on how to remove or delete items from the list using a function or specific code. As I am new to Handlebars, I would appreciate any help. ...

"Troubleshooting issue in Django 1.6.2 where CSS styles are not being applied to

I am encountering an issue with this code and would greatly appreciate some assistance. The base.html file contains a {% block content %}{% endblock %}. I have created a Signup.html file structured like this: {%extends 'base.html'%} {% block co ...

The creation script in create-react-app automatically includes an external import in the CSS file

I am facing an issue with my create-react-app. Everything works perfectly fine when I run it using npm run start. However, after building it with npm run build, some CSS appears to be missing from the app. Upon investigation, I discovered that the file bu ...

Using getters in a template can activate the Angular change detection cycle

When using getters inside templates, it seems that Angular's change detection can get stuck in a loop with the getter being called multiple times. Despite researching similar issues, I have not been able to find a clear solution. Background info: I ...

Using placeholders with inputs in an Angular2 table generated by ngFor

I have an array public example = [['hallo', 'fruit', 'rose'], ['apple','book']] Currently, I am working on creating a table of inputs. The values in this table depend on the specific part that I am usin ...

Dynamic content that adjusts based on a multi-row element

I'm currently designing a webpage layout with a calendar on one side and a series of information-divs on the other. In desktop view, I want the calendar to span three rows like so: CAL DIV1 CAL DIV2 CAL DIV3 Right now, I am achieving this using neste ...

Looking to recreate this style of table using HTML and CSS?

https://i.sstatic.net/nDrxq.png Trying to replicate the layout from this image for my blog, but struggling with the source code. Any suggestions on how to achieve a similar design without using divs within table rows? Looking for a cleaner solution. ...

Issue with displaying ChartJS on Django HTML page

I am attempting to create a horizontal bar chart in HTML, but unfortunately, it is not displaying correctly. I have sent 2 variables from views.py, which are {{top5StockCode}} and {{top5TotalSales}}. The values of {{top5StockCode}} that were sent from vi ...

Resolving route data in Angular 2 and above

When retrieving data from an API in an Angular route resolver, I encountered a problem where if there was an error due to a stale token, I needed to refresh the token and then retry the API call. Below is the code snippet illustrating this scenario: impor ...

What steps can be taken to eliminate the 404 error when refreshing an Angular 8 Single Page Application (SPA) without using

In my single page application project, I am utilizing Angular 8. Upon uploading my published code to the IIS server without using hash(#) in routing, I encounter a 404 error when attempting to refresh the page. Can anyone provide assistance on how to res ...

Troubleshooting problem with CSS background image

I'm looking to make my webpage more dynamic and interactive. One issue I have is that the background image of the body element stretches when new elements are added, which is not the desired behavior. Any suggestions on how I can fix this? <styl ...

The window fails to retain the scroll position when overflow is enabled

Whenever I click on a specific div, I use jQuery to dynamically apply overflow: hidden to the html and body. $(".mydiv").on("click", function() { $("html, body").css("overflow", "hidden"); }); However, this action causes the window to scroll to the to ...

What could be causing my project to install an erroneous Angular version?

It appears that my project is not utilizing the latest Angular code, but I am unsure of the reason behind this. I have checked my package.json file and found the following dependencies: "devDependencies": { "@angular/common": "2.0.0", "@angular ...

Creating a vertical scrolling marquee to showcase a list in React - step by step guide

Trying to create a marquee effect that displays a list of items in a vertical auto-scroll. After reaching the end of the list, I want it to loop back to the beginning seamlessly for continuous animation. The code snippet below shows my progress so far - a ...

Clicking on the icon reveals the current date

I need some help with the input field that displays the calendar date. Currently, I can only click on the input field to show the calendar date. What I actually want is for users to be able to click on a calendar icon to display the calendar date, which sh ...

Setting up a functionality for a PHP-generated select option

When the main select tag "category" is changed, it triggers a PHP script to display a new select tag: <select id="category" onchange="showme(this);"> <option value="txt">text</option> <option value="img">image</ ...

The React modal window stubbornly refuses to close

import c from '../Profile.module.css'; import { useState } from 'react'; import { createPortal } from 'react-dom'; import Modal from '../Modal/Modal'; const TransactionItem = (props) => { const modalRoot = ...

Tips on positioning images to the left and right without causing text to wrap around them

I have successfully floated an image to the left of text with the following CSS. How can I achieve a similar effect with an image to the right of text on the same page? Do I need to use a clearfix between the left and right images? Thank you! .innercont ...

Display a loading screen while transitioning between routes in Angular 2

Is there a way to implement a loading screen for route changes in Angular 2? ...

Steps for retrieving information from a View, transferring it to a Controller, and subsequently forwarding it to another View

Hello everyone! So, I have a situation where I need to pass values from a view using @Html.ActionLink to a controller and then pass them to a new view. I've tried creating a ViewModel that matches the values I need, but when I try to show these result ...