-
Notifications
You must be signed in to change notification settings - Fork 3
/
Menu.tsx
78 lines (72 loc) · 2.17 KB
/
Menu.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React, { FunctionComponent, memo, useState } from "react";
import { Animated, StyleSheet } from "react-native";
import { useMappedState } from "redux-react-hook";
import { delay } from "../utils/delay";
import { actions } from "../actions";
import { ReduxState } from "../types/ReduxState";
import { COLOR_SHUTTLE_GRAY } from "../config/colors";
import { useMappedActions } from "../utils/useMappedActions";
import { RippleEffect } from "../components/RippleEffect";
import { StaggerAnimator } from "../components/StaggerAnimator";
import { MENU_ANIM_DURATION } from "../config/constants";
const mapState = (state: ReduxState) => ({
highScore: state.stats.highScore
});
const mapActions = {
navigateToPlayground: actions.navigateToPlayground
};
export const Menu: FunctionComponent = memo(() => {
console.warn(" - ");
const { highScore } = useMappedState(mapState);
const { navigateToPlayground } = useMappedActions(mapActions);
const [animationStatus, setAnimationStatus] = useState<"showing" | "hiding">(
"showing"
);
const handlePress = async () => {
setAnimationStatus("hiding");
await delay(MENU_ANIM_DURATION);
navigateToPlayground();
};
return (
<RippleEffect onPress={handlePress}>
<StaggerAnimator
style={styles.container}
status={animationStatus}
enterDuration={MENU_ANIM_DURATION}
exitDuration={MENU_ANIM_DURATION}
>
<Animated.Text style={styles.title}>Just tap</Animated.Text>
<Animated.View style={[styles.scoreContainer]}>
<Animated.Text style={styles.score}>
{highScore ? `High score: ${highScore}` : ""}
</Animated.Text>
</Animated.View>
</StaggerAnimator>
</RippleEffect>
);
});
const styles = StyleSheet.create({
container: {
width: "100%",
height: "100%",
alignItems: "center",
justifyContent: "center"
},
title: {
fontSize: 66,
fontWeight: "300",
color: COLOR_SHUTTLE_GRAY
},
scoreContainer: {
position: "absolute",
left: 0,
bottom: 60,
width: "100%",
alignItems: "center",
justifyContent: "center"
},
score: {
fontSize: 18,
color: COLOR_SHUTTLE_GRAY
}
});