-
Notifications
You must be signed in to change notification settings - Fork 676
Fix cross-graph navigation crash by hoisting events to root controller #2589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cross-graph navigation crash by hoisting events to root controller #2589
Conversation
📝 WalkthroughWalkthroughAdded a new callback parameter Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 🧪 Unit Test Generation v2 is now available!We have significantly improved our unit test generation capabilities. To enable: Add this to your reviews:
finishing_touches:
unit_tests:
enabled: trueTry it out by using the Have feedback? Share your thoughts on our Discord thread! Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavbarNavigationScreen.kt (1)
380-396: HoistmoreClientInfocallback to root scope, similar toonMoreInfoClickedfix.The
moreClientInfocallback (lines 382-387) also navigates to the DataTable route using the nestednavController, which will cause the sameIllegalArgumentExceptionas the originalonMoreInfoClickedissue. It should be hoisted to the root navigation scope and passed down, matching the fix pattern applied toonMoreInfoClicked.feature/client/src/commonMain/kotlin/com/mifos/feature/client/navigation/ClientNavigation.kt (1)
362-368: AddloadMoreSavingsAccountInfocallback parameter toclientNavGraphfor consistent navigation pattern.The
savingsDestinationat line 365 usesnavController::navigateToDataTabledirectly, inconsistent with howloanDestinationhandles the same scenario via theonMoreInfoClickedcallback parameter. This creates a nested NavController issue: if the DataTable route is registered only in the root NavHost, navigation from the savings screen will fail withIllegalArgumentException.Add a
loadMoreSavingsAccountInfo: (String, Int) -> Unitcallback parameter toclientNavGraph(matching the pattern used foronMoreInfoClickedinloanDestination), and pass it through tosavingsDestinationinstead of the direct method reference.
🧹 Nitpick comments (3)
cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavbarNavigationScreen.kt (2)
110-119: Parameter ordering: required parameter after optional one.
onMoreInfoClickedis a required parameter but is positioned afternavControllerwhich has a default value. In Kotlin, required parameters should typically precede optional ones to allow callers to use positional arguments naturally. Also, there's inconsistent spacing (:vs:) with the colon.Suggested reordering and spacing fix
`@Composable` internal fun AuthenticatedNavbarNavigationScreen( navigateToDocumentScreen: (Int, String) -> Unit, onDrawerItemClick: (String) -> Unit, + onMoreInfoClicked: (String, Int) -> Unit, modifier: Modifier = Modifier, navController: NavHostController = rememberMifosNavController( name = "AuthenticatedNavbarScreen", ), - onMoreInfoClicked : (String, Int) -> Unit, viewModel: AuthenticatedNavbarNavigationViewModel = koinViewModel(), ) {
183-191: Same parameter ordering and spacing issue.For consistency,
onMoreInfoClickedshould be moved before optional parameters and the spacing should be normalized to match other parameters.Suggested fix
`@Composable` internal fun AuthenticatedNavbarNavigationScreenContent( navController: NavHostController, onDrawerItemClick: (String) -> Unit, navigateToDocumentScreen: (Int, String) -> Unit, + onMoreInfoClicked: (String, Int) -> Unit, + onAction: (AuthenticatedNavBarAction) -> Unit, modifier: Modifier = Modifier, snackbarHostState: SnackbarHostState = remember { SnackbarHostState() }, - onMoreInfoClicked : (String, Int) -> Unit, - onAction: (AuthenticatedNavBarAction) -> Unit, ) {cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavbarRoute.kt (1)
25-36: Minor: Missing space after comma in type signature.The type signature
(String,Int)at line 28 is missing a space after the comma. For consistency with Kotlin style conventions and other files in this PR, it should be(String, Int).Suggested fix
internal fun NavGraphBuilder.authenticatedNavbarGraph( onDrawerItemClick: (String) -> Unit, navigateToDocumentScreen: (Int, String) -> Unit, - onMoreInfoClicked : (String,Int) -> Unit, + onMoreInfoClicked: (String, Int) -> Unit, ) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Fixes a crash (IllegalArgumentException) caused by navigating to the Data Table screen from within a nested (tab) NavController by hoisting the navigation event to the root graph.
Changes:
- Added an
onMoreInfoClickedcallback toclientNavGraphso Data Table navigation can be executed by the parent/rootNavController. - Threaded
onMoreInfoClickedthroughauthenticatedNavbarGraphandAuthenticatedNavbarNavigationScreento bridge nested and root navigation graphs. - Updated the loan destination wiring to use the hoisted callback instead of
navController::navigateToDataTable.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| feature/client/src/commonMain/kotlin/com/mifos/feature/client/navigation/ClientNavigation.kt | Adds onMoreInfoClicked to the client nav graph and routes loan “More Info” through it. |
| cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavigation.kt | Supplies the root navigateToDataTable callback into the authenticated navbar graph. |
| cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavbarRoute.kt | Extends navbar graph API to accept and forward onMoreInfoClicked. |
| cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavbarNavigationScreen.kt | Hoists and passes the callback down into the nested client navigation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavbarRoute.kt
Outdated
Show resolved
Hide resolved
...on/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavbarNavigationScreen.kt
Show resolved
Hide resolved
cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavigation.kt
Show resolved
Hide resolved
1f5476b to
114672b
Compare
…x crash fix(feature/client) : hoist data table navigation to root graph to fix crash
114672b to
73b5ac6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavbarNavigationScreen.kt (1)
380-388:⚠️ Potential issue | 🟠 MajorRoute DataTable navigation through the root controller.
moreClientInfostill callsnavController.navigateToDataTablefrom the nested NavHost; if the DataTable destination lives only in the root graph (per the PR objective), this path can still crash. Consider delegating toonMoreInfoClicked(root nav) instead.✅ Proposed fix
clientNavGraph( navController = navController, moreClientInfo = { clientId -> - navController.navigateToDataTable( - Constants.DATA_TABLE_NAME_CLIENT, - clientId, - ) + onMoreInfoClicked( + Constants.DATA_TABLE_NAME_CLIENT, + clientId, + ) }, onMoreInfoClicked = onMoreInfoClicked, activateClient = { clientId -> navController.navigateToActivateRoute( clientId, Constants.ACTIVATE_CLIENT, ) }, hasDatatables = navController::navigateDataTableList, )
biplab1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. This can be merged.
Fixes - Jira-#MIFOSAC-638
Description
This PR fixes a runtime crash occurring when attempting to navigate from the Client/Loan screen (inside the authenticated tabs) to the Data Table screen.
The Problem (Root Cause)
The app uses a nested navigation structure:
AuthenticatedNavbarandDataTable.AuthenticatedNavbar(includingClientNavGraph).The crash (
java.lang.IllegalArgumentException) occurred because we were triggering navigation toDataTableRouteusing the nestedNavController. SinceDataTableRouteis only registered in the RootNavHost, the nested controller could not resolve the destination and crashed.Behavior Changes
loanbef.webm
loanaft.webm
The Solution
I applied the Event Hoisting pattern to bridge the two navigation graphs:
clientNavGraphto expose a lambda callback (onMoreInfoClicked) instead of accepting aNavControllerto perform the navigation directly.AuthenticatedNavbarNavigationScreen).authenticatedNavbarGraph(the parent), where the RootNavControlleris available.Changes
authenticatedNavbarGraphto acceptonMoreInfoClicked.navController::navigateToDataTableinto the graph at the root level.Verification
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.