Skip to content

Commit

Permalink
fix: fix exit animation
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Nov 7, 2023
1 parent fdc0992 commit af488f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function GameLaunchingImage({
initial={styles.initial}
onAnimationComplete={onAnimationComplete}
onAnimationStart={onAnimationStart}
transition={{ duration: 0.2 }}
transition={{ duration: 0.4 }}
>
{children}
</motion.div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ import { GameLaunchingImage } from './game-launching-image'
function getMaskStyle(target: HTMLButtonElement | undefined) {
const boundingClientRect = target?.getBoundingClientRect()
const { y, x, width, height } = boundingClientRect || {}
const isValidBounding =
typeof y === 'number' && typeof x === 'number' && typeof width === 'number' && typeof height === 'number'
let maskPosition = {}
if (boundingClientRect) {
if (isValidBounding) {
maskPosition =
width && height ? { top: y, left: x, width, height } : { top: '50%', left: '50%', width: '0', height: '0' }
}
const initial = { ...maskPosition, filter: 'brightness(1)' }
const expanded = { ...maskPosition, top: 0, left: 0, width: '100%', height: '100%', filter: 'brightness(0)' }
return { valid: Boolean(boundingClientRect), initial, expanded }
const exit = isValidBounding ? { width: 0, height: 0, left: x + width / 2, top: y + height / 2, opacity: 0 } : initial
return { valid: isValidBounding, initial, exit, expanded }
}

export function GameLaunching() {
Expand Down Expand Up @@ -69,7 +72,11 @@ export function GameLaunching() {
}
}

const styles = { initial: maskStyle.initial, exit: maskStyle.initial, animate: maskStyle.expanded }
const styles = {
initial: maskStyle.initial,
exit: maskStyle.exit,
animate: maskStyle.expanded,
}

return (
<GameLaunchingImage
Expand Down
16 changes: 11 additions & 5 deletions src/views/components/routes/library/platform/home-screen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ export function HomeScreen() {
// load roms from cache
const [peekRomsState, { execute: loadRomsFromCache }] = useAsync(async () => {
if (currentPlatformName) {
const { platform: romsPlatform, roms } = await peekRoms(currentPlatformName)
const { platform: romsPlatform, roms: newRoms } = await peekRoms(currentPlatformName)
if (romsPlatform === currentPlatformRef.current) {
setRoms(roms?.length ? roms : [])
if (newRoms?.length) {
setRoms(newRoms)
} else if (!roms?.length) {
setRoms([])
}
}
}
})
Expand Down Expand Up @@ -155,11 +159,13 @@ export function HomeScreen() {
)

useEffect(() => {
if (isRomRoute) {
return
}

;(async () => {
await loadPlatformsAndRomsFromCache()
if (!isRomRoute) {
await loadPlatformsAndRomsFromRemote()
}
await loadPlatformsAndRomsFromRemote()
})()
}, [params.library, currentPlatformName, isRomRoute, loadPlatformsAndRomsFromCache, loadPlatformsAndRomsFromRemote])

Expand Down

0 comments on commit af488f6

Please sign in to comment.