-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
42 lines (35 loc) · 1.12 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
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import { useEffect, useRef, useState } from "react";
import * as Notification from "expo-notifications";
import "./src/configs/notification";
export default function App() {
const notificationListener = useRef<Notification.Subscription>();
const [notification, setNotification] = useState<Notification.Notification>();
useEffect(() => {
notificationListener.current = Notification.addNotificationReceivedListener(
(notification) => {
setNotification(notification);
}
);
return () => {
Notification.removeNotificationSubscription(notificationListener.current);
};
});
return (
<View style={styles.container}>
<Text>App notificação</Text>
<Text>Titulo: {notification?.request.content.title}</Text>
<Text>Mensagem: {notification?.request.content.body}</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});