https://kotlinlang.org logo
Title
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).
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

Stefano Sansone

10/06/2021, 9:43 AM
Thank you so much, I will try to adapt this to my case. Hope they solve this soon
👍🏽 1
z

zokipirlo

10/06/2021, 10:59 AM
I'm using custom spacer composable as first child in
Column
inside
text=
@Composable
fun HackySpacer(space: Dp) {
    Box(
        modifier = Modifier
            .height(space)
            .fillMaxWidth()
    ) {
        Text(text = "")
    }
}
z

Zoltan Demant

10/06/2021, 11:38 AM
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

zokipirlo

10/06/2021, 11:46 AM
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

Zoltan Demant

10/06/2021, 12:07 PM
Hiding keyboard works for me in my alerts, both with
FocusManager.current.clearFocus
and
LocalSoftwareKeyboardController.current?.hide()
🥲
z

zokipirlo

10/06/2021, 12:21 PM
Aha, now I see... I had
val keyboardController = LocalSoftwareKeyboardController.current
outside
AlertDialog
. Had to move it inside, and now it works 🙂 Thanks!
👍🏽 1