modify base dialog for reduced padding

mostly for layout customizer
This commit is contained in:
Helium314 2025-02-06 18:08:31 +01:00
parent 2e5d8ac02b
commit 0d9619f562
4 changed files with 67 additions and 32 deletions

View file

@ -14,7 +14,6 @@ import helium314.keyboard.latin.utils.prefs
import kotlinx.coroutines.flow.MutableStateFlow
// todo (roughly in order)
// try making a dialog with reduced padding
// work on todos in other files
// check dark and light theme (don't have dynamic)
// any way to get rid of the "old" background on starting settings? probably comes from app theme, can we avoid it?

View file

@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.window.DialogProperties
import helium314.keyboard.latin.R
import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.checkLayout
@ -49,6 +50,9 @@ fun CustomizeLayoutDialog(
valid
},
singleLine = false,
modifier = Modifier.imePadding()
modifier = Modifier.imePadding(),
// decorFitsSystemWindows = false is necessary so the dialog is not covered by keyboard
// but this also stops the background from being darkened... great idea to combine both
properties = DialogProperties(decorFitsSystemWindows = false)
)
}

View file

@ -19,6 +19,7 @@ import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.window.DialogProperties
// mostly taken from StreetComplete / SCEE
/** Dialog with which to input text. OK button is only clickable if [checkTextValid] returns true. */
@ -35,6 +36,7 @@ fun TextInputDialog(
textInputLabel: @Composable (() -> Unit)? = null,
singleLine: Boolean = true,
keyboardType: KeyboardType = KeyboardType.Unspecified,
properties: DialogProperties = DialogProperties(),
checkTextValid: (text: String) -> Boolean = { it.isNotBlank() }
) {
val focusRequester = remember { FocusRequester() }
@ -66,6 +68,7 @@ fun TextInputDialog(
singleLine = singleLine
)
},
properties = properties
)
}

View file

@ -1,11 +1,20 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Copyright (C) 2021 The Android Open Source Project
* parts taken from Material3 AlertDialog.kt
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
*/
package helium314.keyboard.settings.dialogs
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.material3.AlertDialog
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.contentColorFor
@ -14,9 +23,12 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import helium314.keyboard.settings.Theme
// text should be smaller, and background should be darkened
@Composable
fun ThreeButtonAlertDialog(
onDismissRequest: () -> Unit,
@ -29,10 +41,36 @@ fun ThreeButtonAlertDialog(
confirmButtonText: String? = stringResource(android.R.string.ok),
cancelButtonText: String = stringResource(android.R.string.cancel),
neutralButtonText: String? = null,
properties: DialogProperties = DialogProperties()
) {
AlertDialog(
Dialog(
onDismissRequest = onDismissRequest,
confirmButton = { // mis-use the confirm button and put everything in there
properties = properties
) {
Box(
modifier = modifier.sizeIn(minWidth = 280.dp, maxWidth = 560.dp),
propagateMinConstraints = true
) {
Surface(
shape = MaterialTheme.shapes.medium,
color = MaterialTheme.colorScheme.surface,
contentColor = contentColorFor(MaterialTheme.colorScheme.surface),
) {
Column(modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 6.dp)) {
title?.let {
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.titleLarge) {
Box(Modifier.padding(PaddingValues(bottom = 16.dp))) {
title()
}
}
}
text?.let {
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyMedium) {
Box(Modifier.weight(weight = 1f, fill = false).padding(bottom = 8.dp)) {
text()
}
}
}
Row {
if (neutralButtonText != null)
TextButton(
@ -46,20 +84,10 @@ fun ThreeButtonAlertDialog(
onClick = { onDismissRequest(); onConfirmed() },
) { Text(confirmButtonText) }
}
},
modifier = modifier,
title = {
// avoid way too large title (headlineSmall)
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.titleLarge) {
title?.invoke()
}
},
text = text,
shape = MaterialTheme.shapes.medium,
containerColor = MaterialTheme.colorScheme.surface,
textContentColor = contentColorFor(MaterialTheme.colorScheme.surface),
properties = DialogProperties(decorFitsSystemWindows = false), // otherwise Modifier.imePadding() is ignored
)
}
}
}
}
@Preview
@ -71,6 +99,7 @@ private fun Preview() {
onConfirmed = { },
text = { Text("hello") },
title = { Text("title") },
neutralButtonText = "Default"
)
}
}