-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
140 lines (127 loc) · 4.12 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { Text, View, FlatList, StyleSheet, StatusBar, TouchableHighlight } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import ABVScreen from "./screens/ABV"
import SettingsScreen from './screens/Settings'
import RecipesScreen from './screens/Recipes'
import BottlesScreen from './screens/Bottles'
import HydrometerScreen from './screens/Hydrometer'
import UnitConvertScreen from './screens/UnitConvert'
const DATA = [
{
id: 'item-abv',
title: 'ABV calculator',
description: 'Alcohol by volume',
},
{
id: 'item-bottles',
title: 'Bottles',
description: 'Calcute how many bottles do you need'
},
{
id: 'item-hydro',
title: 'Hydrometer',
description: 'Hydrometer temperature correction'
},
{
id: 'item-unit',
title: 'Unit converter',
description: 'Unit conversion calculators'
},
];
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1 }}>
<FlatList
ItemSeparatorComponent={
Platform.OS !== 'android' &&
(({ highlighted }) => (
<View
style={[styles.separator, highlighted && { marginLeft: 0 }]}
/>
))
}
data={DATA}
renderItem={({ item, index, separators }) => (
<TouchableHighlight
key={item.key}
underlayColor="#c0c0c0"
onPress={() => this._onPress(item, navigation)}
onShowUnderlay={separators.highlight}
onHideUnderlay={separators.unhighlight}>
<Item title={item.title} description={item.description} />
</TouchableHighlight>
)}
keyExtractor={item => item.id}
/>
</View>
);
}
_onPress = (item, navigation) => {
switch (item.id) {
case "item-abv":
navigation.navigate('ABV');
break;
case "item-bottles":
navigation.navigate('Bottles');
break;
case "item-hydro":
navigation.navigate('Hydrometer');
break;
case "item-unit":
navigation.navigate('Unit Converter');
break;
}
}
type ItemProps = { title: string, description: string };
const Item = ({ title, description }: ItemProps) => (
<View style={styles.item}>
<Text style={styles.title}>{title}</Text>
<Text>{description}</Text>
</View>
);
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
function Home() {
return (
<Tab.Navigator>
<Tab.Screen name="Tools" component={HomeScreen} />
<Tab.Screen name="Recipes" component={RecipesScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
);
}
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={Home} options={{ headerShown: false }} />
<Stack.Screen name="ABV" component={ABVScreen} />
<Stack.Screen name="Bottles" component={BottlesScreen} />
<Stack.Screen name="Unit Converter" component={UnitConvertScreen} />
<Stack.Screen name="Hydrometer" component={HydrometerScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 2,
marginTop: StatusBar.currentHeight || 0,
},
item: {
backgroundColor: '',
padding: 5,
marginVertical: 8,
marginHorizontal: 16,
},
title: {
fontSize: 32,
},
separator: {
backgroundColor: 'grey',
height: 0.3,
}
});
export default App;