Skip to content

Commit

Permalink
preload images
Browse files Browse the repository at this point in the history
  • Loading branch information
vnxx committed Apr 17, 2020
1 parent 4bac3f2 commit 0c3c0ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import Designer from './componens/designer'
import Editor from './componens/editor'
import { tshirts } from './componens/tshirtcolor'

const initial = {
direction: 'front',
Expand Down Expand Up @@ -42,9 +43,9 @@ function App() {
})
const elStage = React.useRef();

React.useEffect(() => {
// console.log(tshirt)
}, [tshirt])
// React.useEffect(() => {
// // console.log(tshirt)
// }, [])

const checkDeselect = e => {
// deselect when clicked on empty area
Expand All @@ -61,15 +62,27 @@ function App() {
})
}

React.useEffect(() => {

}, [])

React.useEffect(() => {
if (!appLoaded) {
// console.log('app loaded')
setAppLoaded(true)
let fisrtLoad = document.getElementById("fisrtLoad")
fisrtLoad.classList.add("fade-out")
setTimeout(() => {
fisrtLoad.style.display = "none"
}, 500)
// preload images
tshirts.forEach((pic) => {
const image = new Image()
image.src = pic
image.onload = () => {
// hide loading when images loaded
// console.log('image loaded')
setAppLoaded(true)
let fisrtLoad = document.getElementById("fisrtLoad")
fisrtLoad.classList.add("fade-out")
setTimeout(() => {
fisrtLoad.style.display = "none"
}, 500)
}
})
}
}, [appLoaded, setAppLoaded])

Expand Down
3 changes: 3 additions & 0 deletions src/componens/tshirtcolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import white_back from '../assets/tshirt/white/back.png'
import black_front from '../assets/tshirt/black/front.png'
import black_back from '../assets/tshirt/black/back.png'

export const tshirts = [white_front, white_back, black_front, black_back]

export default function TshirtView({ color, direction }) {

switch (color) {
case 'black':
if (direction === 'front') {
Expand Down

0 comments on commit 0c3c0ac

Please sign in to comment.