Skip to content
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

ResultNavigator in netted graphs #716

Open
jorgepayrillium opened this issue Jan 17, 2025 · 0 comments
Open

ResultNavigator in netted graphs #716

jorgepayrillium opened this issue Jan 17, 2025 · 0 comments

Comments

@jorgepayrillium
Copy link

I have a HomeScreen(mainGraph) and FilterScreen(rootGraph). I need get result back to MainScreen. Here is what i have:

class RootDestinationsNavigator(value: DestinationsNavigator = FakeNavigator()) : DestinationsNavigator by value

class ParentBackNavigator(navigator: ResultBackNavigator) : ResultBackNavigator by navigator

@destination
@composable
fun MainScreen(
rootNavController: NavController,
backNavigator: ResultBackNavigator
) {
val navController = rememberNavController() // 👉this will be bottomBar's NavController
DestinationsNavHost(
defaultTransitions = DefaultSlideAnimation,
navGraph = NavGraphs.main,
navController = navController,
dependenciesContainerBuilder = {
// 👉 pass it to all destinations of bottomBar who need it
dependency(RootDestinationsNavigator(rootNavController.rememberDestinationsNavigator()))
dependency(ParentBackNavigator(backNavigator))
}
)
}

@destination
@composable
fun FilterScreen(
resultNavigator: ParentBackNavigator,
viewModel: FilterViewModel = koinViewModel()
) {..}

@destination(start = true)
@composable
fun HomeScreen(
rootDestinationsNavigator: RootDestinationsNavigator,
resultContract: ResultRecipient<FilterScreenDestination, Boolean>,
viewModel: HomeViewModel = koinViewModel()
) {
resultContract.onResult {
if (it)
viewModel.refresh()
}}

I get error on compile time "IllegalDestinationsSetup: Composable 'FilterScreen' must receive a ResultBackNavigator of type 'Boolean' in order to be used as result originator for 'HomeScreen"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant