-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
213 lines (206 loc) · 8.1 KB
/
App.js
File metadata and controls
213 lines (206 loc) · 8.1 KB
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
import 'react-native-gesture-handler'; // Required for handling gestures in the app
import React from 'react';
import { NavigationContainer, CommonActions } from '@react-navigation/native'; // Provides navigation capabilities and common actions like reset
import { createDrawerNavigator, DrawerContentScrollView, DrawerItemList } from '@react-navigation/drawer'; // Handles drawer navigation
import { createStackNavigator } from '@react-navigation/stack'; // Used for creating stacks within navigation
import { Image, StyleSheet, View } from 'react-native'; // Basic React Native components for UI
import Toast from 'react-native-toast-message'; // A library for displaying toast messages across the app
import HomeScreen from "./screens/Home"; // Import the Home screen
import ProgramStack from './Navigation/ProgramStack'; // Import for the program stack, which handles session navigation
import AnnouncementsScreen from "./screens/Announcements"; // Import the Announcements screen
import EventDetailsScreen from './screens/EventDetails'; // Import the EventDetails screen
import AnnouncementsHeader from './Components/AnnouncementsHeader'; // Import the custom header for Announcements
import { FavoriteProvider } from './context/FavoriteContext'; // Provide favorite events context to the app
import { EventProvider } from './context/EventContext'; // Provide event management context to the app
import AddEventScreen from './screens/AddEvent'; // Import screen for adding new events
import AddAnnouncement from './screens/AddAnnouncement'; // Import screen for adding announcements
import QRCodeScreen from './screens/QRCodeScanner'; // Import screen for QR code scanner
import About from './screens/About'; // Import About screen
import OrganisersScreen from './screens/Organisers'; // Import screen for the organizing committee
import Site from './screens/Site'; // Import site information screen
// Initialize the drawer and stack navigators
const Drawer = createDrawerNavigator();
const Stack = createStackNavigator();
// Custom drawer content component to include the ACIS logo at the top
const CustomDrawerContent = (props) => (
<DrawerContentScrollView {...props}>
{/* Logo at the top of the drawer */}
<View style={styles.logoContainer}>
<Image
source={require('./images/acis-logo.png')}
style={styles.logo}
/>
</View>
{/* List of drawer items */}
<DrawerItemList {...props} />
</DrawerContentScrollView>
);
export default function App() {
// Function to reset the navigation stack to ensure only one route is in the history
const handleNavigationReset = (navigation, routeName) => {
navigation.dispatch(
CommonActions.reset({
index: 0, // Set the index to 0 so it's the only screen
routes: [{ name: routeName }], // The new route to navigate to
})
);
};
// Global options applied to all screens in the stack, such as header styling and button configuration
const screenOptions = ({ navigation }) => ({
// Custom header component with Announcements button
headerRight: () => <AnnouncementsHeader navigation={navigation} />,
headerStyle: {
backgroundColor: '#304067', // Set the top bar background color
},
headerTintColor: '#FCFAF8', // Set color for icons and text in the header
headerTitle: 'ACIS', // Title for the header bar
headerTitleAlign: 'center', // Align title to the center
headerTitleStyle: {
fontSize: 24, // Font size for the title text
fontWeight: 'bold', // Make the title text bold
},
});
// Drawer navigation structure, including key app sections like Home, Sessions, and Check-in
const DrawerNavigator = () => (
<Drawer.Navigator drawerContent={(props) => <CustomDrawerContent {...props} />}>
{/* Home screen */}
<Drawer.Screen
name="Home"
component={HomeScreen}
options={screenOptions} // Apply global screen options
listeners={({ navigation }) => ({
drawerItemPress: (e) => {
e.preventDefault(); // Prevent default navigation
handleNavigationReset(navigation, 'Home'); // Reset stack and navigate to Home
},
})}
/>
{/* Site screen */}
<Drawer.Screen
name="Site"
component={Site}
options={screenOptions}
listeners={({ navigation }) => ({
drawerItemPress: (e) => {
e.preventDefault();
handleNavigationReset(navigation, 'Site');
},
})}
/>
{/* Sessions screen (program stack) */}
<Drawer.Screen
name="Sessions"
component={ProgramStack}
options={screenOptions}
listeners={({ navigation }) => ({
drawerItemPress: (e) => {
e.preventDefault();
handleNavigationReset(navigation, 'Sessions');
},
})}
/>
{/* QR Code Check-in screen */}
<Drawer.Screen
name="Check-in"
component={QRCodeScreen}
options={screenOptions}
listeners={({ navigation }) => ({
drawerItemPress: (e) => {
e.preventDefault();
handleNavigationReset(navigation, 'Check-in');
},
})}
/>
{/* Committee screen */}
<Drawer.Screen
name="Committee"
component={OrganisersScreen}
options={screenOptions}
listeners={({ navigation }) => ({
drawerItemPress: (e) => {
e.preventDefault();
handleNavigationReset(navigation, 'Committee');
},
})}
/>
{/* About screen */}
<Drawer.Screen
name="About"
component={About}
options={screenOptions}
listeners={({ navigation }) => ({
drawerItemPress: (e) => {
e.preventDefault();
handleNavigationReset(navigation, 'About');
},
})}
/>
</Drawer.Navigator>
);
return (
// Wrap app in event context provider to manage event data
<EventProvider>
<NavigationContainer>
{/* Stack Navigator to handle navigation between screens */}
<Stack.Navigator>
{/* Main drawer navigation screen */}
<Stack.Screen
name="Drawer"
component={DrawerNavigator}
options={{ headerShown: false }} // Hide the header for the drawer
/>
{/* Announcements screen */}
<Stack.Screen
name="Announcements"
component={AnnouncementsScreen}
options={screenOptions} // Apply global styling here
/>
{/* Event details screen */}
<Stack.Screen
name="EventDetails"
component={EventDetailsScreen}
options={screenOptions} // Use the same global options
/>
{/* Add new event screen */}
<Stack.Screen
name="AddEvent"
component={AddEventScreen}
options={{
headerStyle: {
backgroundColor: '#304067', // Same color for the toolbar
},
headerTintColor: '#FCFAF8', // Set icon/text color in header
headerTitle: '', // Remove title for this screen
}}
/>
{/* Add new announcement screen */}
<Stack.Screen
name="AddAnnouncement"
component={AddAnnouncement}
options={{
headerStyle: {
backgroundColor: '#304067', // Toolbar background color
},
headerTintColor: '#FCFAF8', // Set toolbar icon color
headerTitle: '', // Remove title from the header for this screen
}}
/>
</Stack.Navigator>
{/* Toast messages across the app */}
<Toast ref={(ref) => Toast.setRef(ref)} />
</NavigationContainer>
</EventProvider>
);
}
// Styles for the custom drawer logo container and logo itself
const styles = StyleSheet.create({
logoContainer: {
alignItems: 'center',
marginVertical: 20, // Space above and below the logo
},
logo: {
width: 150, // Set width of the logo
height: 150, // Set height of the logo
resizeMode: 'contain', // Ensure the image doesn't stretch
},
});