-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
72 lines (67 loc) · 2.05 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
import { StatusBar } from 'expo-status-bar'
import React, { useEffect, useRef } from 'react'
import { Provider as PaperProvider, configureFonts } from 'react-native-paper'
import { useFonts } from 'expo-font'
import {
NunitoSans_300Light,
NunitoSans_400Regular,
NunitoSans_600SemiBold,
NunitoSans_700Bold,
NunitoSans_800ExtraBold,
NunitoSans_900Black
} from '@expo-google-fonts/nunito-sans'
import AppLoading from 'expo-app-loading'
import { theme, fontConfig } from './theme'
import './src/i18n'
import { Routes } from './src/routes'
import { AuthProvider } from './src/context/AuthContext'
import * as Notifications from 'expo-notifications'
import { Subscription } from 'expo-modules-core'
import * as Linking from 'expo-linking'
export default function App(): React.ReactElement {
const [fontsLoaded, error] = useFonts({
NunitoSans_300Light,
NunitoSans_400Regular,
NunitoSans_600SemiBold,
NunitoSans_700Bold,
NunitoSans_800ExtraBold,
NunitoSans_900Black
})
const notificacaoAbertaListener = useRef<Subscription>()
useEffect(() => {
notificacaoAbertaListener.current =
Notifications.addNotificationResponseReceivedListener(response => {
// esse evento se ativa quando o usuário clica na notificação
try {
const { data } = response.notification.request.content
if (data) {
const link = data.link as string
if (link) {
const url = Linking.makeUrl(link, data.params)
Linking.openURL(url)
}
}
} catch (err) {
console.log(err)
}
})
return () => {
Notifications.removeNotificationSubscription(
notificacaoAbertaListener.current
)
}
}, [])
if (!fontsLoaded) {
return <AppLoading />
} else {
const themeWithFonts = { ...theme, fonts: configureFonts(fontConfig) }
return (
<PaperProvider theme={themeWithFonts}>
<StatusBar style="inverted" />
<AuthProvider>
<Routes />
</AuthProvider>
</PaperProvider>
)
}
}