<https://stackoverflow.com/questions/69452854/incr...
# compose
This is my current custom AlertDialog composable. Its a bit rough, but it should give you an idea of how you can work around it until its fixed (I dont know if they will actually fix/change the default behavior, fingers crossed).
Copy code
Dialog(
    onDismissRequest = onDismiss
) {
    val scope = AlertActionScope(
        onDismiss = onDismiss
    )

    Surface(
        modifier = modifier,
        shape = MaterialTheme.shapes.medium,
        content = {
            Container(
                content = {
                    Container(
                        modifier = Modifier
                            .weight(
                                value = 1f,
                                fill = false
                            )
                            .padding(
                                all = when {
                                    insetContent -> {
                                        DialogPadding
                                    }
                                    else -> 0.dp
                                }
                            ),
                        spacing = KeylineSmall,
                        content = {
                            if (title != null) {
                                Text(
                                    text = title,
                                    type = Title
                                )
                            }

                            if (content != null) {
                                CompositionLocalProvider(
                                    LocalContentAlpha provides ContentAlpha.high,
                                    LocalTextStyle provides MaterialTheme.typography.body2
                                ) {
                                    content()
                                }
                            }
                        }
                    )

                    if (negative != null || positive != null) {
                        FlowRow(
                            modifier = Modifier
                                .fillMaxWidth()
                                .padding(all = 8.dp),
                            mainAxisSpacing = 8.dp,
                            crossAxisSpacing = 12.dp,
                            mainAxisAlignment = FlowMainAxisAlignment.End
                        ) {
                            negative?.invoke(scope)
                            positive?.invoke(scope)
                        }
                    }
                }
            )
        }
    )
}
s
Thank you so much, I will try to adapt this to my case. Hope they solve this soon
👍🏽 1
z
I'm using custom spacer composable as first child in
Column
inside
text=
Copy code
@Composable
fun HackySpacer(space: Dp) {
    Box(
        modifier = Modifier
            .height(space)
            .fillMaxWidth()
    ) {
        Text(text = "")
    }
}
z
If that works for your use case, great! 🙂 I was using a large composable in the text block and it was being cut off by the baseline function, might be worth keeping in mind if you run into the same thing down the line!
z
Yeah, it works in my case, because I have only few `TextField`s inside. Had to use that spacer, because
TextField
is otherwise positioned over title. And only empty
Text
"fixes" problem 🙂 I have a different problem.... it's keyboard, which isn't hidding as written here: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1633348928463500 AlertDialog is really crapy.
z
Hiding keyboard works for me in my alerts, both with
FocusManager.current.clearFocus
and
LocalSoftwareKeyboardController.current?.hide()
🥲
z
Aha, now I see... I had
val keyboardController = LocalSoftwareKeyboardController.current
outside
AlertDialog
. Had to move it inside, and now it works 🙂 Thanks!
👍🏽 1