-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
206 lines (195 loc) · 7.51 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
import WaitScreen from './src/screens/WaitScreen'
global.Buffer = require('buffer').Buffer
import { createContext, useContext, useEffect } from 'react'
import { NavigationContainer } from '@react-navigation/native'
import { createNativeStackNavigator } from '@react-navigation/native-stack'
import { PaperProvider } from 'react-native-paper'
import WelcomeScreen from './src/screens/WelcomeScreen'
import TabNavigator from './src/components/TabNavigator'
import LoginScreen from './src/screens/LoginScreen'
import SignupScreen from './src/screens/SignupScreen'
import theme from './src/theme'
import type { NativeStackScreenProps } from '@react-navigation/native-stack'
import ConnectScreen from './src/screens/ConnectScreen'
import WifiScreen from './src/screens/WifiScreen'
import { AuthProvider, useAuth } from './src/providers/AuthProvider'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { QueryClientProvider, QueryClient } from '@tanstack/react-query'
import { Device } from './src/models/device.type'
import SensorScreen from './src/screens/SensorScreen'
import { PermissionsAndroid, Platform, StatusBar } from 'react-native'
import type { StatusBarStyle } from 'react-native'
const queryClient = new QueryClient()
export type StackParamList = {
Welcome: undefined
Login: undefined
Signup: undefined
Tabs: undefined
Wifi: undefined
Connect: undefined
Devices: undefined
Sensor: { device: Device } | undefined
Wait: { device: Device } | undefined
}
const Stack = createNativeStackNavigator<StackParamList>()
const Navigation = () => {
const { authState } = useAuth()
useEffect(() => {
// BleManager.enableBluetooth().then(() => {
// console.log('Bluetooth is turned on!')
// })
if (Platform.OS === 'android' && Platform.Version >= 23) {
PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
).then(result => {
if (result) {
console.log('Permission is OK')
} else {
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
).then(result => {
if (result) {
console.log('User accept')
} else {
console.log('User refuse')
}
})
}
})
PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.NEARBY_WIFI_DEVICES
).then(result => {
if (result) {
console.log('Permission is OK')
} else {
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.NEARBY_WIFI_DEVICES
).then(result => {
if (result) {
console.log('User accept')
} else {
console.log('User refuse')
}
})
}
})
PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN
).then(result => {
if (result) {
console.log('Permission is OK')
} else {
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN
).then(result => {
if (result) {
console.log('User accept')
} else {
console.log('User refuse')
}
})
}
})
PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT
).then(result => {
if (result) {
console.log('Permission is OK')
} else {
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT
).then(result => {
if (result) {
console.log('User accept')
} else {
console.log('User refuse')
}
})
}
})
}
}, [])
return (
<NavigationContainer>
<StatusBar barStyle='dark-content' />
<Stack.Navigator>
{authState?.authenticated ? (
<>
<Stack.Screen
name='Tabs'
component={TabNavigator}
options={{
headerBackVisible: false,
headerShown: false,
}}
/>
<Stack.Screen
name='Connect'
component={ConnectScreen}
options={{
title: 'Połącz z urządzeniem',
headerShown: false,
}}
/>
<Stack.Screen
name='Wifi'
component={WifiScreen}
options={{
title: 'Wybierz sieć WiFi',
headerShown: false,
}}
/>
<Stack.Screen
name='Sensor'
component={SensorScreen}
options={{
title: 'Wybierz sieć WiFi',
headerShown: false,
}}
/>
<Stack.Screen
name='Wait'
component={WaitScreen}
options={{
title: 'Wybierz sieć WiFi',
headerShown: false,
}}
/>
</>
) : (
<>
<Stack.Screen
name='Welcome'
component={WelcomeScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name='Login'
component={LoginScreen}
options={{ title: 'Zaloguj się' }}
/>
<Stack.Screen
name='Signup'
component={SignupScreen}
options={{ title: 'Zarejestruj się' }}
/>
</>
)}
</Stack.Navigator>
</NavigationContainer>
)
}
function App() {
return (
<AuthProvider>
<QueryClientProvider client={queryClient}>
<SafeAreaProvider>
<PaperProvider theme={theme}>
<Navigation />
</PaperProvider>
</SafeAreaProvider>
</QueryClientProvider>
</AuthProvider>
)
}
export default App