import { StyleSheet, ScrollView, KeyboardAvoidingView, } from "react-native"; import { Text } from "@/components/ui/Text"; import { useState, useEffect } from "react"; import * as Notifications from "expo-notifications"; import { useLocalSearchParams } from "expo-router"; import { StatusBar } from "expo-status-bar"; import { SafeAreaView } from "react-native-safe-area-context"; import { Colors, Spacing } from "@/constants/theme"; import { Card } from "@/components/ui/Cards"; import { Section, SectionHeader } from "@/components/ui/Sections"; type NotificationParams = { title?: string; body?: string; notificationId?: string; }; type ReceivedNotification = { title?: string; body?: string; }; export default function NotificationsPage() { const params = useLocalSearchParams(); const [liveNotification, setLiveNotification] = useState(null); useEffect(() => { const sub = Notifications.addNotificationReceivedListener((n) => { setLiveNotification({ title: n.request.content.title ?? undefined, body: n.request.content.body ?? undefined, }); }); return () => sub.remove(); }, []); const displayed = liveNotification ?? (params.title || params.body ? { title: params.title, body: params.body } : null); return (
{displayed ? ( Title: {displayed.title} Body: {displayed.body} ) : ( Nenhuma notificação recebida. )}
); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: Colors.light.background, }, keyboardView: { flex: 1, }, scrollContainer: { flexGrow: 1, paddingHorizontal: 24, justifyContent: "flex-start", minHeight: "100%", }, header: { alignItems: "flex-start", marginBottom: 40, }, });