I wrote a short article on what I think is the bes...
# compose-web
u
I wrote a short article on what I think is the best method to display a loader while resources are loading. https://kdroidfilter.github.io/blog/2024/resources-loader-compose-web
K 5
k
a
Since your implementation simply disables the loader once the canvas is being rendered, this can be done in HTML/CSS only. ComposeViewport injects its' canvas into the page, so you can have a loading container element in your html, and as long as it's the
:only-child
, show it. Once the canvas is injected into the page, it will simply disappear.
Minimal example:
Copy code
<body>
<div class="container">
    <svg width="24" height="24" viewBox="0 0 24 24" xmlns="<http://www.w3.org/2000/svg>">
        <!-- svg content -->
    </svg>
    <noscript>
        This page requires JavaScript to be enabled.
    </noscript>
</div>
</body>
Copy code
.container {
    display: none;
}

.container:only-child {
    display: flex;
    width: 100%;
    height: 100%;
    gap: 2em;
    justify-content: center;
    align-items: center;
}
Copy code
fun main() {
    ComposeViewport(document.body!!) { 
        App()
    }
}