Closed javierpe closed 2 years ago
This is not possible because the navigator contains the NavController instance which shouldn’t be referenced by any component with a bigger lifecycle than the Activity or you will leak it.
Also just wanna point out that you can navigate with NavController itself and pass it into DestinationsNavHost. This allows you to navigate at the top level and not just inside the destinations. Not sure if this solves your issue partly.
Other than that, you can probably create some kind of singleton event publisher that can be injected anywhere and listen for its events right above calling DestinationsNavHost. Then you make the actual navigation there.
I’ll close this but I’m happy to keep talking below!
Yes, it can be dangerous not to manage the injection of the Destinations resource well, although I think I can only assign a scope to the Hilt instance 🤔 (I will do some tests).
So far I have integrated it into a open source project that I am working with SDUI and I am delighted, I have completely eliminated an entire module!
Everything is like magic, thanks for this library. As a proposal I would like not to depend on DestinationsNavHost to be able to extract DestinationsNavigator, if this happens I could navigate from any site injecting it with HIlt and not only composable functions. This could help to have unit tests for navigation...