mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-02 12:52:15 +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.foundation.layout.Column
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.ui.platform.ComposeView
|
import androidx.compose.ui.platform.ComposeView
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import helium314.keyboard.latin.R
|
import helium314.keyboard.latin.R
|
||||||
import helium314.keyboard.latin.settings.Settings
|
import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.utils.Log
|
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
|
@ -29,6 +29,10 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
|
||||||
if (Settings.getInstance().current == null)
|
if (Settings.getInstance().current == null)
|
||||||
Settings.init(this)
|
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)
|
settingsContainer = SettingsContainer(this)
|
||||||
|
|
||||||
val spellchecker = intent?.getBooleanExtra("spellchecker", false) ?: false
|
val spellchecker = intent?.getBooleanExtra("spellchecker", false) ?: false
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
package helium314.keyboard.settings.dialogs
|
package helium314.keyboard.settings.dialogs
|
||||||
|
|
||||||
import android.widget.Toast
|
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.Icon
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextField
|
import androidx.compose.material3.TextField
|
||||||
|
@ -14,10 +16,10 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
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.platform.LocalDensity
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import androidx.compose.ui.window.DialogProperties
|
|
||||||
import helium314.keyboard.latin.R
|
import helium314.keyboard.latin.R
|
||||||
import helium314.keyboard.latin.utils.LayoutType
|
import helium314.keyboard.latin.utils.LayoutType
|
||||||
import helium314.keyboard.latin.utils.LayoutUtilsCustom
|
import helium314.keyboard.latin.utils.LayoutUtilsCustom
|
||||||
|
@ -52,6 +54,7 @@ fun LayoutEditDialog(
|
||||||
|| isNameValid(LayoutUtilsCustom.getCustomLayoutName(displayNameValue.text))
|
|| isNameValid(LayoutUtilsCustom.getCustomLayoutName(displayNameValue.text))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val keyboardHeight = WindowInsets.ime.getBottom(LocalDensity.current)
|
||||||
TextInputDialog(
|
TextInputDialog(
|
||||||
onDismissRequest = {
|
onDismissRequest = {
|
||||||
job?.cancel()
|
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
|
valid && nameValid // don't allow saving with invalid name, but inform user about issues with layout content
|
||||||
},
|
},
|
||||||
modifier = Modifier.imePadding(),
|
// 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...
|
||||||
// decorFitsSystemWindows = false is necessary so the dialog is not covered by keyboard
|
modifier = Modifier.padding(bottom = with(LocalDensity.current)
|
||||||
// but this also stops the background from being darkened... great idea to combine both
|
{ (WindowInsets.ime.getBottom(LocalDensity.current) / 2 + 36).toDp() }), // why is the /2 necessary?
|
||||||
// todo: also it results in an ugly effect when adding a new layout... need to find something else
|
|
||||||
properties = DialogProperties(decorFitsSystemWindows = false),
|
|
||||||
reducePadding = true,
|
reducePadding = true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,38 +56,38 @@ fun ThreeButtonAlertDialog(
|
||||||
color = MaterialTheme.colorScheme.surface,
|
color = MaterialTheme.colorScheme.surface,
|
||||||
contentColor = contentColorFor(MaterialTheme.colorScheme.surface),
|
contentColor = contentColorFor(MaterialTheme.colorScheme.surface),
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.padding(
|
Column(modifier = Modifier.padding(
|
||||||
start = if (reducePadding) 8.dp else 16.dp,
|
start = if (reducePadding) 8.dp else 16.dp,
|
||||||
end = if (reducePadding) 8.dp else 16.dp,
|
end = if (reducePadding) 8.dp else 16.dp,
|
||||||
top = if (reducePadding) 8.dp else 16.dp,
|
top = if (reducePadding) 8.dp else 16.dp,
|
||||||
bottom = if (reducePadding) 2.dp else 6.dp
|
bottom = if (reducePadding) 2.dp else 6.dp
|
||||||
)) {
|
)) {
|
||||||
title?.let {
|
title?.let {
|
||||||
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.titleLarge) {
|
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.titleLarge) {
|
||||||
Box(Modifier.padding(PaddingValues(bottom = if (reducePadding) 4.dp else 16.dp))) {
|
Box(Modifier.padding(PaddingValues(bottom = if (reducePadding) 4.dp else 16.dp))) {
|
||||||
title()
|
title()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
text?.let {
|
||||||
text?.let {
|
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyMedium) {
|
||||||
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyMedium) {
|
Box(Modifier.weight(weight = 1f, fill = false).padding(bottom = if (reducePadding) 2.dp else 8.dp)) {
|
||||||
Box(Modifier.weight(weight = 1f, fill = false).padding(bottom = if (reducePadding) 2.dp else 8.dp)) {
|
text()
|
||||||
text()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Row {
|
||||||
Row {
|
if (neutralButtonText != null)
|
||||||
if (neutralButtonText != null)
|
TextButton(
|
||||||
TextButton(
|
onClick = onNeutral
|
||||||
onClick = onNeutral
|
) { Text(neutralButtonText) }
|
||||||
) { Text(neutralButtonText) }
|
Spacer(modifier.weight(1f))
|
||||||
Spacer(modifier.weight(1f))
|
TextButton(onClick = onDismissRequest) { Text(cancelButtonText) }
|
||||||
TextButton(onClick = onDismissRequest) { Text(cancelButtonText) }
|
if (confirmButtonText != null)
|
||||||
if (confirmButtonText != null)
|
TextButton(
|
||||||
TextButton(
|
enabled = checkOk(),
|
||||||
enabled = checkOk(),
|
onClick = { onDismissRequest(); onConfirmed() },
|
||||||
onClick = { onDismissRequest(); onConfirmed() },
|
) { Text(confirmButtonText) }
|
||||||
) { Text(confirmButtonText) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue