Ionic skeleton loader

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Skeleton loaders are super cool temporary placeholders for when your content is loading. Pretty sure you have seen them around on Facebook or Instagram.

Today we'll be looking at how to create this cool skeleton loader in Ionic.
First of all, we'll start by using the Ionic starter app we built a while ago. You can find the starter on GitHub.
For our example, we'll be adding a skeleton loader on our tab1 page.
Open up the tab1.page.html and add the following:
<ion-list>
<ion-list-header>
<ion-skeleton-text animated style="width: 80px"></ion-skeleton-text>
</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-skeleton-text></ion-skeleton-text>
</ion-thumbnail>
<ion-label>
<h3>
<ion-skeleton-text animated style="width: 80%"></ion-skeleton-text>
</h3>
<p>
<ion-skeleton-text animated style="width: 60%"></ion-skeleton-text>
</p>
</ion-label>
</ion-item>
</ion-list>
This will be roughly the same format as our data, and you can see we render a full list with a header and one item in this case. It's up to you to create multiple items if needed. Furthermore, the skeletons will fill up the areas at hand. You can see we offset some by making them partial widths. They also come with the animated attribute. This will give them the remarkable moving aspect.
Now we need to stop showing this once our actual data is loaded.
Let's first head over to the tab1.page.ts file to load some delayed data.
data = [];
constructor() {
setTimeout(() => {
this.data.push({
thumbnail: "URL",
title: "Chris Bongers",
description: "Some cool description about this person",
});
}, 2000);
}
This will load our data array with one person but be delayed by 2000 milliseconds.
Now we can modify our html file to reflect this data.
<ion-list *ngIf="data.length">
<ion-list-header> Famous people </ion-list-header>
<ion-item *ngFor="let item of data">
<ion-thumbnail slot="start">
<img [src]="item.thumbnail" />
</ion-thumbnail>
<ion-label>
<h3>{{item.title}}</h3>
<p>{{item.description}}</p>
</ion-label>
</ion-item>
</ion-list>
And the last element we need to add is a ngIf on our skeleton list.
<ion-list *ngIf="!data.length"></ion-list>
This will make sure the skeleton doesn't show when the data is loaded.
All and all, we should now have this cool effect:

You can find the full demo code on the following GitHub repo.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter