-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
215 lines (195 loc) · 5.87 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
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
import React from 'react';
import {createAppContainer, createSwitchNavigator} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import codePush from "react-native-code-push";
import LandingPage from "./src/pages/Landing";
import {mapping, light, dark} from '@eva-design/eva';
import {ApplicationProvider, IconRegistry, Drawer, Layout, Icon} from '@ui-kitten/components';
import {Provider as PaperProvider} from 'react-native-paper';
import HomePage from "./src/pages/Home";
import CreditsPage from "./src/pages/Credits";
import RedemptionPage from "./src/pages/Redemption";
import AppLoading from "./src/pages/AppLoading";
import AnniversaryPage from "./src/pages/Anniversary";
import {createDrawerNavigator} from "react-navigation-drawer";
import Push from 'appcenter-push';
// @ts-ignore
import Notifications, {NotificationsAndroid} from 'react-native-notifications';
import {Platform, SafeAreaView} from "react-native";
import AsyncStorage from "@react-native-community/async-storage";
import SettingsPage from "./src/pages/Settings";
//@ts-ignore
import customTheme from './assets/theme/custom-theme.json'
import {EvaIconsPack} from '@ui-kitten/eva-icons';
import {Text} from "@ui-kitten/components";
//@ts-ignore
import customMapping from './assets/theme/custom-mapping.json'
import {ThemeContext} from "./src/functions/theme";
import {ThemedIcon} from "./src/components/Icon/ThemedIcon";
import SearchPage from "./src/pages/Search";
import CategoryEventsPage from "./src/pages/CategoryEvents";
import analytics from '@react-native-firebase/analytics'
import EventDetailsPage from "./src/pages/EventDetails";
import TravelPage from "./src/pages/Travel";
//@ts-ignore
function getActiveRouteName(navigationState) {
if (!navigationState) {
return null;
}
const route = navigationState.routes[navigationState.index];
if (route.routes) {
return getActiveRouteName(route);
}
return route.routeName;
}
const drawerData: { title: string; icon: any }[] = [
{
title: "Home",
icon: () => (<ThemedIcon name={'home-outline'} size={20} style={{marginRight: 15}}/>)
},
{
title: "Redemption",
icon: () => (<ThemedIcon name={'gift-outline'} size={20} style={{marginRight: 15}}/>)
},
{
title: "Settings",
icon: () => (<ThemedIcon name={'settings-2-outline'} size={20} style={{marginRight: 15}}/>)
},
{
title: "Credits",
icon: () => (<ThemedIcon name={'info-outline'} size={20} style={{marginRight: 15}}/>)
},
]
const DrawerComponent = ({navigation}: any) => {
const onSelect = (index: any) => {
const route = drawerData[index];
navigation.navigate(route.title);
};
return (
<Layout style={{flex: 1}}>
<SafeAreaView>
<Drawer data={drawerData} onSelect={onSelect}/>
</SafeAreaView>
</Layout>
);
};
const AppNavigator = createStackNavigator({
Home: {
screen: HomePage
},
Anniversary: {
screen: AnniversaryPage
},
Search: {
screen: SearchPage
},
CategoryEvents: {
screen: CategoryEventsPage
},
EventDetails: {
screen: EventDetailsPage
},
Travel: {
screen: TravelPage
}
}, {});
const DrawerNavigator = createDrawerNavigator({
Home: {
screen: AppNavigator
},
Settings: {
screen: SettingsPage
},
Credits: {
screen: CreditsPage
},
Redemption: {
screen: RedemptionPage
},
}, {
drawerPosition: 'right',
contentComponent: DrawerComponent
})
const AuthNavigator = createStackNavigator({
Landing: {
screen: LandingPage,
},
})
const Switch = createSwitchNavigator({
AppLoading: AppLoading,
Auth: AuthNavigator,
App: DrawerNavigator
}, {
initialRouteName: 'AppLoading'
})
const AppContainer = createAppContainer(Switch)
export interface AppState {
theme: 'light' | 'dark'
}
const themes = {light, dark}
class App extends React.Component<{}, AppState> {
constructor(props: {}) {
super(props);
this.state = {
theme: 'light'
}
}
componentWillMount(): void {
AsyncStorage.getItem("theme").then((theme) => {
if (theme === 'light' || theme === 'dark') {
this.setState({theme})
}
})
}
componentDidMount(): void {
Push.setListener({
onPushNotificationReceived: function (pushNotification) {
let message = pushNotification.message;
let title = pushNotification.title;
if (message === null) {
message = '';
}
const Notif = Platform.OS === 'ios' ? Notifications : NotificationsAndroid
Notif.localNotification({
title: title,
body: message,
});
}
}).catch(() => {
//@ts-ignore
alert("Error initializing Push Notifications")
})
}
_toggleTheme() {
const nextTheme = this.state.theme === 'light' ? 'dark' : 'light';
AsyncStorage.setItem('theme', nextTheme).then(() => {
this.setState({theme: nextTheme})
})
}
render() {
const currentTheme = themes[this.state.theme]
return (
<PaperProvider>
<IconRegistry icons={EvaIconsPack}/>
<ThemeContext.Provider value={{
theme: this.state.theme, toggleTheme: () => {
this._toggleTheme()
}
}}>
<ApplicationProvider mapping={mapping}
customMapping={customMapping}
theme={{...currentTheme, ...customTheme}}>
<AppContainer onNavigationStateChange={(prevState, currentState) => {
const currentRouteName = getActiveRouteName(currentState);
const previousRouteName = getActiveRouteName(prevState);
if (previousRouteName !== currentRouteName) {
analytics().setCurrentScreen(currentRouteName, currentRouteName);
}
}}/>
</ApplicationProvider>
</ThemeContext.Provider>
</PaperProvider>
)
}
}
export default codePush({checkFrequency: codePush.CheckFrequency.ON_APP_RESUME})(App)