-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5eaebce
commit 2b9b57c
Showing
8 changed files
with
215 additions
and
108 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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { FC, useRef } from "react"; | ||
import { StyleSheet, Animated, TouchableWithoutFeedback } from "react-native"; | ||
import { Text } from "op-common"; | ||
import { useAnimation, useOnMount, scale, delay } from "op-utils"; | ||
import { animations, metrics, colors } from "op-design"; | ||
import { credits } from "op-config"; | ||
|
||
const asyncAnimationStart = (anim: Animated.CompositeAnimation) => | ||
new Promise((resolve) => anim.start(resolve)); | ||
|
||
interface SplashProps { | ||
onHide: () => void; | ||
} | ||
|
||
export const Splash: FC<SplashProps> = function ({ onHide }) { | ||
const skippingEnabledRef = useRef(true); | ||
const hasSkippedRef = useRef(false); | ||
|
||
// Animations setup | ||
const fadeCreditsAnimDuration = 200; | ||
const fadeCreditsStaggerDuration = 100; | ||
const backgroundColorAnimDuration = 200; | ||
// We can use hooks in loops in this case because "credits" is a constant | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const fadeCreditsAnims = credits.map(() => useAnimation()); | ||
const backgroundColorAnim = useAnimation(); | ||
const splashDuration = 2000; | ||
const showAnim = Animated.stagger( | ||
fadeCreditsStaggerDuration, | ||
fadeCreditsAnims.map((anim) => | ||
anim.setup({ duration: fadeCreditsAnimDuration }) | ||
) | ||
); | ||
|
||
const hideAnim = Animated.sequence([ | ||
Animated.stagger( | ||
fadeCreditsStaggerDuration, | ||
fadeCreditsAnims.map((anim) => | ||
anim.setup({ duration: fadeCreditsAnimDuration, toValue: 0 }) | ||
) | ||
), | ||
backgroundColorAnim.setup({ | ||
duration: backgroundColorAnimDuration, | ||
useNativeDriver: false, | ||
}), | ||
]); | ||
|
||
const animate = async () => { | ||
await asyncAnimationStart(showAnim); | ||
await delay(splashDuration); | ||
skippingEnabledRef.current = false; | ||
if (!hasSkippedRef.current) { | ||
await asyncAnimationStart(hideAnim); | ||
onHide(); | ||
} | ||
}; | ||
|
||
useOnMount(() => { | ||
animate(); | ||
}); | ||
|
||
const rootAnimStyle = { | ||
backgroundColor: backgroundColorAnim.value.interpolate({ | ||
inputRange: [0, 1], | ||
outputRange: [colors.splash, colors.primary[9]], | ||
}), | ||
}; | ||
|
||
// If the user touches the screen, end the animation early | ||
const handlePress = () => { | ||
if (!skippingEnabledRef.current || hasSkippedRef.current) return; | ||
hasSkippedRef.current = true; | ||
hideAnim.start(onHide); | ||
}; | ||
|
||
return ( | ||
<TouchableWithoutFeedback onPress={handlePress}> | ||
<Animated.View style={[styles.root, rootAnimStyle]}> | ||
{credits.map((credit, index) => ( | ||
<Text | ||
key={credit} | ||
weight="bold" | ||
style={[ | ||
styles.credit, | ||
animations.fadeSlideBottom(fadeCreditsAnims[index].value), | ||
]} | ||
> | ||
{credit} | ||
</Text> | ||
))} | ||
</Animated.View> | ||
</TouchableWithoutFeedback> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
root: { | ||
padding: metrics.screenMargin, | ||
flex: 1, | ||
flexDirection: "column", | ||
justifyContent: "center", | ||
backgroundColor: colors.splash, | ||
}, | ||
credit: { | ||
color: "white", | ||
fontSize: scale(28), | ||
marginVertical: scale(12), | ||
}, | ||
}); |
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,109 +1,17 @@ | ||
import React, { FC, useRef } from "react"; | ||
import { StyleSheet, Animated, TouchableWithoutFeedback } from "react-native"; | ||
import { Text } from "op-common"; | ||
import { useAnimation, useOnMount, scale, delay } from "op-utils"; | ||
import { animations, metrics, colors } from "op-design"; | ||
import { credits } from "op-config"; | ||
|
||
const asyncAnimationStart = (anim: Animated.CompositeAnimation) => | ||
new Promise((resolve) => anim.start(resolve)); | ||
import { FC } from "react"; | ||
import { useOnMount } from "op-utils"; | ||
|
||
interface SplashProps { | ||
onHide: () => void; | ||
} | ||
|
||
export const Splash: FC<SplashProps> = function ({ onHide }) { | ||
const skippingEnabledRef = useRef(true); | ||
const hasSkippedRef = useRef(false); | ||
|
||
// Animations setup | ||
const fadeCreditsAnimDuration = 200; | ||
const fadeCreditsStaggerDuration = 100; | ||
const backgroundColorAnimDuration = 200; | ||
// We can use hooks in loops in this case because "credits" is a constant | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const fadeCreditsAnims = credits.map(() => useAnimation()); | ||
const backgroundColorAnim = useAnimation(); | ||
const splashDuration = 2000; | ||
const showAnim = Animated.stagger( | ||
fadeCreditsStaggerDuration, | ||
fadeCreditsAnims.map((anim) => | ||
anim.setup({ duration: fadeCreditsAnimDuration }) | ||
) | ||
); | ||
|
||
const hideAnim = Animated.sequence([ | ||
Animated.stagger( | ||
fadeCreditsStaggerDuration, | ||
fadeCreditsAnims.map((anim) => | ||
anim.setup({ duration: fadeCreditsAnimDuration, toValue: 0 }) | ||
) | ||
), | ||
backgroundColorAnim.setup({ | ||
duration: backgroundColorAnimDuration, | ||
useNativeDriver: false, | ||
}), | ||
]); | ||
|
||
const animate = async () => { | ||
await asyncAnimationStart(showAnim); | ||
await delay(splashDuration); | ||
skippingEnabledRef.current = false; | ||
if (!hasSkippedRef.current) { | ||
await asyncAnimationStart(hideAnim); | ||
onHide(); | ||
} | ||
}; | ||
// @ts-ignore | ||
document.getElementById("splash").style.display = "none"; | ||
|
||
useOnMount(() => { | ||
animate(); | ||
onHide(); | ||
}); | ||
|
||
const rootAnimStyle = { | ||
backgroundColor: backgroundColorAnim.value.interpolate({ | ||
inputRange: [0, 1], | ||
outputRange: [colors.splash, colors.primary[9]], | ||
}), | ||
}; | ||
|
||
// If the user touches the screen, end the animation early | ||
const handlePress = () => { | ||
if (!skippingEnabledRef.current || hasSkippedRef.current) return; | ||
hasSkippedRef.current = true; | ||
hideAnim.start(onHide); | ||
}; | ||
|
||
return ( | ||
<TouchableWithoutFeedback onPress={handlePress}> | ||
<Animated.View style={[styles.root, rootAnimStyle]}> | ||
{credits.map((credit, index) => ( | ||
<Text | ||
key={credit} | ||
weight="bold" | ||
style={[ | ||
styles.credit, | ||
animations.fadeSlideBottom(fadeCreditsAnims[index].value), | ||
]} | ||
> | ||
{credit} | ||
</Text> | ||
))} | ||
</Animated.View> | ||
</TouchableWithoutFeedback> | ||
); | ||
return null; | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
root: { | ||
padding: metrics.screenMargin, | ||
flex: 1, | ||
flexDirection: "column", | ||
justifyContent: "center", | ||
backgroundColor: colors.splash, | ||
}, | ||
credit: { | ||
color: "white", | ||
fontSize: scale(28), | ||
marginVertical: scale(12), | ||
}, | ||
}); |