spierce7
02/12/2021, 10:54 PMmanueldidonna
02/12/2021, 11:19 PMZach Klippenstein (he/him) [MOD]
02/12/2021, 11:19 PMval background = AmbientBackground.current
Box(Modifier.background(background))
You can also inline it:
Box(Modifier.background(AmbientBackground.current))
If you are implementing your own custom modifier than needs to read ambients, probably the first thing to do is ask, does the modifier really need to read the ambient? Would it be more clear/less magic to just ask the caller to pass it in directly?
If the answer to that is “no”, then you can use the composed
helper to create a modifier that can read from the composition wherever it’s applied:
fun Modifier.customBackground() = composed {
this.background(AmbientBackground.current)
}
Note that that function is not composable itself. This is different and better than simply making a composable modifier factory function, since it guarantees that the composition will be read as close to the actual use site as possible, e.g. in case the caller calls your factory function very far away from wherever they end up passing the modifier to be used.spierce7
02/12/2021, 11:46 PMdispatchKeyEvent
via the Activity, but I need to somehow funnel them into compose. I was thinking it’d be fun to learn how to get them into the composable similar to the modifier that allows you to get key events in a composable.Lukas K-G
03/05/2021, 3:31 PMspierce7
03/05/2021, 3:59 PMdispatchKeyEvent
in the Activity, and I was able to get the eventsLukas K-G
03/05/2021, 4:00 PM