-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
64 lines (57 loc) · 1.62 KB
/
App.js
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
import { ImageBackground, SafeAreaView, StyleSheet, View } from "react-native";
import StartScreen from "./screens/StartScreen";
import { LinearGradient } from "expo-linear-gradient";
import { useState } from "react";
import MainScreen from "./screens/MainScreen";
import GameOverScreen from "./screens/GameOverScreen";
export default function App() {
const [userNumber, setUserNumber] = useState();
const [gameOver, setGameOver] = useState(true);
const [roundsNumber, setRoundsNumber] = useState(0);
function pickedNumberHandler(pickedNumber) {
setUserNumber(pickedNumber);
setGameOver(false);
}
function gameOverHandler() {
setGameOver(true);
}
function startNewGame() {
setUserNumber(null);
setRoundsNumber(0);
}
let screen = <StartScreen onPickedNumber={pickedNumberHandler} />;
if (userNumber) {
screen = (
<MainScreen userNumber={userNumber} onGameOver={gameOverHandler} />
);
}
if (gameOver && userNumber) {
screen = (
<GameOverScreen
roundsNumber={roundsNumber}
userNumber={userNumber}
onStartNewGame={startNewGame}
/>
);
}
return (
<LinearGradient colors={["#578585", "#C5D0D3"]} style={styles.rootScreen}>
<ImageBackground
source={require("./assets/images/david-libeert.jpg")}
resizeMode="cover"
style={styles.rootScreen}
imageStyle={styles.image}
>
<SafeAreaView style={styles.rootScreen}>{screen}</SafeAreaView>
</ImageBackground>
</LinearGradient>
);
}
const styles = StyleSheet.create({
rootScreen: {
flex: 1,
},
image: {
opacity: 0.7,
},
});