mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 14:02:44 +00:00
modify base dialog for reduced padding
mostly for layout customizer
This commit is contained in:
parent
2e5d8ac02b
commit
0d9619f562
4 changed files with 67 additions and 32 deletions
|
@ -14,7 +14,6 @@ import helium314.keyboard.latin.utils.prefs
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
// todo (roughly in order)
|
// todo (roughly in order)
|
||||||
// try making a dialog with reduced padding
|
|
||||||
// work on todos in other files
|
// work on todos in other files
|
||||||
// check dark and light theme (don't have dynamic)
|
// 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?
|
// any way to get rid of the "old" background on starting settings? probably comes from app theme, can we avoid it?
|
||||||
|
|
|
@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import helium314.keyboard.latin.R
|
import helium314.keyboard.latin.R
|
||||||
import helium314.keyboard.latin.utils.Log
|
import helium314.keyboard.latin.utils.Log
|
||||||
import helium314.keyboard.latin.utils.checkLayout
|
import helium314.keyboard.latin.utils.checkLayout
|
||||||
|
@ -49,6 +50,9 @@ fun CustomizeLayoutDialog(
|
||||||
valid
|
valid
|
||||||
},
|
},
|
||||||
singleLine = false,
|
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)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import androidx.compose.ui.text.TextRange
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
|
||||||
// mostly taken from StreetComplete / SCEE
|
// mostly taken from StreetComplete / SCEE
|
||||||
/** Dialog with which to input text. OK button is only clickable if [checkTextValid] returns true. */
|
/** 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,
|
textInputLabel: @Composable (() -> Unit)? = null,
|
||||||
singleLine: Boolean = true,
|
singleLine: Boolean = true,
|
||||||
keyboardType: KeyboardType = KeyboardType.Unspecified,
|
keyboardType: KeyboardType = KeyboardType.Unspecified,
|
||||||
|
properties: DialogProperties = DialogProperties(),
|
||||||
checkTextValid: (text: String) -> Boolean = { it.isNotBlank() }
|
checkTextValid: (text: String) -> Boolean = { it.isNotBlank() }
|
||||||
) {
|
) {
|
||||||
val focusRequester = remember { FocusRequester() }
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
@ -66,6 +68,7 @@ fun TextInputDialog(
|
||||||
singleLine = singleLine
|
singleLine = singleLine
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
properties = properties
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
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.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
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.LocalTextStyle
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.contentColorFor
|
import androidx.compose.material3.contentColorFor
|
||||||
|
@ -14,9 +23,12 @@ import androidx.compose.runtime.CompositionLocalProvider
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
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 androidx.compose.ui.window.DialogProperties
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
|
|
||||||
|
// text should be smaller, and background should be darkened
|
||||||
@Composable
|
@Composable
|
||||||
fun ThreeButtonAlertDialog(
|
fun ThreeButtonAlertDialog(
|
||||||
onDismissRequest: () -> Unit,
|
onDismissRequest: () -> Unit,
|
||||||
|
@ -29,37 +41,53 @@ fun ThreeButtonAlertDialog(
|
||||||
confirmButtonText: String? = stringResource(android.R.string.ok),
|
confirmButtonText: String? = stringResource(android.R.string.ok),
|
||||||
cancelButtonText: String = stringResource(android.R.string.cancel),
|
cancelButtonText: String = stringResource(android.R.string.cancel),
|
||||||
neutralButtonText: String? = null,
|
neutralButtonText: String? = null,
|
||||||
|
properties: DialogProperties = DialogProperties()
|
||||||
) {
|
) {
|
||||||
AlertDialog(
|
Dialog(
|
||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
confirmButton = { // mis-use the confirm button and put everything in there
|
properties = properties
|
||||||
Row {
|
) {
|
||||||
if (neutralButtonText != null)
|
Box(
|
||||||
TextButton(
|
modifier = modifier.sizeIn(minWidth = 280.dp, maxWidth = 560.dp),
|
||||||
onClick = { onDismissRequest(); onNeutral() }
|
propagateMinConstraints = true
|
||||||
) { Text(neutralButtonText) }
|
) {
|
||||||
Spacer(modifier.weight(1f))
|
Surface(
|
||||||
TextButton(onClick = onDismissRequest) { Text(cancelButtonText) }
|
shape = MaterialTheme.shapes.medium,
|
||||||
if (confirmButtonText != null)
|
color = MaterialTheme.colorScheme.surface,
|
||||||
TextButton(
|
contentColor = contentColorFor(MaterialTheme.colorScheme.surface),
|
||||||
enabled = checkOk(),
|
) {
|
||||||
onClick = { onDismissRequest(); onConfirmed() },
|
Column(modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 6.dp)) {
|
||||||
) { Text(confirmButtonText) }
|
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(
|
||||||
|
onClick = { onDismissRequest(); onNeutral() }
|
||||||
|
) { Text(neutralButtonText) }
|
||||||
|
Spacer(modifier.weight(1f))
|
||||||
|
TextButton(onClick = onDismissRequest) { Text(cancelButtonText) }
|
||||||
|
if (confirmButtonText != null)
|
||||||
|
TextButton(
|
||||||
|
enabled = checkOk(),
|
||||||
|
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
|
@Preview
|
||||||
|
@ -71,6 +99,7 @@ private fun Preview() {
|
||||||
onConfirmed = { },
|
onConfirmed = { },
|
||||||
text = { Text("hello") },
|
text = { Text("hello") },
|
||||||
title = { Text("title") },
|
title = { Text("title") },
|
||||||
|
neutralButtonText = "Default"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue