|
@@ -342,6 +342,8 @@ class Godot private constructor(val context: Context) {
|
|
|
*/
|
|
|
@JvmOverloads
|
|
|
fun enableEdgeToEdge(enabled: Boolean, override: Boolean = false) {
|
|
|
+ // Note: If modifying edge-to-edge or immersive mode logic, ensure to test with GodotIO.getDisplaySafeArea()
|
|
|
+ // to confirm there are no regressions in safe area calculation.
|
|
|
val window = getActivity()?.window ?: return
|
|
|
|
|
|
if (!isEdgeToEdge.compareAndSet(!enabled, enabled) && !override) {
|
|
@@ -354,27 +356,36 @@ class Godot private constructor(val context: Context) {
|
|
|
ViewCompat.setOnApplyWindowInsetsListener(rootView, null)
|
|
|
rootView.setPadding(0, 0, 0, 0)
|
|
|
} else {
|
|
|
- val insetType = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
|
|
|
if (rootView.rootWindowInsets != null) {
|
|
|
val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(rootView.rootWindowInsets)
|
|
|
- val insets = windowInsets.getInsets(insetType)
|
|
|
+ val insets = windowInsets.getInsets(getInsetType())
|
|
|
rootView.setPadding(insets.left, insets.top, insets.right, insets.bottom)
|
|
|
}
|
|
|
|
|
|
ViewCompat.setOnApplyWindowInsetsListener(rootView) { v: View, insets: WindowInsetsCompat ->
|
|
|
- val windowInsets = insets.getInsets(insetType)
|
|
|
+ val windowInsets = insets.getInsets(getInsetType())
|
|
|
v.setPadding(windowInsets.left, windowInsets.top, windowInsets.right, windowInsets.bottom)
|
|
|
WindowInsetsCompat.CONSUMED
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun getInsetType(): Int {
|
|
|
+ return if (!useImmersive.get() || isEditorBuild()) {
|
|
|
+ WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
|
|
|
+ } else {
|
|
|
+ WindowInsetsCompat.Type.systemBars()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Toggle immersive mode.
|
|
|
* Must be called from the UI thread.
|
|
|
*/
|
|
|
@JvmOverloads
|
|
|
fun enableImmersiveMode(enabled: Boolean, override: Boolean = false) {
|
|
|
+ // Note: If modifying edge-to-edge or immersive mode logic, ensure to test with GodotIO.getDisplaySafeArea()
|
|
|
+ // to confirm there are no regressions in safe area calculation.
|
|
|
val activity = getActivity() ?: return
|
|
|
val window = activity.window ?: return
|
|
|
|