-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
99 lines (87 loc) · 2.52 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
import { StatusBar } from 'expo-status-bar'
import React, { useContext, useEffect, useRef, useState } from 'react'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import useCachedResources from './hooks/useCachedResources'
import useColorScheme from './hooks/useColorScheme'
import Navigation from './navigation'
import AuthProvider, { AuthContext } from './context/authContext'
import Toast, { BaseToast, ErrorToast } from 'react-native-toast-message'
import socket from './utils/socket'
import Colors from './constants/Colors'
import { AppState } from 'react-native'
import { AuthContextType } from './types/auth'
export default function App() {
const isLoadingComplete = useCachedResources()
const colorScheme = useColorScheme()
const toastConfig = {
success: (props: any) => (
<BaseToast
{...props}
text1Style={{
fontSize: 17,
color: 'white'
}}
text2Style={{
fontSize: 14,
color: 'white'
}}
style={{ backgroundColor: Colors.primary, borderLeftColor: Colors.primary, height: 80, borderRadius: 15, marginTop: 20, width: '90%' }}
/>
),
error: (props: any) => (
<ErrorToast
{...props}
text1Style={{
fontSize: 17,
color: 'white'
}}
text2Style={{
fontSize: 14,
color: 'white'
}}
style={{ backgroundColor: Colors.error, borderLeftColor: Colors.error, height: 80, borderRadius: 15, marginTop: 20, width: '90%' }}
/>
),
}
const showToast = (type: 'success' | 'error' | 'info', text1: string, text2: string) => {
Toast.show({
type: type,
text1: text1,
text2: text2,
})
}
useEffect(() => {
socket.connect()
socket.on('connect', () => {
console.log('connect')
})
socket.on('disconnect', () => {
console.log('disconnected')
})
socket.on('error', (title: string, error: string) => {
showToast('error', title, error)
})
socket.on('info', (title: string, message: string) => {
showToast('success', title, message)
})
return () => {
socket.disconnect()
}
}, [])
if (!isLoadingComplete) {
return null
} else {
return (
<AuthProvider>
<SafeAreaProvider>
{true && <Navigation colorScheme={colorScheme} />}
<StatusBar style="light" />
<Toast
position="top"
config={toastConfig}
/>
</SafeAreaProvider>
</AuthProvider>
)
}
}