Adding a Loading Animation to Your Bubble App
In this Bubble tutorial video, I'm going to demonstrate how you can add in a loading animation while your Bubble app makes the API call to the OpenAI API. This is a great bit of UI and UX improvement that you can make to your app because sometimes users just get a bit confused when they click a button and it appears like nothing happens. Yes, Bubble puts a floating bar going across the top of the screen if you're doing a client-side workflow, but you can improve upon that so that your users know that they're getting something good and that they need to wait for it. This is all important when you're using OpenAI with Bubble.
Using Lottie Animations for Loading Indicators
I'm going to demonstrate in this tutorial how to do that with Lottie animations. Lottie files have become a popular format for animations on the web because they're lightweight. They're basically JSON files and they scale quite nicely too. So they've got a number of advantages over GIFs or other image animation files.
Adding the Lottie Plugin to Your Bubble App
To add in a Lottie animation, I need to add in a plugin. I'm just going to pick one of these. This one's got a lot of users, let's try that one and add in Lottie. Let's just make this 300 by 300. Obviously, you can adapt to the right size. For the Lottie file, if you want complete control over where you're hosting it, you can download the Lottie file and upload it to your Bubble storage. But in this example, I'm just going to pick one of these and link directly to it into one of my workspaces in Lottie.
Configuring the Lottie Animation
I think I need to click this one here of JSON. So then I paste that in there as the dynamic link and I'm going to preview my app to see if it loads in the Lottie animation correctly. Brilliant, yes it does.
Implementing the Loading Animation in Your Workflow
So how do I get it to show during my API call and hide the rest of the time? First of all, I've made sure that wherever I'm displaying my results, I have this unticked: "The element is visible on page load" and I tick "Collapse when hidden". Then on my Lottie element, now that I've added that in, I'm going to also say it is not visible on page load and it's collapsed when hidden.
Adding Workflow Steps for the Loading Animation
I need to add just a couple of steps or maybe three steps to my submit button. The first thing I'm going to do when the button's clicked is show my Lottie animation. I'm going to show that first. This is where the app makes a call to the OpenAI API, and so this is actually where the waiting occurs. Then, in this case, I'm using a custom state. I'm saving it as a custom state in order to display the results on my page. So I'm going to add in here "hide Lottie" because I know that it's completed the wait from OpenAI here, and then I'm going to show, in this case, I'm using a multi-line input. This just happens to be the element I'm using to display the reply from OpenAI.
Testing the Loading Animation
Let's preview and I'll go Twitter again and I'll say "What are the limitations of Bubble?" Okay, so I see my animation. I'm also getting the Bubble loading bar across the top, and then the animation gives way to the results.
Conclusion
So there you have it. That is how you can use a loading animation to improve the UI in your Bubble app. If you're learning Bubble, you need to check out our website Planet No Code where we've got hundreds of Bubble tutorial videos, some of which you cannot find on YouTube. We're just hoping to create the best resource for learning Bubble out there.