-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix spinner delay by optimizing image loading
- Loading branch information
1 parent
7488406
commit 0fd3c84
Showing
1 changed file
with
13 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import logo from '../../assets/images/logo.png'; | ||
import React from 'react'; | ||
|
||
function Spinner() { | ||
const [imageLoaded, setImageLoaded] = useState(false); | ||
|
||
useEffect(() => { | ||
const img = new Image(); | ||
img.src = logo; | ||
img.onload = () => setImageLoaded(true); | ||
}, []); | ||
|
||
return ( | ||
<div className="flex justify-center items-center h-dvh" role="status" aria-live="polite"> | ||
<div className="relative h-40 w-40"> | ||
<div className={`absolute rounded-full h-40 w-40 border-t-4 border-b-4 border-main-blue ${imageLoaded ? 'animate-spin' : ''}`}></div> | ||
<div className={`absolute inset-0 flex items-center justify-center ${!imageLoaded && 'opacity-0'}`}> | ||
<img src={logo} className="object-contain w-24" alt="Loading..." onLoad={() => setImageLoaded(true)} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
const Spinner = () => { | ||
return ( | ||
<div className="flex justify-center items-center h-[100dvh]" role="status" aria-live="polite"> | ||
<div className="relative h-40 w-40"> | ||
<div className="absolute rounded-full h-40 w-40 border-t-4 border-b-4 border-main-blue animate-spin"></div> | ||
<div className="absolute inset-0 flex items-center justify-center"> | ||
<img src="/wallet_192.png" alt="Loading..." className="object-contain w-24" /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Spinner; |