Skip to content

Commit d9cf7b6

Browse files
committed
added comments for clarity
2 parents 49cdd71 + c9d0e7e commit d9cf7b6

17 files changed

+762
-751
lines changed

ADPCMobileApp_v2.0/App.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
// App.js, entry point into the app
12
// Import necessary hooks and modules from React, React Native, and other dependencies.
23
import React, { useEffect, useContext, useState } from 'react';
34
import { PermissionsAndroid, Platform, StatusBar, StyleSheet, ActivityIndicator, View, Text } from 'react-native';
4-
import { NavigationContainer } from '@react-navigation/native'; // For managing navigation.
5-
import AppNavigation from './AppNavigation'; // Custom navigation setup.
6-
import ThemeProvider from './ThemeProvider'; // Provides theming capabilities.
5+
import { NavigationContainer } from '@react-navigation/native';
6+
import AppNavigation from './AppNavigation';
7+
import ThemeProvider from './ThemeProvider';
78
import { BLEProvider} from './BLEContext';
89
import ThemeContext from './ThemeContext';
910

10-
11+
/**
12+
* ThemeAwareStatusBar is a functional component that adjusts the status bar
13+
* appearance based on the current theme (dark or light).
14+
*/
1115
const ThemeAwareStatusBar = () => {
1216
const { theme } = useContext(ThemeContext);
1317

@@ -23,13 +27,13 @@ const App = () => {
2327
const [loading, setLoading] = useState(true);
2428
const { theme } = useContext(ThemeContext);
2529

26-
27-
// Use the useEffect hook to request necessary permissions upon app initialization.
30+
// useEffect hook to request necessary permissions upon app initialization.
2831
useEffect(() => {
29-
3032
const requestBluetoothPermissions = async () => {
3133
try {
3234
// Check the platform and version to request appropriate permissions.
35+
// Android permissions defined in AndroidManifest.xml
36+
// iOS permissions defined in Info.plist
3337
if (Platform.OS === 'android' && Platform.Version >= 31) {
3438
// For Android 12 (API level 31) and above, request multiple permissions including
3539
// location access, Bluetooth scan, and Bluetooth connect.
@@ -39,22 +43,21 @@ const App = () => {
3943
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
4044
]);
4145
console.log('Permissions status:', permissionsStatus);
46+
// Check if all permissions are granted
4247
permissionsGranted = Object.values(permissionsStatus).every(status => status === PermissionsAndroid.RESULTS.GRANTED);
4348
} else if (Platform.OS === 'android' && Platform.Version >= 23) {
4449
// For Android 6 (Marshmallow, API level 23) to Android 11, request location permission.
4550
// This is necessary for Bluetooth scanning due to the need to access location information.
4651
const locationPermissionStatus = await PermissionsAndroid.request(
4752
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
4853
);
49-
// Log the outcome of the permission request.
5054
if (locationPermissionStatus === PermissionsAndroid.RESULTS.GRANTED) {
5155
console.log('Location permission granted');
5256
} else {
5357
console.log('Location permission denied');
5458
}
5559
}
5660
} catch (err) {
57-
// Catch and log any errors that occur during the permission request process.
5861
console.warn(err);
5962
}
6063
setLoading(!permissionsGranted);
@@ -63,6 +66,7 @@ const App = () => {
6366
requestBluetoothPermissions();
6467
}, []);
6568

69+
// Render a loading indicator while waiting for permissions
6670
if (loading) {
6771
return (
6872
<View style={[styles.container, { backgroundColor: theme?.backgroundColor || '#FFF' }]}>
@@ -73,6 +77,7 @@ const App = () => {
7377
);
7478
}
7579

80+
// Main app content, wrapped with providers for BLE, theming, and navigation
7681
return (
7782
<BLEProvider>
7883
<ThemeProvider>

ADPCMobileApp_v2.0/AppNavigation.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Importing necessary React and React Navigation components and contexts.
22
import React, { useContext } from 'react';
33
import { createDrawerNavigator, DrawerContentScrollView, DrawerItemList } from '@react-navigation/drawer';
4+
// Importing screens that will be used in navigation.
45
import AboutScreen from './screens/AboutScreen';
56
import HomeScreen from './screens/HomeScreen';
67
import ThemeContext from './ThemeContext';
@@ -10,41 +11,40 @@ import DiscoverDevicesScreen from './screens/DiscoverDevicesScreen';
1011
import ManageConsentsScreen from './screens/ManageConsentsScreen';
1112
import HiddenStack from './HiddenStackNavigator';
1213

13-
14-
// Create a Drawer navigator instance.
14+
// DrawerNavigator resembles a "Burger Menu (Three horizontal bars)" in the UI
1515
const Drawer = createDrawerNavigator();
1616

1717
const AppNavigation = () => {
18-
// Access the current theme from ThemeContext to apply dynamic theming.
19-
const { theme } = useContext(ThemeContext);
2018

19+
const { theme } = useContext(ThemeContext);
2120
// Define a custom drawer content component to customize the appearance of the drawer.
2221
const CustomDrawerContent = (props) => {
2322
return (
2423
<DrawerContentScrollView {...props} style={{ backgroundColor: theme.backgroundColor }}>
2524
<DrawerItemList {...props}
26-
labelStyle={{ color: theme.textColor }} // Assuming you have a textColor in your theme
27-
activeTintColor={theme.textColor} // Use theme colors for active item label
28-
inactiveTintColor={theme.textColor} // Use theme colors for inactive item label
29-
activeBackgroundColor={theme.backgroundColor} // Use theme color for active item background
30-
itemStyle={{ backgroundColor: theme.backgroundColor }} // Use theme color for item background
25+
labelStyle={{ color: theme.textColor }}
26+
activeTintColor={theme.textColor}
27+
inactiveTintColor={theme.textColor}
28+
activeBackgroundColor={theme.backgroundColor}
29+
itemStyle={{ backgroundColor: theme.backgroundColor }}
3130
/>
3231
</DrawerContentScrollView>
3332
);
3433
};
3534

3635
return (
36+
// Drawer.Navigator setup with custom configurations for theming and the custom drawer content.
3737
<Drawer.Navigator
3838
screenOptions={{
3939
drawerLabelStyle: {
4040
color: theme.textColor,
4141
},
4242
headerStyle: {
43-
backgroundColor: theme.backgroundColor, // Apply background color from the theme for header
43+
backgroundColor: theme.backgroundColor,
4444
},
45-
headerTintColor: theme.textColor, // Apply text color from the theme for header text
45+
headerTintColor: theme.textColor,
4646
drawerStyle: {
47-
backgroundColor: theme.backgroundColor, // Apply background color from the theme for drawer
47+
backgroundColor: theme.backgroundColor,
4848
},
4949

5050

@@ -122,10 +122,11 @@ const AppNavigation = () => {
122122
},
123123
}}
124124
/>
125+
{/* HiddenStack is used for navigating to the device detail screen but is hidden from the drawer. */}
125126
<Drawer.Screen
126127
name="Device Details"
127128
component={HiddenStack}
128-
options={{ drawerItemStyle: { height: 0 } }}
129+
options={{ drawerItemStyle: { height: 0 } }} // Makes this navigation item not visible in the drawer.
129130
/>
130131
</Drawer.Navigator>
131132
);

0 commit comments

Comments
 (0)