Closed amitkma closed 1 year ago
You would have to provide it yourself at the entry point to your composable running within Molecule. Molecule is not Android-specific nor does it have to run in a location where a Context is available. If you have one that you want to make available, you can provide it like a normal composition local at the root of your composition.
@amitkma did you get this working? Would be great to get an example as part of this thread as probably others will run into it as well.
The docs for providing composition local values is here: https://developer.android.com/jetpack/compose/compositionlocal#providing-values. If you have a context instance you provide it as LocalContext
at the root (or wherever) of your Molecule-based composition.
I tried multiple variations but none of them seem to work as expected. Can you provide an example?
I forgot the built-in one returns Unit
.
You have to use your own variant that returns the inner lambda value. See https://issuetracker.google.com/issues/271871288 for both the feature request as well as code you can use.
I am trying to access Context inside a presenter composable using
LocalContext.Current
, But I couldn't make it work. I am getting the following error ->Any advise or workaround it?