Skip to content

Add optional navGraphRoute parameter to sharedKoinViewModel for flexible navigation graph resolution#2262

Merged
arnaudgiuliani merged 1 commit intoInsertKoinIO:4.1.1from
rfaturriza:patch-1
Sep 2, 2025
Merged

Add optional navGraphRoute parameter to sharedKoinViewModel for flexible navigation graph resolution#2262
arnaudgiuliani merged 1 commit intoInsertKoinIO:4.1.1from
rfaturriza:patch-1

Conversation

@rfaturriza
Copy link
Copy Markdown
Contributor

@rfaturriza rfaturriza commented Jul 30, 2025

This PR introduces an overload for sharedKoinViewModel to allow an optional navGraphRoute parameter.

Motivation
The current implementation relies on destination.parent?.route which works for simple hierarchies. In more complex navigation setups (nested graphs, sibling graphs, multi-level NavHost), developers may need explicit control over which NavBackStackEntry to use.

Changes
• Added navGraphRoute parameter with default this.destination.parent?.route.
• Fallback to default koinViewModel() if navGraphRoute is null.

Example Usage

val vm: MyViewModel = navBackStackEntry.sharedKoinViewModel(
    navController = navController,
    navGraphRoute = "route_graph"
)

This improves flexibility without breaking existing API.

@rfaturriza
Copy link
Copy Markdown
Contributor Author

Related issue #2261 #2256

@arnaudgiuliani arnaudgiuliani self-requested a review September 2, 2025 16:12
@arnaudgiuliani arnaudgiuliani added this to the 4.1.1 milestone Sep 2, 2025
@arnaudgiuliani arnaudgiuliani added the status:accepted accepted to be developed label Sep 2, 2025
Copy link
Copy Markdown
Member

@arnaudgiuliani arnaudgiuliani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok 👍

@arnaudgiuliani arnaudgiuliani merged commit f5e6b04 into InsertKoinIO:4.1.1 Sep 2, 2025
@rfaturriza rfaturriza deleted the patch-1 branch September 3, 2025 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:accepted accepted to be developed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants