From ac5dcbe75106ce8571dbde2318025d5c483a5b5a Mon Sep 17 00:00:00 2001 From: Gauvain Date: Wed, 3 Jun 2026 23:59:17 +0200 Subject: [PATCH] feat(settings): gate notifications page behind OS permission --- .../(home)/settings/notifications/page.tsx | 57 +++++++++++-------- translations/en.json | 7 +-- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/app/(auth)/(tabs)/(home)/settings/notifications/page.tsx b/app/(auth)/(tabs)/(home)/settings/notifications/page.tsx index 8ba093d3d..7842ea40f 100644 --- a/app/(auth)/(tabs)/(home)/settings/notifications/page.tsx +++ b/app/(auth)/(tabs)/(home)/settings/notifications/page.tsx @@ -1,47 +1,54 @@ +import { Ionicons } from "@expo/vector-icons"; import * as Notifications from "expo-notifications"; import { t } from "i18next"; import { useEffect, useState } from "react"; -import { Linking, ScrollView, Switch } from "react-native"; +import { Linking, ScrollView, Switch, View } from "react-native"; +import { Button } from "@/components/Button"; +import { Text } from "@/components/common/Text"; import { ListGroup } from "@/components/list/ListGroup"; import { ListItem } from "@/components/list/ListItem"; import { useSettings } from "@/utils/atoms/settings"; export default function NotificationsPage() { const { settings, updateSettings } = useSettings(); - const [granted, setGranted] = useState(null); + const [perm, setPerm] = + useState(null); useEffect(() => { - Notifications.getPermissionsAsync().then((p) => setGranted(p.granted)); + Notifications.getPermissionsAsync().then(setPerm); }, []); const requestPermission = async () => { - const p = await Notifications.requestPermissionsAsync(); - setGranted(p.granted); - if (!p.granted) Linking.openSettings(); + const res = await Notifications.requestPermissionsAsync(); + setPerm(res); + // Only bounce to system settings when the OS will not prompt again. + if (!res.granted && res.canAskAgain === false) { + Linking.openSettings(); + } }; - if (!settings) return null; + if (!settings || perm === null) return null; + + if (!perm.granted) { + return ( + + + + {t("home.settings.notifications.disabled_title")} + + + {t("home.settings.notifications.disabled_description")} + + + + ); + } return ( - - - - +