Travis Griggs
04/11/2023, 5:16 PMonGloballyPositioned
to capture the box of the "target widget", then when I open a full screen alert dialog that covers it all, I place whatever edit widget (e.g. BasicTextField) directly over the target widget. To get that precise placement, I had to use a fillFullSize() Column, which meant there was no dismiss region, so that had to be emulated through the column's clickable, and tweak the indication so there was no full screen ripple. This requires a bit of what feels like "transfer of state" between the modal dialog back to the normal tree. This was a fun experiment though, because it allowed me to learn more about Dialog(s).
2. For my second attempt, I chose to learn more about custom CompositionLocals. I created a ScrimShield compasable that's meant to sit at the top of the screen and makes an optional scrimhole (giggle) state available anywhere in the tree below. This allows a widget that wants to become modal to be right in the normal tree, but just throw its globallyPositioned box in the scrimhole, which the root ScrimShield then uses to place a view over the whole screen. Actually, it places a series of views "around" the hole which do an alpha overlay and eat events, but allow the widget in the "hole" to be the only widget capable of interacting. So it essentially casts an event eating/color shading set of views over all of the rest of the screen. I like this approach (a little) better, it seems to fit the "composable" nature of the behavior. But I wish that the scrim shield could be implemented a little more gracefully (I wish you could define a Layout that drew an arbitrary cover Path, and could then filter touch inputs based on whether they were in the said path or not)mattinger
04/11/2023, 7:11 PM@Composable
fun ScrimShieldLayout(
modifier: Modifier = Modifier,
showScrim: Boolean = false,
content: @Composable () -> Unit,
) {
Box(
modifier = modifier.then(
if (showScrim) {
Modifier.drawWithContent {
drawContent()
drawRoundRect(
color = Color.Green,
alpha = 0.3f,
size = size
)
}
} else {
Modifier
}
)
) {
content()
}
}
@Composable
@Preview(showBackground = true)
fun ScrimShieldLayoutPreview() {
ScrimShieldLayout(
showScrim = true,
modifier = Modifier.fillMaxSize()
) {
Text(text = "booya")
}
}
Travis Griggs
04/12/2023, 6:18 PMmattinger
04/14/2023, 6:22 PM