-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
77 lines (66 loc) · 1.97 KB
/
App.js
File metadata and controls
77 lines (66 loc) · 1.97 KB
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
import { StatusBar } from "expo-status-bar";
import React, { useState } from "react";
import { StyleSheet, View, SafeAreaView } from "react-native";
//File imports
import Header from "./App/components/Header";
import StartGameScreen from "./App/Screens/StartGameScreen";
import GameScreen from "./App/Screens/GameScreen";
import GameOverScreen from "./App/Screens/GameOver";
import * as Font from "expo-font";
import { AppLoading } from "expo-app-loading";
const fetchFontHandler = () => {
return Font.loadAsync({
"open-sans-Regular": require("./App/assets/Fonts/OpenSans-Regular.ttf"),
"open-sans-Bold": require("./App/assets/Fonts/OpenSans-Bold.ttf"),
});
};
export default App = () => {
const [selectedNum, setSelectedNum] = useState();
const [guessRound, setGuessRound] = useState(0);
const [dataLoaded, setDataLoaded] = useState(false);
if (!dataLoaded) {
return (
<AppLoading
startAsync={fetchFontHandler}
onFinish={setDataLoaded(true)}
onError={(err) => console.log(err)}
/>
);
}
const startNewGameHandler = () => {
setSelectedNum(null);
setGuessRound(0);
};
const selectedGameHandler = (selectedNumber) => {
setSelectedNum(selectedNumber);
};
const gameOverHandler = (numberOfRound) => {
setGuessRound(numberOfRound);
};
let firstScreen = <StartGameScreen onStartGame={selectedGameHandler} />;
if (selectedNum && guessRound <= 0) {
firstScreen = (
<GameScreen userValue={selectedNum} onGameOver={gameOverHandler} />
);
} else if (guessRound > 0) {
firstScreen = (
<GameOverScreen
roundNumber={guessRound}
userNumber={selectedNum}
onPressStartNewGame={startNewGameHandler}
/>
);
}
return (
<SafeAreaView style={styles.container}>
<StatusBar style="auto" />
<Header headerTitle="Guess a number" />
{firstScreen}
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
});