Comments (7)
I see. At the moment, I think CompositionLocal is the correct solution for you then.
// top level
val LocalNavigator = compositionLocalOf<Navigator> { error("No LocalNavigator was provided") }
// inside your Activities or every time you need to provide a different Navigator instance
CompositionLocalProvider(LocalNavigator provides myNavigator) {
// ... Content goes here , for example your DestinationsNavHost call
// This part of Composition will see the `myNavigator` instance
// when accessing LocalNavigator.current
}
// then in your screens:
@Destination
@Composable
fun MyScreen(
navigator: Navigator = LocalNavigator.current
) {
navigator.navigate//...
}
This specific code was not tested, so take it with a grain of salt.
from compose-destinations.
Sounds, good! Thank you for the help and the nice library.
from compose-destinations.
@Rawa I brought back Dependencies container feature. It was helpful for multi-module too.
It was also improved.
So in case you prefer using that over CompositionLocals (which have the issue of creating implicit dependencies that all children Composables can also access), you can migrate to it :)
from compose-destinations.
Hi @Rawa !
Thanks for opening the issue 👍
So yeah this was a conscious decision. The reason is that container was a bit awkward to send specific things like lambdas and "Composable runtime stuff" (for example if you wanted to pass State<Something>
it wouldn't work as expected ).
I thought about keeping both solutions where the container could be used for general components that you want to pass to a lot of composables and keep the manual calls in case there is a specific Screen that you need something else, BUT, I was afraid that would increase the complexity of the APIs and have at most some very niche actual use cases. Especially because both things intersect with CompositionLocal in some use cases.
So basically I figured between calling manually and CompositionLocal, all cases would be solved without increasing complexity unnecessarily.
That said, have you looked into CompositionLocal to pass stuff to your screens? If there are components that all or most of your screens need, maybe that could be a good solution for you.
In the end, I still don't have a final decision. If I see enough people wanting the DestinationDependenciesContainer
back, I can totally bring it back easily.
Hope this helps at least explain my thought process, and please let me know if CompositionLocal or manually calling your composables is an ok solution for you.
from compose-destinations.
@raamcosta Thanks for the detailed reply, I understand your line of thinking, and also agree that is most cases is solved by other alternatives. In general I don't believe one should pass around State<Something>
, but I see your point since it can snowball away into a DI framework.
In my case the component I want to provide to the composable is a activity navigator, similar to a destinations navigator but it helps me with logic navigate to another activity. Currently I could inject this into the view model to solve it or cast activity and then grab it, but it feels more like it is a implementation detail that the view should handle. Unfortunately I don't think a LocalComposition would help in this case, but feel free to correct me if you think I'm wrong.
from compose-destinations.
Closing this, let me know if there is anything I can help with.
from compose-destinations.
Thanks!
from compose-destinations.
Related Issues (20)
- Deeplink pattern
- Nested Graph Problem HOT 5
- popUpTo will not pop up Destination inside NavGraph
- [Security] Repository is vulnerable to MavenGate
- Generated code isn't internal
- Best way to implement / sample code with master-detail for tablets?
- Nested Destination NavGraph with default one being the "deeper HOT 4
- Forbid navigation into subgraphs from other than start destinations of the subgraph
- Compose to Fragment Navigation
- Update to compose navigation 1.7.0-alpha02 HOT 2
- WearOS: Disable swipe-to-dismiss gesture on a destination. HOT 4
- KSP throws error when creating new NavGraphs HOT 1
- Destination for multi module project. HOT 1
- Preserve top-level screens for bottom bar HOT 2
- Crash Caused by android.os.RemoteException while calling navController?.navigate(PipOverlayScreenDestination) HOT 1
- Bottom Sheet Navigation Different Behavior Requirement HOT 1
- Using ModalBottomSheetLayout always fallsback to startdestination when configuration changes HOT 2
- BottomSheet onDismiss callback possible? HOT 1
- Combine Destination annotations HOT 7
- Lifecycle for screens that then shows a dialog HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compose-destinations.