From c830e368fea94308c4e8bc0dd49e2d070610ac12 Mon Sep 17 00:00:00 2001 From: Darkeye14 Date: Thu, 14 Nov 2024 23:33:46 +0530 Subject: [PATCH] Bug: App does not navigate to home screen after a successful login --- .../com/mifos/mifosxdroid/AndroidClient.kt | 9 ++++++- .../mifosxdroid/navigation/HomeNavigation.kt | 2 +- .../navigation/PasscodeNavGraph.kt | 24 +++++++++++++++---- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt index adf72a8324..ca760295c0 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt @@ -2,14 +2,18 @@ package com.mifos.mifosxdroid import androidx.compose.runtime.Composable import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import com.mifos.feature.auth.navigation.authNavGraph import com.mifos.feature.auth.navigation.navigateToLogin import com.mifos.feature.splash.navigation.SplashScreens import com.mifos.feature.splash.navigation.splashNavGraph +import com.mifos.mifosxdroid.navigation.HomeNavigation +import com.mifos.mifosxdroid.navigation.MifosNavGraph import com.mifos.mifosxdroid.navigation.homeGraph import com.mifos.mifosxdroid.navigation.navigateHome import com.mifos.mifosxdroid.navigation.passcodeNavGraph +import org.mifos.library.passcode.navigateToPasscodeScreen @Composable fun AndroidClient() { @@ -30,11 +34,14 @@ fun AndroidClient() { ) authNavGraph( - navigatePasscode = {}, + navigatePasscode = navController::navigateToPasscodeScreen, navigateHome = navController::navigateHome, updateServerConfig = {} ) + composable(MifosNavGraph.MAIN_GRAPH){ + HomeNavigation() + } homeGraph() } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeNavigation.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeNavigation.kt index 27a7c173a5..fc367a56a4 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeNavigation.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeNavigation.kt @@ -285,4 +285,4 @@ fun HomeNavigation() { Navigation(navController = navController, padding = paddingValues) } } -} \ No newline at end of file +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/PasscodeNavGraph.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/PasscodeNavGraph.kt index bc9a7e01d6..8d1ccb12f7 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/PasscodeNavGraph.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/PasscodeNavGraph.kt @@ -9,8 +9,11 @@ */ package com.mifos.mifosxdroid.navigation +import androidx.navigation.NavController +import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.NavGraphBuilder import androidx.navigation.NavHostController +import androidx.navigation.navOptions import androidx.navigation.navigation import org.mifos.library.passcode.PASSCODE_SCREEN import org.mifos.library.passcode.passcodeRoute @@ -23,20 +26,33 @@ internal fun NavGraphBuilder.passcodeNavGraph(navController: NavHostController) passcodeRoute( onForgotButton = { navController.popBackStack() - navController.navigate(MifosNavGraph.MAIN_GRAPH) + navController.navigateToMainGraph() }, onSkipButton = { navController.popBackStack() - navController.navigate(MifosNavGraph.MAIN_GRAPH) + navController.navigateToMainGraph() }, onPasscodeConfirm = { navController.popBackStack() - navController.navigate(MifosNavGraph.MAIN_GRAPH) + navController.navigateToMainGraph() }, onPasscodeRejected = { navController.popBackStack() - navController.navigate(MifosNavGraph.MAIN_GRAPH) + navController.navigateToMainGraph() }, ) } } +fun NavController.navigateToMainGraph(){ + val options = navOptions { + popUpTo(graph.findStartDestination().id) { + saveState = false + } + launchSingleTop = true + restoreState = false + } + navigate(MifosNavGraph.MAIN_GRAPH , options) + + + +}