Lauren Yew
12/22/2020, 8:29 PMProviders
and Ambients
like a Dagger inject where I can get a dependency without passing it as a param anywhere? Is there a best practice on their use? https://developer.android.com/reference/kotlin/androidx/compose/runtime/Ambientjw
12/22/2020, 8:30 PMContext.getSystemService
.Lauren Yew
12/22/2020, 8:31 PMLauren Yew
12/22/2020, 8:32 PMLauren Yew
12/22/2020, 8:33 PMActiveUser
example in the docjw
12/22/2020, 8:34 PMLauren Yew
12/22/2020, 8:35 PMrsktash
12/22/2020, 8:51 PMAdam Powell
12/22/2020, 8:51 PM{ error("missing foo") }
but you can if you really want toAdam Powell
12/22/2020, 8:51 PMjw
12/22/2020, 8:53 PMContext.getSystemService(VIBRATOR)
will crash on devices without a vibrator motor if you're not careful! But the last time I remember seeing that was like 2011...
Seems like your only choice is an explicit argument or the ambient system, although the Compose i've done is not Compose UI and I have never used ambients so my advice is likely not that useful.rsktash
12/22/2020, 8:57 PMrsktash
12/22/2020, 9:00 PMKirill Grouchnikov
12/22/2020, 9:04 PMContext.getSystemService
is really a global object that can't be "redefined". Ambients in Compose can be redefined (or provided) at any level in the hierarchy, and that applies to the entire subtree unless some subchild redefines it again.Kirill Grouchnikov
12/22/2020, 9:05 PMLauren Yew
12/22/2020, 9:06 PMKirill Grouchnikov
12/22/2020, 9:07 PMKirill Grouchnikov
12/22/2020, 9:08 PMKirill Grouchnikov
12/22/2020, 9:09 PMAdam Powell
12/22/2020, 9:09 PMContext.getSystemService
-type things are what we tend to use them for in the stock compose librariesKirill Grouchnikov
12/22/2020, 9:10 PMAdam Powell
12/22/2020, 9:11 PMAdam Powell
12/22/2020, 9:11 PMAdam Powell
12/22/2020, 9:13 PMAdam Powell
12/22/2020, 9:14 PMrsktash
12/22/2020, 9:15 PMAdam Powell
12/22/2020, 9:17 PMAdam Powell
12/22/2020, 9:19 PMDisposableEffect
is one way to initialize/tear down an object that needs it; we also still need to add some sort of rememberDisposable
that does it in one go with creating something in a remember
expression. There are some edge cases where DisposableEffect
won't clean up an object created in a remember
expression if the composition pass where the object was created failsVinay Gaba
12/22/2020, 10:02 PMDominaezzz
12/22/2020, 11:00 PMjw
12/22/2020, 11:32 PMjw
12/22/2020, 11:36 PMjw
12/22/2020, 11:37 PMColton Idle
12/23/2020, 1:28 AM