mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-01 04:12:12 +00:00
improve handling of IME padding
still not really good...
This commit is contained in:
parent
d8e9a004e5
commit
682a4ae911
3 changed files with 41 additions and 36 deletions
|
@ -8,10 +8,10 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.isGone
|
||||
import helium314.keyboard.latin.R
|
||||
import helium314.keyboard.latin.settings.Settings
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.latin.utils.prefs
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
|
@ -29,6 +29,10 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
|
|||
if (Settings.getInstance().current == null)
|
||||
Settings.init(this)
|
||||
|
||||
// with this the layout edit dialog is not covered by the keyboard
|
||||
// alterative of Modifier.imePadding() and properties = DialogProperties(decorFitsSystemWindows = false) has other weird side effects
|
||||
ViewCompat.setOnApplyWindowInsetsListener(window.decorView.rootView) { _, insets -> insets }
|
||||
|
||||
settingsContainer = SettingsContainer(this)
|
||||
|
||||
val spellchecker = intent?.getBooleanExtra("spellchecker", false) ?: false
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
package helium314.keyboard.settings.dialogs
|
||||
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.ime
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
|
@ -14,10 +16,10 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import helium314.keyboard.latin.R
|
||||
import helium314.keyboard.latin.utils.LayoutType
|
||||
import helium314.keyboard.latin.utils.LayoutUtilsCustom
|
||||
|
@ -52,6 +54,7 @@ fun LayoutEditDialog(
|
|||
|| isNameValid(LayoutUtilsCustom.getCustomLayoutName(displayNameValue.text))
|
||||
)
|
||||
|
||||
val keyboardHeight = WindowInsets.ime.getBottom(LocalDensity.current)
|
||||
TextInputDialog(
|
||||
onDismissRequest = {
|
||||
job?.cancel()
|
||||
|
@ -91,11 +94,9 @@ fun LayoutEditDialog(
|
|||
}
|
||||
valid && nameValid // don't allow saving with invalid name, but inform user about issues with layout content
|
||||
},
|
||||
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
|
||||
// todo: also it results in an ugly effect when adding a new layout... need to find something else
|
||||
properties = DialogProperties(decorFitsSystemWindows = false),
|
||||
// todo: this looks weird when the text field is not covered by the keyboard, but better then not seeing the bottom part of the field...
|
||||
modifier = Modifier.padding(bottom = with(LocalDensity.current)
|
||||
{ (WindowInsets.ime.getBottom(LocalDensity.current) / 2 + 36).toDp() }), // why is the /2 necessary?
|
||||
reducePadding = true,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -56,38 +56,38 @@ fun ThreeButtonAlertDialog(
|
|||
color = MaterialTheme.colorScheme.surface,
|
||||
contentColor = contentColorFor(MaterialTheme.colorScheme.surface),
|
||||
) {
|
||||
Column(modifier = Modifier.padding(
|
||||
start = if (reducePadding) 8.dp else 16.dp,
|
||||
end = if (reducePadding) 8.dp else 16.dp,
|
||||
top = if (reducePadding) 8.dp else 16.dp,
|
||||
bottom = if (reducePadding) 2.dp else 6.dp
|
||||
)) {
|
||||
title?.let {
|
||||
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.titleLarge) {
|
||||
Box(Modifier.padding(PaddingValues(bottom = if (reducePadding) 4.dp else 16.dp))) {
|
||||
title()
|
||||
Column(modifier = Modifier.padding(
|
||||
start = if (reducePadding) 8.dp else 16.dp,
|
||||
end = if (reducePadding) 8.dp else 16.dp,
|
||||
top = if (reducePadding) 8.dp else 16.dp,
|
||||
bottom = if (reducePadding) 2.dp else 6.dp
|
||||
)) {
|
||||
title?.let {
|
||||
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.titleLarge) {
|
||||
Box(Modifier.padding(PaddingValues(bottom = if (reducePadding) 4.dp else 16.dp))) {
|
||||
title()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
text?.let {
|
||||
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyMedium) {
|
||||
Box(Modifier.weight(weight = 1f, fill = false).padding(bottom = if (reducePadding) 2.dp else 8.dp)) {
|
||||
text()
|
||||
text?.let {
|
||||
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyMedium) {
|
||||
Box(Modifier.weight(weight = 1f, fill = false).padding(bottom = if (reducePadding) 2.dp else 8.dp)) {
|
||||
text()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Row {
|
||||
if (neutralButtonText != null)
|
||||
TextButton(
|
||||
onClick = onNeutral
|
||||
) { Text(neutralButtonText) }
|
||||
Spacer(modifier.weight(1f))
|
||||
TextButton(onClick = onDismissRequest) { Text(cancelButtonText) }
|
||||
if (confirmButtonText != null)
|
||||
TextButton(
|
||||
enabled = checkOk(),
|
||||
onClick = { onDismissRequest(); onConfirmed() },
|
||||
) { Text(confirmButtonText) }
|
||||
Row {
|
||||
if (neutralButtonText != null)
|
||||
TextButton(
|
||||
onClick = onNeutral
|
||||
) { Text(neutralButtonText) }
|
||||
Spacer(modifier.weight(1f))
|
||||
TextButton(onClick = onDismissRequest) { Text(cancelButtonText) }
|
||||
if (confirmButtonText != null)
|
||||
TextButton(
|
||||
enabled = checkOk(),
|
||||
onClick = { onDismissRequest(); onConfirmed() },
|
||||
) { Text(confirmButtonText) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue