-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
47 lines (41 loc) · 1.2 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
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Header from './Components/Header';
import MainScreen from './Screens/MainScreen';
import { ScreenContext } from './ScreenContext';
import DataContainer from './Components/DataContainer';
import BackButton from './Components/BackButton';
import { init } from './Service/db'
init().then(() => {
console.log("initialized Db")
}).catch((err) => {
console.log("error");
console.log(err);
});
export default function App() {
const [Screen, setScreen] = useState(<MainScreen />);
const [backBtn, setBackBtn] = useState(null);
const handleSetScreen = screen => {
const main = <MainScreen />
const data = <DataContainer>{screen}</DataContainer>
const back = screen.type === main.type ? null : <BackButton />
setScreen(data);
setBackBtn(back);
}
return (
<ScreenContext.Provider
value={{ currentScreen: Screen, handleScreenChange: handleSetScreen }}>
<View style={styles.container}>
<Header >
{backBtn}
</Header>
{Screen}
</View>
</ScreenContext.Provider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});