-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
175 lines (163 loc) · 4.38 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { NavigationContainer, ThemeProvider } from "@react-navigation/native";
import { StatusBar } from "expo-status-bar";
import React from "react";
import { View } from "react-native";
import { colors, Icon } from "react-native-elements";
import { TouchableHighlight } from "react-native-gesture-handler";
import { createSharedElementStackNavigator } from "react-navigation-shared-element";
import { palette, sizes, theme } from "./constants/theme";
import HomeScreen from "./screens/HomeScreen";
import ProfileScreen from "./screens/ProfileScreen";
import SettingsScreen from "./screens/SettingsScreen";
const BOTTOM_BAR_HEIGHT = sizes.xs * 4;
const TOP_BAR_HEIGHT = BOTTOM_BAR_HEIGHT * 1.5;
const Tabs = createBottomTabNavigator();
const Stack = createSharedElementStackNavigator();
const TabsNavigation = () => {
return (
<Tabs.Navigator
initialRouteName="Explore"
tabBarOptions={{
activeTintColor: palette.primary,
style: {
height: BOTTOM_BAR_HEIGHT,
backgroundColor: palette.black,
borderTopWidth: 0.5,
borderTopColor: colors.grey0,
},
inactiveTintColor: colors.grey2,
tabStyle: {
paddingBottom: sizes.xs / 2,
},
}}
>
<Tabs.Screen
options={{
tabBarIcon: ({ color }) => (
<Icon name="home" type="feather" color={color} />
),
}}
name="Home"
component={HomeScreen}
/>
<Tabs.Screen
name="Profile"
component={ProfileScreen}
options={{
tabBarIcon: ({ color }) => (
<Icon name="user" type="feather" color={color} />
),
}}
/>
</Tabs.Navigator>
);
};
const getHeader = (route) => {
const routeName = route.state
? route.state.routes[route.state.index].name
: route.params?.screen || "Home";
switch (routeName) {
case "Profile":
return { headerShown: false };
case "Explore":
case "Home":
return { headerShown: true, headerTitle: "Home" };
default:
return { headerShown: false };
}
};
const TopBarIcon = ({ iconName, color, onPress }) => {
return (
<TouchableHighlight style={{ marginRight: sizes.xs }}>
<Icon
color={color}
size={sizes.md}
type="feather"
name={iconName}
onPress={onPress}
/>
</TouchableHighlight>
);
};
const getHeaderRightIcons = (route) => {
const routeName = route.state
? route.state.routes[route.state.index].name
: route.params?.screen || "Home";
const IconsRight = () => (
<View style={{ display: "flex", flexDirection: "row" }}>
<TopBarIcon
color={palette.white}
iconName={"search"}
onPress={() => {}}
/>
<TopBarIcon
color={palette.white}
iconName={"more-vertical"}
onPress={() => {}}
/>
</View>
);
switch (routeName) {
case "Profile":
return null;
case "Explore":
case "Home":
return IconsRight;
default:
return null;
}
};
const StackNavigation = (props) => {
return (
<Stack.Navigator
screenOptions={{
headerTitleStyle: {
fontSize: sizes.sm,
color: palette.white,
},
headerRightContainerStyle: {
alignItems: "center",
alignContent: "center",
},
headerStyle: {
height: TOP_BAR_HEIGHT,
backgroundColor: palette.black,
borderBottomWidth: 0.5,
borderBottomColor: colors.grey0,
},
// headerTransparent: true,
}}
>
<Stack.Screen
name="Explore"
component={TabsNavigation}
options={({ route }) => {
return {
headerRight: getHeaderRightIcons(route),
...getHeader(route),
};
}}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={({ route }) => ({
headerTitle: null,
headerTintColor: palette.white,
})}
/>
</Stack.Navigator>
);
};
function App() {
return (
<ThemeProvider theme={theme}>
<NavigationContainer theme={theme}>
<StatusBar style="light" translucent backgroundColor="transparent" />
<StackNavigation />
</NavigationContainer>
</ThemeProvider>
);
}
export default App;