Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136/* * This is a reimplementation of what exists in our HTML template files * already. Once the React tree mounts, this is what gets rendered first, until * the app is ready to go. */
import {useEffect, useRef, useState} from 'react'import {Image} from 'react-native'import Svg, {ClipPath, Defs, G, Path, Rect} from 'react-native-svg'
import {DEFAULT_BRAND_CONFIG} from '#/lib/community/BrandContext'import {atoms as a, flattenToCSS} from '#/alf'
const size = 100const ratio = 243 / 285
function isRemoteAsset(path: string): boolean { return path.startsWith('http://') || path.startsWith('https://')}
export function Splash({ isReady, children,}: React.PropsWithChildren<{ isReady: boolean}>) { const [isAnimationComplete, setIsAnimationComplete] = useState(false) const splashRef = useRef<HTMLDivElement>(null)
// hide the static one that's baked into the HTML - gets replaced by our React version below useEffect(() => { // double rAF ensures that the React version gets painted first requestAnimationFrame(() => { requestAnimationFrame(() => { const splash = document.getElementById('splash') if (splash) { splash.remove() } }) }) }, [])
// when ready, we fade/scale out useEffect(() => { if (!isReady) return
const reduceMotion = window.matchMedia( '(prefers-reduced-motion: reduce)', ).matches const node = splashRef.current if (!node || reduceMotion) { setIsAnimationComplete(true) return }
const animation = node.animate( [ {opacity: 1, transform: 'scale(1)'}, {opacity: 0, transform: 'scale(1.5)'}, ], { duration: 300, easing: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)', fill: 'forwards', }, ) animation.onfinish = () => setIsAnimationComplete(true)
return () => { animation.cancel() } }, [isReady])
const hasRemoteLogo = isRemoteAsset(DEFAULT_BRAND_CONFIG.assets.logo)
return ( <> {isReady && children}
{!isAnimationComplete && ( <div ref={splashRef} style={flattenToCSS([ a.fixed, a.inset_0, a.flex, a.align_center, a.justify_center, // to compensate for the `top: -50px` below {transformOrigin: 'center calc(50% - 50px)'}, ])}> {hasRemoteLogo ? ( <Image source={{uri: DEFAULT_BRAND_CONFIG.assets.logo}} accessibilityIgnoresInvertColors style={[a.relative, {width: size, height: size, top: -50}]} /> ) : ( <Svg fill="none" viewBox="0 0 285 243" style={[ a.relative, {width: size, height: size * ratio, top: -50}, ]}> <G clipPath="url(#clip0_splash_web)"> <Path fill="var(--text)" d="M148.846 144.562C148.846 159.75 161.158 172.062 176.346 172.062H207.012V185.865H176.346C161.158 185.865 148.846 198.177 148.846 213.365V243.045H136.029V213.365C136.029 198.177 123.717 185.865 108.529 185.865H77.8633V172.062H108.529C123.717 172.062 136.029 159.75 136.029 144.562V113.896H148.846V144.562Z" /> <Path fill="var(--text)" d="M170.946 31.8766C160.207 42.616 160.207 60.0281 170.946 70.7675L192.631 92.4516L182.871 102.212L161.186 80.5275C150.447 69.7881 133.035 69.7881 122.296 80.5275L101.309 101.514L92.2456 92.4509L113.232 71.4642C123.972 60.7248 123.972 43.3128 113.232 32.5733L91.5488 10.8899L101.309 1.12988L122.993 22.814C133.732 33.5533 151.144 33.5534 161.884 22.814L183.568 1.12988L192.631 10.1925L170.946 31.8766Z" /> <Path fill="var(--text)" d="M79.0525 75.3259C75.1216 89.9962 83.8276 105.076 98.498 109.006L128.119 116.943L124.547 130.275L94.9267 122.338C80.2564 118.407 65.1772 127.113 61.2463 141.784L53.5643 170.453L41.1837 167.136L48.8654 138.467C52.7963 123.797 44.0902 108.718 29.4199 104.787L-0.201172 96.8497L3.37124 83.5173L32.9923 91.4542C47.6626 95.3851 62.7419 86.679 66.6728 72.0088L74.6098 42.3877L86.9895 45.7048L79.0525 75.3259Z" /> <Path fill="var(--text)" d="M218.413 71.4229C222.344 86.093 237.423 94.7992 252.094 90.8683L281.715 82.9313L285.287 96.2628L255.666 104.2C240.995 108.131 232.29 123.21 236.22 137.88L243.902 166.55L231.522 169.867L223.841 141.198C219.91 126.528 204.831 117.822 190.16 121.753L160.539 129.69L156.967 116.357L186.588 108.42C201.258 104.49 209.964 89.4103 206.033 74.74L198.096 45.1189L210.476 41.8018L218.413 71.4229Z" /> </G> <Defs> <ClipPath id="clip0_splash_web"> <Rect width="285" height="243" fill="white" /> </ClipPath> </Defs> </Svg> )} </div> )} </> )}