Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: fix back navigation on first app launch

Ammar Ahmed4b35f2ecd28a
diff --git a/apps/mobile/app/components/auth/common.js b/apps/mobile/app/components/auth/common.js
index df2a4096b..42bfba88c 100644
--- a/apps/mobile/app/components/auth/common.js
+++ b/apps/mobile/app/components/auth/common.js
@@ -33,6 +33,9 @@ export function hideAuth() {
eSendEvent(eCloseLoginDialog);
if (initialAuthMode.current === AuthMode.welcomeSignup) {
Navigation.replace("FluidPanelsView");
+ setTimeout(() => {
+ Navigation.resetRootState();
+ }, 300);
} else {
Navigation.goBack();
}
diff --git a/apps/mobile/app/components/auth/index.js b/apps/mobile/app/components/auth/index.js
index cbfdfd499..25e37f66c 100644
--- a/apps/mobile/app/components/auth/index.js
+++ b/apps/mobile/app/components/auth/index.js
@@ -89,6 +89,9 @@ const Auth = ({ navigation, route }) => {
onPress={() => {
if (initialAuthMode.current === 2) {
Navigation.replace("FluidPanelsView");
+ setTimeout(() => {
+ Navigation.resetRootState();
+ }, 300);
} else {
Navigation.goBack();
}
diff --git a/apps/mobile/app/services/navigation.ts b/apps/mobile/app/services/navigation.ts
index 2303f02ca..bdcecb3be 100755
--- a/apps/mobile/app/services/navigation.ts
+++ b/apps/mobile/app/services/navigation.ts
@@ -166,6 +166,20 @@ function closeDrawer() {
fluidTabsRef.current?.closeDrawer();
}
+function resetRootState() {
+ const state = rootNavigatorRef.getState();
+ const focusedRouteKey = state.routes[state.index].key;
+ const routes = state.routes.filter(
+ (route) => route.name !== "Auth" && route.name !== "Welcome"
+ );
+ const newIndex = routes.findIndex((route) => route.key === focusedRouteKey);
+ rootNavigatorRef.reset({
+ ...state,
+ routes: routes,
+ index: newIndex
+ });
+}
+
const Navigation = {
navigate,
goBack,
@@ -177,7 +191,8 @@ const Navigation = {
queueRoutesForUpdate,
routeNeedsUpdate,
routeNames,
- routeUpdateFunctions
+ routeUpdateFunctions,
+ resetRootState
};
export default Navigation;