From 1bfe894ae261bdb3185b22fbced32cda33a925d5 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 16 Oct 2026 18:48:13 +0200 Subject: [PATCH] Keep Home mounted when opening a link while the app is running (#12025) Co-authored-by: Claude Opus 5.5 --- src/Navigation.tsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 1416e5d91..0023f722b 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -13,6 +13,7 @@ import { createNavigationContainerRef, DarkTheme, DefaultTheme, + getActionFromState as getActionFromStateDefault, type LinkingOptions, NavigationContainer, StackActions, @@ -824,6 +825,19 @@ const FlatNavigator = ({ * to the navigation context. */ +/** + * `LINKING` has no `config`, so on its own `getActionFromState` doesn't know + * that Home is the HomeTab stack's initial route. For the [Home, screen] state + * that `getStateFromPath` builds for most links, it then resets the whole + * HomeTab stack, remounting Home and losing its feeds and scroll position. + * With this, a link opens the screen on top of the existing stack, or on top of + * Home if the stack hasn't mounted yet. It is defined at module scope so that + * `getActionFromState` can cache what it derives from it. + */ +const NATIVE_LINK_ACTION_CONFIG = { + screens: {HomeTab: {initialRouteName: 'Home'}}, +} + const LINKING = { // TODO figure out what we are going to use // note: `bluesky://` is what is used in app.config.js @@ -893,6 +907,13 @@ const LINKING = { return res } }, + + getActionFromState(state, options) { + return getActionFromStateDefault( + state, + IS_NATIVE ? NATIVE_LINK_ACTION_CONFIG : options, + ) + }, } satisfies LinkingOptions let didHandlePushNotificationEntry = false -- knotmirror 0.0.1