-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
54 lines (48 loc) · 1.45 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
import * as React from "react";
import { Platform, AppState, Text, View, StyleSheet, StatusBar } from "react-native";
import GameBoard from "./components/GameBoard";
import { name } from "./assets/random-name";
import { remove } from 'firebase/database';
const App = () => {
// From the react naive docs
const appState = React.useRef(AppState.currentState);
const [appStateVisible, setAppStateVisible] = React.useState(appState.current);
React.useEffect(() => {
const subscription = AppState.addEventListener("change", nextAppState => {
if (
appState.current.match(/inactive|background/) &&
nextAppState === "active"
) {
if(Platform.OS === 'web') location.reload();
}
appState.current = nextAppState;
setAppStateVisible(appState.current);
if(appState.current == 'background') remove(playerRef);
});
return () => {subscription.remove()};
}, []);
return (
<View style={styles.container}>
<View style={{ margin: StatusBar.currentHeight + 15 || 15 }} />
<Text style={styles.paragraph}>🐢 User: {name} 🎯</Text>
<GameBoard />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
backgroundColor: "#121212",
},
paragraph: {
margin: 4,
fontSize: 18,
fontWeight: "bold",
textAlign: "center",
color: "#FFFFFF",
opacity: 0.87,
},
});
export default App;