From fd081d46a657059353bfb1e6022b68eedaee4e1a Mon Sep 17 00:00:00 2001 From: devthejo Date: Wed, 9 Jul 2025 17:50:07 +0200 Subject: [PATCH] feat(anchor): bglost notification scroll to permissions + wip --- ...actionOpenBackgroundGeolocationSettings.js | 23 ++++++++++++++ .../actions/actionOpenSettings.js | 17 +++++++++++ .../notifBackgroundGeolocationLost.js | 16 ++++++++-- src/notifications/notificationTypes.js | 5 +++- src/notifications/onEvent.js | 23 +++++++++++++- src/notifications/setActionCategories.js | 5 ++++ src/scenes/Params/View.js | 30 ++++++++++++++++--- 7 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 src/notifications/actions/actionOpenBackgroundGeolocationSettings.js diff --git a/src/notifications/actions/actionOpenBackgroundGeolocationSettings.js b/src/notifications/actions/actionOpenBackgroundGeolocationSettings.js new file mode 100644 index 0000000..4dab5b0 --- /dev/null +++ b/src/notifications/actions/actionOpenBackgroundGeolocationSettings.js @@ -0,0 +1,23 @@ +import { navActions } from "~/stores"; +import { createLogger } from "~/lib/logger"; +import { BACKGROUND_SCOPES } from "~/lib/logger/scopes"; + +const backgroundGeolocationLogger = createLogger({ + module: BACKGROUND_SCOPES.NOTIFICATIONS, + feature: "action-open-background-geolocation-settings", +}); + +export default function actionOpenBackgroundGeolocationSettings({ data }) { + backgroundGeolocationLogger.debug( + "actionOpenBackgroundGeolocationSettings called", + ); + + navActions.setNextNavigation([ + { + name: "Params", + params: { + anchor: "permissions", + }, + }, + ]); +} diff --git a/src/notifications/actions/actionOpenSettings.js b/src/notifications/actions/actionOpenSettings.js index 87fd5f8..a72e120 100644 --- a/src/notifications/actions/actionOpenSettings.js +++ b/src/notifications/actions/actionOpenSettings.js @@ -1,9 +1,26 @@ import { navActions } from "~/stores"; +import { createLogger } from "~/lib/logger"; +import { BACKGROUND_SCOPES } from "~/lib/logger/scopes"; + +const settingsLogger = createLogger({ + module: BACKGROUND_SCOPES.NOTIFICATIONS, + feature: "action-open-settings", +}); export default function actionOpenSettings({ data }) { + settingsLogger.debug("actionOpenSettings called", { + data, + hasData: !!data, + dataKeys: data ? Object.keys(data) : [], + }); + navActions.setNextNavigation([ { name: "Params", }, ]); + + settingsLogger.debug("Navigation set to Params screen", { + navigationTarget: "Params", + }); } diff --git a/src/notifications/channels/notifBackgroundGeolocationLost.js b/src/notifications/channels/notifBackgroundGeolocationLost.js index ad8c9f2..3adb897 100644 --- a/src/notifications/channels/notifBackgroundGeolocationLost.js +++ b/src/notifications/channels/notifBackgroundGeolocationLost.js @@ -21,6 +21,18 @@ export default async function notifBackgroundGeolocationLost(data) { }, ); + // DEBUG: Log notification configuration for diagnosis + backgroundGeolocationLogger.info( + "DEBUG: Background geolocation notification config", + { + channelId, + pressActionId: "open-settings", + launchActivity: "default", + hasData: !!data, + dataKeys: data ? Object.keys(data) : [], + }, + ); + // Generate notification content const { title, body, bigText } = generateBackgroundGeolocationLostContent(data); @@ -34,14 +46,14 @@ export default async function notifBackgroundGeolocationLost(data) { bigText, android: { pressAction: { - id: "open-settings", + id: "open-background-geolocation-settings", launchActivity: "default", }, actions: [ { title: "Paramètres", pressAction: { - id: "open-settings", + id: "open-background-geolocation-settings", launchActivity: "default", }, }, diff --git a/src/notifications/notificationTypes.js b/src/notifications/notificationTypes.js index 131c710..bfbcbd4 100644 --- a/src/notifications/notificationTypes.js +++ b/src/notifications/notificationTypes.js @@ -84,10 +84,13 @@ export const createNotificationHandlers = (handlers) => { suggest_keep_open: async (data) => await openAlert({ data }), relative_invitation: async (data) => await openRelatives({ data }), relative_allow_ask: async (data) => await openRelatives({ data }), - background_geolocation_lost: async (data) => { + background_geolocation_lost: async (_data) => { navActions.setNextNavigation([ { name: "Params", + params: { + anchor: "permissions", + }, }, ]); }, diff --git a/src/notifications/onEvent.js b/src/notifications/onEvent.js index 459f7b4..3a83d4d 100644 --- a/src/notifications/onEvent.js +++ b/src/notifications/onEvent.js @@ -15,6 +15,7 @@ import actionRelativeAllowReject from "./actions/actionRelativeAllowReject"; import actionRelativeInvitationAccept from "./actions/actionRelativeInvitationAccept"; import actionRelativeInvitationReject from "./actions/actionRelativeInvitationReject"; import actionOpenSettings from "./actions/actionOpenSettings"; +import actionOpenBackgroundGeolocationSettings from "./actions/actionOpenBackgroundGeolocationSettings"; import { navActions } from "~/stores"; @@ -97,11 +98,12 @@ export const onNotificationOpenedAppEvent = async (remoteMessage) => { // return; // } try { - eventLogger.info("Processing background notification tap", { + eventLogger.debug("Processing background notification tap", { messageId: remoteMessage?.messageId, data: remoteMessage?.data, notification: remoteMessage?.notification, clickAction: remoteMessage?.notification?.android?.clickAction, + notificationType: remoteMessage?.data?.type || "unknown", }); if (!remoteMessage?.notification) { @@ -275,8 +277,27 @@ export const onEvent = async ({ type, notification, pressAction }) => { break; } case "open-settings": { + eventLogger.debug("Processing open-settings action", { + data, + actionId, + notificationId: notification?.id, + launchActivity: pressAction?.launchActivity, + }); await actionOpenSettings({ data }); break; } + case "open-background-geolocation-settings": { + eventLogger.debug( + "Processing open-background-geolocation-settings action", + { + data, + actionId, + notificationId: notification?.id, + launchActivity: pressAction?.launchActivity, + }, + ); + await actionOpenBackgroundGeolocationSettings({ data }); + break; + } } }; diff --git a/src/notifications/setActionCategories.js b/src/notifications/setActionCategories.js index 0b99cfd..92b9896 100644 --- a/src/notifications/setActionCategories.js +++ b/src/notifications/setActionCategories.js @@ -123,6 +123,11 @@ export default async function setActionCategories() { title: "Paramètres", foreground: true, }, + { + id: "open-background-geolocation-settings", + title: "Paramètres", + foreground: true, + }, ], }, ]); diff --git a/src/scenes/Params/View.js b/src/scenes/Params/View.js index 3c89035..e3a9148 100644 --- a/src/scenes/Params/View.js +++ b/src/scenes/Params/View.js @@ -1,5 +1,5 @@ -import React from "react"; -import { View, ScrollView } from "react-native"; +import React, { useCallback, useRef } from "react"; +import { View, ScrollView, InteractionManager } from "react-native"; import { createStyles } from "~/theme"; import ParamsNotifications from "./Notifications"; import ParamsRadius from "./Radius"; @@ -7,12 +7,34 @@ import ParamsEmergencyCall from "./EmergencyCall"; import ThemeSwitcher from "./ThemeSwitcher"; import Permissions from "./Permissions"; import SentryOptOut from "./SentryOptOut"; +import { useRoute, useFocusEffect } from "@react-navigation/native"; export default function ParamsView({ data }) { const styles = useStyles(); + const scrollRef = useRef(null); + const { params } = useRoute(); + const didScroll = useRef(false); + + const recordLayout = useCallback( + (key) => + ({ + nativeEvent: { + layout: { y }, + }, + }) => { + if (didScroll.current || params?.anchor !== key) return; + + InteractionManager.runAfterInteractions(() => { + scrollRef.current?.scrollTo({ y, animated: true }); + didScroll.current = true; + }); + }, + [params?.anchor], + ); + return ( - + @@ -29,7 +51,7 @@ export default function ParamsView({ data }) { - +