remove weird workaround to get acceptable layout edit dialog positioning

not necessary any more after enabling edge to edge
This commit is contained in:
Helium314 2025-04-21 08:29:50 +02:00
parent d9f17733d9
commit 7e59bcc799
2 changed files with 7 additions and 18 deletions

View file

@ -79,16 +79,6 @@ class SettingsActivity : ComponentActivity(), SharedPreferences.OnSharedPreferen
setSystemBarIconColor() setSystemBarIconColor()
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
// with this the layout edit dialog is not covered by the keyboard
// alternative of Modifier.imePadding() and properties = DialogProperties(decorFitsSystemWindows = false) has other weird side effects
ViewCompat.setOnApplyWindowInsetsListener(window.decorView.rootView) { _, insets ->
@Suppress("DEPRECATION")
bottomInsets.value = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
insets.getInsets(Type.ime()).bottom
else insets.systemWindowInsetBottom
insets
}
settingsContainer = SettingsContainer(this) settingsContainer = SettingsContainer(this)
val spellchecker = intent?.getBooleanExtra("spellchecker", false) ?: false val spellchecker = intent?.getBooleanExtra("spellchecker", false) ?: false

View file

@ -2,11 +2,14 @@
package helium314.keyboard.settings.dialogs package helium314.keyboard.settings.dialogs
import android.widget.Toast import android.widget.Toast
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.exclude
import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
@ -14,7 +17,6 @@ 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.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.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
@ -50,7 +52,6 @@ fun LayoutEditDialog(
val ctx = LocalContext.current val ctx = LocalContext.current
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val startIsCustom = LayoutUtilsCustom.isCustomLayout(initialLayoutName) val startIsCustom = LayoutUtilsCustom.isCustomLayout(initialLayoutName)
val bottomInsets by SettingsActivity.bottomInsets.collectAsState()
var displayNameValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { var displayNameValue by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(TextFieldValue( mutableStateOf(TextFieldValue(
if (startIsCustom) LayoutUtilsCustom.getDisplayName(initialLayoutName) if (startIsCustom) LayoutUtilsCustom.getDisplayName(initialLayoutName)
@ -110,10 +111,8 @@ 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
}, },
// this looks weird when the text field is not covered by the keyboard (long dialog) // why is exclude(WindowInsets.systemBars) necessary?
// but better than not seeing the bottom part of the field... modifier = Modifier.windowInsetsPadding(WindowInsets.ime.exclude(WindowInsets.systemBars)),
modifier = Modifier.padding(bottom = with(LocalDensity.current)
{ (bottomInsets / 2 + 36).toDp() }), // why is the /2 necessary?
reducePadding = true, reducePadding = true,
) )
} }