-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathApp.js
123 lines (113 loc) · 3.24 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
import 'react-native-gesture-handler';
import React from 'react';
import {
StyleSheet,
View,
TouchableOpacity,
} from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import HomeScreen from './src/screens/HomeScreen';
import FavoriteScreen from './src/screens/FavoriteScreen';
import ShopScreen from './src/screens/ShopScreen';
import LinearGradient from 'react-native-linear-gradient';
import AppIcon, { Icons } from './src/components/AppIcon';
import Colors from "./src/constants/Colors";
const BottomTab = ({ type, color, size = 24, isFocused, index }) => {
const icon = index == 0 ? 'home' : 'heart';
const gradient = index == 1;
return (
<View>
{gradient ? (
<LinearGradient
colors={[Colors.light, Colors.dark]}
start={{ x: isFocused ? 0 : 1, y: 0 }} end={{ x: isFocused ? 1 : 0, y: 0 }}
style={styles.middleIcon}>
<AppIcon name={'shopping-basket'} type={type} size={size} color={'white'} />
</LinearGradient>
) : (
<View style={styles.icon}>
<AppIcon name={icon} type={type} size={size} color={color} />
</View>
)}
</View>
)
}
const MyTabBar = ({ state, descriptors, navigation }) => {
return (
<View
style={styles.bottomBar}>
{state.routes.map((route, index) => {
const isFocused = state.index === index;
const { options } = descriptors[route.key];
const onPress = () => {
const event = navigation.emit({
type: 'tabPress',
target: route.key,
})
if (!isFocused && !event.defaultPrevented) {
navigation.navigate(route.name);
}
}
const color = isFocused ? Colors.dark : Colors.gray;
return (
<TouchableOpacity
key={index}
onPress={onPress}
testID={options.tabBarTestID}
accessibilityRole="button"
>
<BottomTab
type={index !== 1 ? Icons.MaterialCommunityIcons : Icons.FontAwesome5}
index={index}
isFocused={isFocused}
size={24}
color={color}
/>
</TouchableOpacity>
)
})}
</View>
)
}
const Tab = createBottomTabNavigator();
const TabNavigator = () => {
return (
<Tab.Navigator
tabBar={(props) => <MyTabBar {...props} />}>
<Tab.Screen name="home" component={HomeScreen} />
<Tab.Screen name="Shop" component={ShopScreen} />
<Tab.Screen name="Favorite" component={FavoriteScreen} />
</Tab.Navigator>
)
}
const App = () => {
return (
<NavigationContainer>
<TabNavigator />
</NavigationContainer>
)
};
const styles = StyleSheet.create({
bottomBar: {
height: 60,
backgroundColor: 'white',
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'space-around',
},
middleIcon: {
bottom: 18,
width: 60,
height: 60,
borderRadius: 30,
backgroundColor: 'red',
justifyContent: 'center',
alignItems: 'center',
shadowColor: 'black',
shadowOffset: { width: 2, height: 2 },
shadowOpacity: 0.6,
elevation: 8,
}
});
export default App;