mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-21 22:59:10 +00:00
fix issues with insets not being respected
This commit is contained in:
parent
43cfbddf68
commit
9ff5fda8ed
3 changed files with 17 additions and 6 deletions
|
@ -4,7 +4,9 @@ package helium314.keyboard.settings
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.WindowInsets.Type
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
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
|
// 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
|
// 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)
|
settingsContainer = SettingsContainer(this)
|
||||||
|
|
||||||
|
@ -209,6 +217,9 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
|
||||||
|
|
||||||
var forceNight: Boolean? = null
|
var forceNight: Boolean? = null
|
||||||
var forceTheme: String? = 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?) {
|
override fun onSharedPreferenceChanged(prefereces: SharedPreferences?, key: String?) {
|
||||||
|
|
|
@ -2,13 +2,12 @@
|
||||||
package helium314.keyboard.settings.dialogs
|
package helium314.keyboard.settings.dialogs
|
||||||
|
|
||||||
import android.widget.Toast
|
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.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
|
||||||
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
|
||||||
|
@ -47,6 +46,7 @@ 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)
|
||||||
|
@ -105,9 +105,10 @@ 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
|
||||||
},
|
},
|
||||||
// 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)
|
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,
|
reducePadding = true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,6 @@ import helium314.keyboard.settings.screens.GetIcon
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
// todo:
|
// todo:
|
||||||
// layout edit dialog does not care about ime padding when called from here, why?
|
|
||||||
// rotating closes the dialog
|
// rotating closes the dialog
|
||||||
@Composable
|
@Composable
|
||||||
fun SubtypeDialog(
|
fun SubtypeDialog(
|
||||||
|
|
Loading…
Add table
Reference in a new issue