-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
79 lines (67 loc) · 2.09 KB
/
App.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
79
import React, { useState, useMemo } from "react";
import { StyleSheet, View, useColorScheme } from "react-native";
import { NavigationContainer, Theme, useTheme } from "@react-navigation/native";
import { darkTheme, lightTheme } from "./assets/css/themes";
import { createStackNavigator } from "@react-navigation/stack";
import { Marcellus_400Regular } from "@expo-google-fonts/marcellus";
import { useFonts } from "expo-font";
import ArticleScreen from "./screens/article";
import HomeScreen from "./screens/home";
const Stack = createStackNavigator();
const App = () => {
const [grandparentValue, setGrandparentValue] = useState("");
const handleParentValueChange = (newValue) => {
setGrandparentValue(newValue);
};
const theme = useTheme();
const scheme = useColorScheme();
const styles = useMemo(() => createStyles(theme), [theme]);
let [fontsLoaded] = useFonts({
Marcellus_400Regular,
});
if (!fontsLoaded) {
return null;
}
return (
<AppLayout
onValueChange={handleParentValueChange}
articleUrl={grandparentValue}
theme={theme}
styles={styles}
scheme={scheme}
/>
);
};
const AppLayout = ({ onValueChange, articleUrl, styles, theme, scheme }) => (
<View style={[styles.body]}>
<NavigationContainer theme={scheme == "dark" ? darkTheme : lightTheme}>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
options={{ title: "Latest News" }}
initialParams={{ onValueChange }}
>
{(props) => <HomeScreen {...props} />}
</Stack.Screen>
<Stack.Screen
name="Article"
component={ArticleScreen}
initialParams={{ articleUrl }}
options={{
headerBackTitleVisible: false,
headerTitle: "",
headerStyle: styles.header,
headerBackTitleStyle: { color: theme.colors.primary },
}}
/>
</Stack.Navigator>
</NavigationContainer>
</View>
);
const createStyles = (theme: Theme) =>
StyleSheet.create({
body: {
flex: 1,
},
});
export default App;