1
+ // App.js, entry point into the app
1
2
// Import necessary hooks and modules from React, React Native, and other dependencies.
2
3
import React , { useEffect , useContext , useState } from 'react' ;
3
4
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' ;
7
8
import { BLEProvider } from './BLEContext' ;
8
9
import ThemeContext from './ThemeContext' ;
9
10
10
-
11
+ /**
12
+ * ThemeAwareStatusBar is a functional component that adjusts the status bar
13
+ * appearance based on the current theme (dark or light).
14
+ */
11
15
const ThemeAwareStatusBar = ( ) => {
12
16
const { theme } = useContext ( ThemeContext ) ;
13
17
@@ -23,13 +27,13 @@ const App = () => {
23
27
const [ loading , setLoading ] = useState ( true ) ;
24
28
const { theme } = useContext ( ThemeContext ) ;
25
29
26
-
27
- // Use the useEffect hook to request necessary permissions upon app initialization.
30
+ // useEffect hook to request necessary permissions upon app initialization.
28
31
useEffect ( ( ) => {
29
-
30
32
const requestBluetoothPermissions = async ( ) => {
31
33
try {
32
34
// Check the platform and version to request appropriate permissions.
35
+ // Android permissions defined in AndroidManifest.xml
36
+ // iOS permissions defined in Info.plist
33
37
if ( Platform . OS === 'android' && Platform . Version >= 31 ) {
34
38
// For Android 12 (API level 31) and above, request multiple permissions including
35
39
// location access, Bluetooth scan, and Bluetooth connect.
@@ -39,22 +43,21 @@ const App = () => {
39
43
PermissionsAndroid . PERMISSIONS . BLUETOOTH_CONNECT ,
40
44
] ) ;
41
45
console . log ( 'Permissions status:' , permissionsStatus ) ;
46
+ // Check if all permissions are granted
42
47
permissionsGranted = Object . values ( permissionsStatus ) . every ( status => status === PermissionsAndroid . RESULTS . GRANTED ) ;
43
48
} else if ( Platform . OS === 'android' && Platform . Version >= 23 ) {
44
49
// For Android 6 (Marshmallow, API level 23) to Android 11, request location permission.
45
50
// This is necessary for Bluetooth scanning due to the need to access location information.
46
51
const locationPermissionStatus = await PermissionsAndroid . request (
47
52
PermissionsAndroid . PERMISSIONS . ACCESS_FINE_LOCATION
48
53
) ;
49
- // Log the outcome of the permission request.
50
54
if ( locationPermissionStatus === PermissionsAndroid . RESULTS . GRANTED ) {
51
55
console . log ( 'Location permission granted' ) ;
52
56
} else {
53
57
console . log ( 'Location permission denied' ) ;
54
58
}
55
59
}
56
60
} catch ( err ) {
57
- // Catch and log any errors that occur during the permission request process.
58
61
console . warn ( err ) ;
59
62
}
60
63
setLoading ( ! permissionsGranted ) ;
@@ -63,6 +66,7 @@ const App = () => {
63
66
requestBluetoothPermissions ( ) ;
64
67
} , [ ] ) ;
65
68
69
+ // Render a loading indicator while waiting for permissions
66
70
if ( loading ) {
67
71
return (
68
72
< View style = { [ styles . container , { backgroundColor : theme ?. backgroundColor || '#FFF' } ] } >
@@ -73,6 +77,7 @@ const App = () => {
73
77
) ;
74
78
}
75
79
80
+ // Main app content, wrapped with providers for BLE, theming, and navigation
76
81
return (
77
82
< BLEProvider >
78
83
< ThemeProvider >
0 commit comments