-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
157 lines (146 loc) · 4.23 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
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
import React, { useEffect } from 'react';
import { CommonActions, NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { Feather, FontAwesome5, Ionicons } from '@expo/vector-icons';
import { BottomTabNavigationOptions } from '@react-navigation/bottom-tabs/lib/typescript/src/types';
import { Platform } from 'react-native';
import * as Device from 'expo-device';
import { requestTrackingPermissionsAsync } from 'expo-tracking-transparency';
import mobileAds, { BannerAd, BannerAdSize, TestIds } from 'react-native-google-mobile-ads';
import Styles from './src/Styles/Styles';
import { WHITE, YELLOW } from './src/constants';
import { MainTab } from './src/types';
import Home from './src/screens/Home';
import Map from './src/screens/Map';
import List from './src/screens/List';
import Website from './src/screens/Website';
import AnalyticsService from './src/libs/AnalyticsService';
import Nationwide from './src/screens/Nationwide';
export default function App() {
const Tabs = createBottomTabNavigator();
mobileAds()
.initialize()
.then((adapterStatuses) => {
// Initialization complete!
});
const adId = (): string => {
if (Device.isDevice) {
if (Platform.OS === 'android') {
return 'ca-app-pub-1063051842575021/7584775669';
}
return 'ca-app-pub-1063051842575021/8005756608';
}
return TestIds.BANNER;
};
const availableTabs: MainTab[] = [
{
name: 'home',
component: Home,
label: 'Home',
showHeader: false,
},
{
name: 'map',
component: Map,
label: 'Map',
showHeader: false,
},
{
name: 'list',
component: List,
label: 'List',
showHeader: false,
},
{
name: 'nationwide',
component: Nationwide,
label: 'Nationwide',
showHeader: false,
icon: ({ color, size }) => (
<FontAwesome5 name="hamburger" size={size} color={color} />
),
},
{
name: 'website',
component: Website,
label: 'Website',
title: 'coeliacsanctuary.co.uk',
icon: ({ color, size }) => (
<Feather name="link" size={size} color={color} />
),
},
];
const options: BottomTabNavigationOptions = {
headerStyle: {
...Styles.bgBlueLight,
},
tabBarItemStyle: {
...Styles.mb2,
},
tabBarIconStyle: {
// ...Styles.mt2,
},
tabBarStyle: {
...Styles.bgBlueLight,
...Styles.justifyBetween,
},
tabBarActiveTintColor: YELLOW,
tabBarInactiveTintColor: WHITE,
tabBarLabelStyle: {
// ...Styles.fontSemibold,
...Styles.textSm,
},
};
useEffect(() => {
(async () => {
const { status } = await requestTrackingPermissionsAsync();
await AnalyticsService.toggleAnalytics(status === 'granted');
})();
}, []);
return (
<>
<NavigationContainer>
<Tabs.Navigator screenOptions={options}>
{availableTabs.map((tab) => (
<Tabs.Screen
key={tab.name}
name={tab.name}
component={tab.component}
options={{
title: tab.label,
headerShown: tab?.showHeader ?? true,
headerTitle: tab?.title ?? tab.label,
tabBarIcon: ({ focused, color, size }) => (
tab.icon
? tab.icon({ focused, color, size })
// @ts-ignore
: <Ionicons name={tab.name} size={size} color={color} />
),
}}
listeners={({ navigation }) => ({
tabPress: (event) => {
event.preventDefault();
navigation.dispatch(
CommonActions.reset({
index: 0,
routes: [
{ name: tab.name },
],
}),
);
},
})}
/>
))}
</Tabs.Navigator>
</NavigationContainer>
<BannerAd
unitId={adId()}
size={BannerAdSize.BANNER}
requestOptions={{
requestNonPersonalizedAdsOnly: true,
}}
/>
</>
);
}