-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.js
409 lines (357 loc) · 12.3 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import React, { useState } from 'react';
import { View, TouchableNativeFeedback, Pressable, Animated, Text, StatusBar } from 'react-native';
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
import { NavigationContainer } from '@react-navigation/native';
import { CardStyleInterpolators, createStackNavigator } from '@react-navigation/stack';
import 'react-native-gesture-handler';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import AppLoading from 'expo-app-loading';
import {
useFonts,
Roboto_400Regular,
Roboto_700Bold,
} from '@expo-google-fonts/roboto';
import { Ionicons, MaterialCommunityIcons, FontAwesome5, Entypo } from '@expo/vector-icons';
import Login from './Telas/LoginScreen';
import Cadastro from './Telas/CadastroScreen'
import ScreenProdutos from './Telas/ScreenProdutos';
import Perfil from './Telas/PerfilScreen';
import CadastrarCoisas from './Telas/CadastrarCoisasScreen';
import Conta from './Telas/Conta';
import Notificacoes from './Telas/Notificacoes';
import Restaurante from './Telas/RestauranteComprar';
import Busca from './Telas/BuscaScreen'
import ComprarProduto from './Telas/ComprarProduto'
import ListaItens from './Telas/listaItens';
import TrocarFoto from './Telas/TrocarFoto';
import Trocar from './Telas/TrocarScreen';
import EditarCoisas from './Telas/EditarScreen';
import { FontAwesome, AntDesign, Feather, MaterialIcons } from '@expo/vector-icons';
import Constants from 'expo-constants';
import * as Font from 'expo-font';
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
const TabTop = createMaterialTopTabNavigator();
const configTransition = {
animation: 'spring',
config: {
stiffness: 2000,
damping: 2000,
mass: 3,
overshootClamping: true,
restDisplacementThreshold: 0.01,
restSpeedThreshold: 0.01,
},
};
function EditarProdutosScreen({ navigation, route }) {
return (
<EditarCoisas tipo="Produtos" navigation={navigation} route={route} />
)
}
function EditarScreen({ navigation, route }) {
return (
<EditarCoisas tipo="Lugares" navigation={navigation} route={route} />
)
}
function TrocarFotoScreen() {
return (
<TrocarFoto />
)
}
function BuscaProdutosScreen({ navigation, route }) {
return (
<Busca route={route} navigation={navigation} tipo="Produtos" />
)
}
function TrocarScreen({ route }) {
return (
<Trocar route={route} />
)
}
function Categoria({ route, navigation }) {
return (
<ListaItens route={route} navigation={navigation} tipo="Lugares" />
)
}
function AbaComprarProduto({ navigation, route }) {
return (
<ComprarProduto navigation={navigation} route={route} />
)
}
function AbaCadastrarProdutos({ navigation, route }) {
return (
<CadastrarCoisas navigation={navigation} route={route} tipo="Produtos" />
)
}
function AbaNotificacoes() {
return (
<Notificacoes />
)
}
function AbaConta({ navigation }) {
return (
<Conta navigation={navigation} />
)
}
function AbaCadatrarCoisas({ navigation, route }) {
return (
<CadastrarCoisas navigation={navigation} route={route} tipo="Lugares" />
)
}
function RestauranteComprar({ navigation, route }) {
return (
<Restaurante navigation={navigation} route={route} />
)
}
function AbaRestaurantes({ navigation, route }) {
const arrayTipos = ["Lanches", "Sorvetes", "Brasileira", "Pizza"];
const iconsCategoria = [
{
text: "Pizza",
icon: "pizza-outline",
tipoIcone: Ionicons
},
{
text: "Brasileira",
icon: "silverware-fork-knife",
tipoIcone: MaterialCommunityIcons
},
{
text: "Lanches",
icon: "hamburger",
tipoIcone: FontAwesome5
},
{
text: "Sorvetes",
icon: "ice-cream",
tipoIcone: FontAwesome5
}
];
return (
<ScreenProdutos iconsCategoria={iconsCategoria} arrayTipos={arrayTipos} navigation={navigation} route={route} />
)
}
function AbaMercados({ navigation, route }) {
const arrayTipos = ["Produtos", "Farmácia"];
const iconsCategoria = [
{
text: "Produtos",
icon: "box",
tipoIcone: Entypo
},
{
text: "Farmácia",
icon: "prescription-bottle",
tipoIcone: FontAwesome5
}
];
return (
<ScreenProdutos iconsCategoria={iconsCategoria} arrayTipos={arrayTipos} navigation={navigation} route={route} />
)
}
function AbaBebidas({ navigation, route }) {
const arrayTipos = ["Cervejas"];
const iconsCategoria = [
{
text: "Cervejas",
icon: "ios-beer-outline",
tipoIcone: Ionicons
},
];
return (
<ScreenProdutos iconsCategoria={iconsCategoria} arrayTipos={arrayTipos} navigation={navigation} route={route} />
)
}
function LoginScreen({ navigation, route }) {
return (
<Login navigation={navigation} route={route} />
);
}
function CadastroScreen({ navigation }) {
return (
<Cadastro navigation={navigation} />
);
}
const TabTopBar = ({ state, descriptors, navigation, position }) => {
const inputRange = state.routes.map((_, i) => i);
const indicator = position.interpolate({
inputRange,
outputRange: [1, 0.75, 0.6]
})
const pos = position.interpolate({
inputRange,
outputRange: [-1, 191, 428]
})
return (
<View style={{ flexDirection: 'row', justifyContent: 'space-between', paddingTop: Constants.statusBarHeight + 5, paddingHorizontal: 10 }}>
{state.routes.map((route, index) => {
const { options } = descriptors[route.key];
const label =
options.tabBarLabel !== undefined
? options.tabBarLabel
: options.title !== undefined
? options.title
: route.name;
const isFocused = state.index === index;
const onPress = () => {
navigation.navigate(route.name)
}
return (
<React.Fragment key={`arrayElement${index}`}>
<View>
<TouchableNativeFeedback background={TouchableNativeFeedback.Ripple('#A18E85')} onPress={onPress} >
<View style={{ padding: 5 }}>
<Text style={{ fontFamily: 'Roboto_700Bold', fontSize: 23, color: isFocused ? '#ED3E3E' : '#A18E85' }}>{label}</Text>
</View>
</TouchableNativeFeedback>
</View>
</React.Fragment>
)
})}
<Animated.View style={{ backgroundColor: '#ED3E3E', height: 1, transform: [{ scaleX: indicator }, { translateX: pos }], width: 150, position: 'absolute', top: 85, left: 18 }} />
</View>
)
}
function HomeScreen() {
return (
<TabTop.Navigator
tabBar={(props) => <TabTopBar {...props} />}
>
<TabTop.Screen name="Restaurantes" component={AbaRestaurantes} />
<TabTop.Screen name="Mercados" component={AbaMercados} />
<TabTop.Screen name="Bebidas" component={AbaBebidas} />
</TabTop.Navigator>
)
}
function BuscaScreen({ navigation, route }) {
return (
<Busca tipo="Lugares" route={route} navigation={navigation} />
)
}
function PedidosScreen() {
return (
<ListaItens tipo="Pedidos" />
)
}
function PerfilScreen({ navigation, route }) {
return (
<Perfil navigation={navigation} route={route} />
)
}
function StackPerfil() {
const [isReady, setIsReady] = useState(false);
function cacheFonts(fonts) {
return fonts.map(font => Font.loadAsync(font));
}
const carregarIcone = async () => {
const fontAssets = cacheFonts([MaterialIcons.font]);
await Promise.all([fontAssets]);
}
if (isReady == false) {
return (
<AppLoading
startAsync={carregarIcone}
onFinish={() => setIsReady(true)}
onError={console.warn}
/>
);
}
return (
<Stack.Navigator
screenOptions={{
headerTitleStyle: { fontFamily: 'Roboto_700Bold', fontSize: 22 }, headerStyle: { borderBottomColor: '#A18E85', borderBottomWidth: 1, elevation: 0, height: 120 }, headerBackImage: () => (<MaterialIcons name="keyboard-backspace" size={40} color="black" />), headerPressColor: '#A18E85', cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS, transitionSpec: {
open: configTransition,
close: configTransition,
},
}}
>
<Stack.Screen options={{ headerShown: false }} name="PerfilTela" component={PerfilScreen} />
<Stack.Screen options={{ title: 'NOTIFICAÇÕES' }} name="Notificacoes" component={AbaNotificacoes} />
<Stack.Screen options={{ title: 'CONTA' }} name="Conta" component={AbaConta} />
<Stack.Screen options={{ title: 'CADASTRAR' }} name="CadastrarCoisas" component={AbaCadatrarCoisas} />
</Stack.Navigator>
)
}
function tabsApp() {
return (
<Tab.Navigator
backBehavior="history"
screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
let iconName;
let IconType;
if (route.name === 'Ínicio') {
IconType = FontAwesome
iconName = "home"
} else if (route.name === 'Busca') {
IconType = AntDesign
iconName = 'search1'
} else if (route.name === 'Pedidos') {
IconType = Feather
iconName = 'shopping-bag'
} else {
IconType = AntDesign
iconName = 'user'
}
return <IconType name={iconName} size={30} color={color} />
},
tabBarActiveTintColor: 'black',
tabBarInactiveTintColor: '#A18E85',
tabBarLabelStyle: { fontFamily: 'Roboto_700Bold', fontSize: 13, marginTop: -10, marginBottom: 10 },
tabBarStyle: { height: 70, elevation: 0, borderTopColor: '#ededed', borderTopWidth: 0.9 },
headerShown: false,
tabBarButton: (props) => <Pressable android_ripple={{ color: '#A18E85', borderless: true }} {...props} />
})}
>
<Tab.Screen name="Ínicio" component={HomeScreen} />
<Tab.Screen name="Busca" component={BuscaScreen} />
<Tab.Screen name="Pedidos" component={PedidosScreen} />
<Tab.Screen name="Perfil" component={StackPerfil} />
</Tab.Navigator>)
}
function SnackAll() {
return (
<Stack.Navigator screenOptions={{
headerShown: false, headerTitleStyle: { fontFamily: 'Roboto_700Bold', fontSize: 22 }, headerStyle: { borderBottomColor: '#A18E85', borderBottomWidth: 1, elevation: 0, height: 120 }, headerBackImage: () => (<MaterialIcons name="keyboard-backspace" size={40} color="black" />), headerPressColor: '#A18E85', cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS, transitionSpec: {
open: configTransition,
close: configTransition,
}
}}>
<Stack.Screen name="TabsView" component={tabsApp} />
<Stack.Screen name="RestauranteComprar" component={RestauranteComprar} />
<Stack.Screen name="ComprarProdutos" component={AbaComprarProduto} />
<Stack.Screen options={{ headerShown: true, title: "CADASTRAR" }} name="CadastrarProdutos" component={AbaCadastrarProdutos} />
<Stack.Screen name="Categoria" options={({ route }) => ({ title: route.params.name, headerShown: true })} component={Categoria} />
<Stack.Screen name="Trocar" options={{ headerShown: true, title: "TROCAR" }} component={TrocarScreen} />
<Stack.Screen name="TrocarFoto" options={{ headerShown: true, title: "TROCAR" }} component={TrocarFotoScreen} />
<Stack.Screen name="BuscaProdutos" options={{ headerShown: true, title: "BUSCAR" }} component={BuscaProdutosScreen} />
<Stack.Screen name="Editar" options={{ headerShown: true, title: "EDITAR" }} component={EditarScreen} />
<Stack.Screen name="EditarProdutos" options={{ headerShown: true, title: "EDITAR" }} component={EditarProdutosScreen} />
</Stack.Navigator>
)
}
function MyStack() {
return (
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Cadastro" component={CadastroScreen} />
<Stack.Screen name="App" component={SnackAll} />
</Stack.Navigator>
);
}
export default function App() {
let [fontsLoaded] = useFonts({
Roboto_400Regular,
Roboto_700Bold,
})
if (!fontsLoaded) {
return <AppLoading />;
} else {
return (
<NavigationContainer theme={{ colors: { background: 'white' } }}>
<StatusBar translucent backgroundColor="transparent" barStyle="dark-content" />
<MyStack />
</NavigationContainer>
);
}
}