2023-12-14 21:48:40 +01:00
|
|
|
import React, {useCallback, useEffect} from 'react'
|
2024-01-08 22:47:25 +01:00
|
|
|
import {
|
|
|
|
View,
|
|
|
|
StyleSheet,
|
|
|
|
Image as RNImage,
|
|
|
|
AccessibilityInfo,
|
|
|
|
useColorScheme,
|
|
|
|
} from 'react-native'
|
2023-12-14 21:48:40 +01:00
|
|
|
import * as SplashScreen from 'expo-splash-screen'
|
2023-12-16 00:40:22 +01:00
|
|
|
import {Image} from 'expo-image'
|
2023-12-14 21:48:40 +01:00
|
|
|
import Animated, {
|
|
|
|
interpolate,
|
|
|
|
runOnJS,
|
|
|
|
useAnimatedStyle,
|
|
|
|
useSharedValue,
|
|
|
|
withTiming,
|
|
|
|
Easing,
|
|
|
|
} from 'react-native-reanimated'
|
|
|
|
import MaskedView from '@react-native-masked-view/masked-view'
|
|
|
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
|
|
|
import Svg, {Path, SvgProps} from 'react-native-svg'
|
|
|
|
|
2024-01-08 21:09:30 +01:00
|
|
|
import {isAndroid} from '#/platform/detection'
|
2024-02-06 20:43:51 +01:00
|
|
|
import {useThemePrefs} from 'state/shell'
|
2024-01-31 22:01:07 +01:00
|
|
|
import {Logotype} from '#/view/icons/Logotype'
|
2024-01-08 21:09:30 +01:00
|
|
|
|
2023-12-16 00:40:22 +01:00
|
|
|
// @ts-ignore
|
|
|
|
import splashImagePointer from '../assets/splash.png'
|
2024-01-08 22:47:25 +01:00
|
|
|
// @ts-ignore
|
|
|
|
import darkSplashImagePointer from '../assets/splash-dark.png'
|
2023-12-16 00:40:22 +01:00
|
|
|
const splashImageUri = RNImage.resolveAssetSource(splashImagePointer).uri
|
2024-01-08 22:47:25 +01:00
|
|
|
const darkSplashImageUri = RNImage.resolveAssetSource(
|
|
|
|
darkSplashImagePointer,
|
|
|
|
).uri
|
2023-12-16 00:40:22 +01:00
|
|
|
|
2023-12-14 21:48:40 +01:00
|
|
|
export const Logo = React.forwardRef(function LogoImpl(props: SvgProps, ref) {
|
|
|
|
const width = 1000
|
|
|
|
const height = width * (67 / 64)
|
|
|
|
return (
|
|
|
|
<Svg
|
|
|
|
fill="none"
|
|
|
|
// @ts-ignore it's fiiiiine
|
|
|
|
ref={ref}
|
|
|
|
viewBox="0 0 64 66"
|
2024-01-08 22:47:25 +01:00
|
|
|
style={[{width, height}, props.style]}>
|
2023-12-14 21:48:40 +01:00
|
|
|
<Path
|
2024-01-08 22:47:25 +01:00
|
|
|
fill={props.fill || '#fff'}
|
2023-12-14 21:48:40 +01:00
|
|
|
d="M13.873 3.77C21.21 9.243 29.103 20.342 32 26.3v15.732c0-.335-.13.043-.41.858-1.512 4.414-7.418 21.642-20.923 7.87-7.111-7.252-3.819-14.503 9.125-16.692-7.405 1.252-15.73-.817-18.014-8.93C1.12 22.804 0 8.431 0 6.488 0-3.237 8.579-.18 13.873 3.77ZM50.127 3.77C42.79 9.243 34.897 20.342 32 26.3v15.732c0-.335.13.043.41.858 1.512 4.414 7.418 21.642 20.923 7.87 7.111-7.252 3.819-14.503-9.125-16.692 7.405 1.252 15.73-.817 18.014-8.93C62.88 22.804 64 8.431 64 6.488 64-3.237 55.422-.18 50.127 3.77Z"
|
|
|
|
/>
|
|
|
|
</Svg>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
isReady: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
const AnimatedLogo = Animated.createAnimatedComponent(Logo)
|
|
|
|
|
|
|
|
export function Splash(props: React.PropsWithChildren<Props>) {
|
|
|
|
const insets = useSafeAreaInsets()
|
|
|
|
const intro = useSharedValue(0)
|
|
|
|
const outroLogo = useSharedValue(0)
|
|
|
|
const outroApp = useSharedValue(0)
|
2023-12-18 23:27:03 +01:00
|
|
|
const outroAppOpacity = useSharedValue(0)
|
2023-12-14 21:48:40 +01:00
|
|
|
const [isAnimationComplete, setIsAnimationComplete] = React.useState(false)
|
2023-12-16 00:40:22 +01:00
|
|
|
const [isImageLoaded, setIsImageLoaded] = React.useState(false)
|
2024-01-03 07:21:17 +01:00
|
|
|
const [isLayoutReady, setIsLayoutReady] = React.useState(false)
|
2024-01-08 22:47:25 +01:00
|
|
|
const [reduceMotion, setReduceMotion] = React.useState<boolean | undefined>(
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
const isReady =
|
|
|
|
props.isReady &&
|
|
|
|
isImageLoaded &&
|
|
|
|
isLayoutReady &&
|
|
|
|
reduceMotion !== undefined
|
|
|
|
|
2024-02-06 20:43:51 +01:00
|
|
|
const {colorMode} = useThemePrefs()
|
2024-01-08 22:47:25 +01:00
|
|
|
const colorScheme = useColorScheme()
|
|
|
|
const themeName = colorMode === 'system' ? colorScheme : colorMode
|
|
|
|
const isDarkMode = themeName === 'dark'
|
2023-12-14 21:48:40 +01:00
|
|
|
|
2024-01-08 21:09:30 +01:00
|
|
|
const logoAnimation = useAnimatedStyle(() => {
|
2023-12-14 21:48:40 +01:00
|
|
|
return {
|
|
|
|
transform: [
|
|
|
|
{
|
|
|
|
scale: interpolate(intro.value, [0, 1], [0.8, 1], 'clamp'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
scale: interpolate(
|
|
|
|
outroLogo.value,
|
2023-12-18 23:27:03 +01:00
|
|
|
[0, 0.08, 1],
|
2024-01-08 21:09:30 +01:00
|
|
|
[1, 0.8, 500],
|
2023-12-14 21:48:40 +01:00
|
|
|
'clamp',
|
|
|
|
),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
opacity: interpolate(intro.value, [0, 1], [0, 1], 'clamp'),
|
|
|
|
}
|
|
|
|
})
|
2024-01-31 22:01:07 +01:00
|
|
|
const bottomLogoAnimation = useAnimatedStyle(() => {
|
|
|
|
return {
|
|
|
|
opacity: interpolate(intro.value, [0, 1], [0, 1], 'clamp'),
|
|
|
|
}
|
|
|
|
})
|
2024-01-08 22:47:25 +01:00
|
|
|
const reducedLogoAnimation = useAnimatedStyle(() => {
|
|
|
|
return {
|
|
|
|
transform: [
|
|
|
|
{
|
|
|
|
scale: interpolate(intro.value, [0, 1], [0.8, 1], 'clamp'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
opacity: interpolate(intro.value, [0, 1], [0, 1], 'clamp'),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-01-08 21:09:30 +01:00
|
|
|
const logoWrapperAnimation = useAnimatedStyle(() => {
|
|
|
|
return {
|
|
|
|
opacity: interpolate(
|
|
|
|
outroAppOpacity.value,
|
|
|
|
[0, 0.1, 0.2, 1],
|
|
|
|
[1, 1, 0, 0],
|
|
|
|
'clamp',
|
|
|
|
),
|
|
|
|
}
|
|
|
|
})
|
2023-12-14 21:48:40 +01:00
|
|
|
|
|
|
|
const appAnimation = useAnimatedStyle(() => {
|
|
|
|
return {
|
|
|
|
transform: [
|
|
|
|
{
|
2023-12-16 00:40:22 +01:00
|
|
|
scale: interpolate(outroApp.value, [0, 1], [1.1, 1], 'clamp'),
|
2023-12-14 21:48:40 +01:00
|
|
|
},
|
|
|
|
],
|
2023-12-18 23:27:03 +01:00
|
|
|
opacity: interpolate(
|
|
|
|
outroAppOpacity.value,
|
2024-01-08 21:09:30 +01:00
|
|
|
[0, 0.1, 0.2, 1],
|
2023-12-18 23:27:03 +01:00
|
|
|
[0, 0, 1, 1],
|
|
|
|
'clamp',
|
|
|
|
),
|
2023-12-14 21:48:40 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const onFinish = useCallback(() => setIsAnimationComplete(true), [])
|
2024-01-03 07:21:17 +01:00
|
|
|
const onLayout = useCallback(() => setIsLayoutReady(true), [])
|
|
|
|
const onLoadEnd = useCallback(() => setIsImageLoaded(true), [])
|
2023-12-14 21:48:40 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-12-16 00:40:22 +01:00
|
|
|
if (isReady) {
|
2024-01-03 07:21:17 +01:00
|
|
|
SplashScreen.hideAsync()
|
|
|
|
.then(() => {
|
|
|
|
intro.value = withTiming(
|
2023-12-14 21:48:40 +01:00
|
|
|
1,
|
2024-01-03 07:21:17 +01:00
|
|
|
{duration: 400, easing: Easing.out(Easing.cubic)},
|
|
|
|
async () => {
|
|
|
|
// set these values to check animation at specific point
|
|
|
|
// outroLogo.value = 0.1
|
|
|
|
// outroApp.value = 0.1
|
|
|
|
outroLogo.value = withTiming(
|
|
|
|
1,
|
|
|
|
{duration: 1200, easing: Easing.in(Easing.cubic)},
|
|
|
|
() => {
|
|
|
|
runOnJS(onFinish)()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
outroApp.value = withTiming(1, {
|
|
|
|
duration: 1200,
|
|
|
|
easing: Easing.inOut(Easing.cubic),
|
|
|
|
})
|
|
|
|
outroAppOpacity.value = withTiming(1, {
|
|
|
|
duration: 1200,
|
|
|
|
easing: Easing.in(Easing.cubic),
|
|
|
|
})
|
2023-12-14 21:48:40 +01:00
|
|
|
},
|
|
|
|
)
|
2024-01-03 07:21:17 +01:00
|
|
|
})
|
|
|
|
.catch(() => {})
|
2023-12-14 21:48:40 +01:00
|
|
|
}
|
2023-12-18 23:27:03 +01:00
|
|
|
}, [onFinish, intro, outroLogo, outroApp, outroAppOpacity, isReady])
|
2023-12-16 00:40:22 +01:00
|
|
|
|
2024-01-08 22:47:25 +01:00
|
|
|
useEffect(() => {
|
|
|
|
AccessibilityInfo.isReduceMotionEnabled().then(setReduceMotion)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const logoAnimations =
|
|
|
|
reduceMotion === true ? reducedLogoAnimation : logoAnimation
|
|
|
|
|
2023-12-14 21:48:40 +01:00
|
|
|
return (
|
2024-01-03 07:21:17 +01:00
|
|
|
<View style={{flex: 1}} onLayout={onLayout}>
|
2023-12-14 21:48:40 +01:00
|
|
|
{!isAnimationComplete && (
|
2024-01-31 22:01:07 +01:00
|
|
|
<View style={StyleSheet.absoluteFillObject}>
|
|
|
|
<Image
|
|
|
|
accessibilityIgnoresInvertColors
|
|
|
|
onLoadEnd={onLoadEnd}
|
|
|
|
source={{uri: isDarkMode ? darkSplashImageUri : splashImageUri}}
|
|
|
|
style={StyleSheet.absoluteFillObject}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
bottomLogoAnimation,
|
|
|
|
{
|
|
|
|
position: 'absolute',
|
|
|
|
bottom: insets.bottom + 40,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
]}>
|
|
|
|
<Logotype fill="#fff" width={90} />
|
|
|
|
</Animated.View>
|
|
|
|
</View>
|
2023-12-14 21:48:40 +01:00
|
|
|
)}
|
|
|
|
|
2024-01-08 22:47:25 +01:00
|
|
|
{isReady &&
|
|
|
|
(isAndroid || reduceMotion === true ? (
|
|
|
|
// Use a simple fade on older versions of android (work around a bug)
|
|
|
|
<>
|
|
|
|
<Animated.View style={[{flex: 1}, appAnimation]}>
|
|
|
|
{props.children}
|
2024-01-08 21:09:30 +01:00
|
|
|
</Animated.View>
|
2024-01-08 22:47:25 +01:00
|
|
|
|
|
|
|
{!isAnimationComplete && (
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
StyleSheet.absoluteFillObject,
|
|
|
|
logoWrapperAnimation,
|
|
|
|
{
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
transform: [{translateY: -(insets.top / 2)}, {scale: 0.1}], // scale from 1000px to 100px
|
|
|
|
},
|
|
|
|
]}>
|
|
|
|
<AnimatedLogo
|
2024-01-31 22:01:07 +01:00
|
|
|
fill="#fff"
|
2024-01-08 22:47:25 +01:00
|
|
|
style={[{opacity: 0}, logoAnimations]}
|
|
|
|
/>
|
|
|
|
</Animated.View>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<MaskedView
|
|
|
|
style={[StyleSheet.absoluteFillObject]}
|
|
|
|
maskElement={
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
{
|
|
|
|
// Transparent background because mask is based off alpha channel.
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
transform: [{translateY: -(insets.top / 2)}, {scale: 0.1}], // scale from 1000px to 100px
|
|
|
|
},
|
|
|
|
]}>
|
2024-01-31 22:01:07 +01:00
|
|
|
<AnimatedLogo fill="#fff" style={[logoAnimations]} />
|
2024-01-08 22:47:25 +01:00
|
|
|
</Animated.View>
|
|
|
|
}>
|
|
|
|
{!isAnimationComplete && (
|
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
StyleSheet.absoluteFillObject,
|
2024-02-16 19:07:57 +01:00
|
|
|
{
|
|
|
|
backgroundColor: isDarkMode
|
|
|
|
? // special off-spec color for dark mode
|
|
|
|
'#0F1824'
|
|
|
|
: '#fff',
|
|
|
|
},
|
2024-01-08 22:47:25 +01:00
|
|
|
]}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Animated.View style={[{flex: 1}, appAnimation]}>
|
|
|
|
{props.children}
|
2024-01-01 01:05:07 +01:00
|
|
|
</Animated.View>
|
2024-01-08 22:47:25 +01:00
|
|
|
</MaskedView>
|
|
|
|
))}
|
2023-12-14 21:48:40 +01:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|