fix issues with insets not being respected

This commit is contained in:
Helium314 2025-02-23 19:01:45 +01:00
parent 43cfbddf68
commit 9ff5fda8ed
3 changed files with 17 additions and 6 deletions

View file

@ -4,7 +4,9 @@ package helium314.keyboard.settings
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.WindowInsets.Type
import android.view.inputmethod.EditorInfo
import android.widget.RelativeLayout
import androidx.appcompat.app.AppCompatActivity
@ -61,7 +63,13 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
// 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 -> insets }
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)
@ -209,6 +217,9 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
var forceNight: Boolean? = null
var forceTheme: String? = null
// weird inset forwarding because otherwise layout dialog sometimes doesn't care about keyboard showing
var bottomInsets = MutableStateFlow(0)
}
override fun onSharedPreferenceChanged(prefereces: SharedPreferences?, key: String?) {

View file

@ -2,13 +2,12 @@
package helium314.keyboard.settings.dialogs
import android.widget.Toast
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
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
@ -47,6 +46,7 @@ fun LayoutEditDialog(
val ctx = LocalContext.current
val scope = rememberCoroutineScope()
val startIsCustom = LayoutUtilsCustom.isCustomLayout(initialLayoutName)
val bottomInsets by SettingsActivity.bottomInsets.collectAsState()
var displayNameValue by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(TextFieldValue(
if (startIsCustom) LayoutUtilsCustom.getDisplayName(initialLayoutName)
@ -105,9 +105,10 @@ fun LayoutEditDialog(
}
valid && nameValid // don't allow saving with invalid name, but inform user about issues with layout content
},
// 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...
// todo: this looks weird when the text field is not covered by the keyboard (long dialog)
// but better than 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?
{ (bottomInsets / 2 + 36).toDp() }), // why is the /2 necessary?
reducePadding = true,
)
}

View file

@ -73,7 +73,6 @@ import helium314.keyboard.settings.screens.GetIcon
import java.util.Locale
// todo:
// layout edit dialog does not care about ime padding when called from here, why?
// rotating closes the dialog
@Composable
fun SubtypeDialog(