Hello! Is it possible to have 'ThreadLocal' anolog for compossibles? I need to put parameter of the ...
p
Hello! Is it possible to have 'ThreadLocal' anolog for compossibles? I need to put parameter of the composable function to such structure to be able to take it from subcomposables without passing it as parameter. Globals can't solve this, cause it is possible to call such function with different parameter values and each should hold it's own 'ThreadLocal' value.
o
Seems like
CompositionLocalProvider
and
staticCompositionLocalOf
is what you’re looking for
c
First off: Compose is intended to run independent of any particular thread, and potentially on multiple threads, so ThreadLocal itself will not work. https://developer.android.com/jetpack/compose/mental-model#parallel Second: CompositionLocals is probably the API you’re thinking of, as that passes objects to the sub-composition of the provider. However, you should really ask yourself if this is absolutely necessary, or if you are just trying to save a parameter, because that’s probably not a good reason to use CompositionLocals. https://kotlinlang.slack.com/archives/CJLTWPH7S/p1611137643313000?thread_ts=1611128119.308900&cid=CJLTWPH7S (ambient was the older term for composition locals)