From bed718347c6e7ca9fa9987bb67eb8a5a83a6d451 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Fri, 22 Aug 2025 10:30:44 -0300 Subject: [PATCH] Fix navigation bar gap when opening keyboard in split pane view. --- .../components/InsetAwareConstraintLayout.kt | 34 +++++++------------ .../conversation/v2/ConversationFragment.kt | 1 + 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/InsetAwareConstraintLayout.kt b/app/src/main/java/org/thoughtcrime/securesms/components/InsetAwareConstraintLayout.kt index af26782fb4..284e5174cd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/InsetAwareConstraintLayout.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/InsetAwareConstraintLayout.kt @@ -1,10 +1,7 @@ package org.thoughtcrime.securesms.components import android.content.Context -import android.os.Build import android.util.AttributeSet -import android.util.DisplayMetrics -import android.view.Surface import android.view.View import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.Guideline @@ -16,8 +13,8 @@ import androidx.core.view.WindowInsetsCompat import org.signal.core.util.logging.Log import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.keyvalue.SignalStore -import org.thoughtcrime.securesms.util.ServiceUtil import org.thoughtcrime.securesms.util.ViewUtil +import org.thoughtcrime.securesms.window.WindowSizeClass.Companion.getWindowSizeClass /** * A specialized [ConstraintLayout] that sets guidelines based on the window insets provided @@ -61,7 +58,6 @@ open class InsetAwareConstraintLayout @JvmOverloads constructor( private val windowInsetsListeners: MutableSet = mutableSetOf() private val keyboardStateListeners: MutableSet = mutableSetOf() private val keyboardAnimator = KeyboardInsetAnimator() - private val displayMetrics = DisplayMetrics() private var overridingKeyboard: Boolean = false private var previousKeyboardHeight: Int = 0 private var applyRootInsets: Boolean = false @@ -104,6 +100,16 @@ open class InsetAwareConstraintLayout @JvmOverloads constructor( private fun insetTarget(): View = if (applyRootInsets) rootView else this + fun setApplyRootInsets(useRootInsets: Boolean) { + if (applyRootInsets == useRootInsets) { + return + } + + ViewCompat.setOnApplyWindowInsetsListener(insetTarget(), null) + applyRootInsets = useRootInsets + ViewCompat.setOnApplyWindowInsetsListener(insetTarget(), windowInsetsListener) + } + /** * Specifies whether or not window insets should be accounted for when applying * insets. This is useful when choosing whether to display the content in this @@ -222,23 +228,7 @@ open class InsetAwareConstraintLayout @JvmOverloads constructor( } private fun isLandscape(): Boolean { - val rotation = getDeviceRotation() - return rotation == Surface.ROTATION_90 - } - - @Suppress("DEPRECATION") - private fun getDeviceRotation(): Int { - if (isInEditMode) { - return Surface.ROTATION_0 - } - - if (Build.VERSION.SDK_INT >= 30) { - context.display?.getRealMetrics(displayMetrics) - } else { - ServiceUtil.getWindowManager(context).defaultDisplay.getRealMetrics(displayMetrics) - } - - return if (displayMetrics.widthPixels > displayMetrics.heightPixels) Surface.ROTATION_90 else Surface.ROTATION_0 + return resources.getWindowSizeClass().isLandscape() } private val Guideline?.guidelineEnd: Int diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt index a1176799f2..dd85d9e6c2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt @@ -594,6 +594,7 @@ class ConversationFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.toolbar.isBackInvokedCallbackEnabled = false + binding.root.setApplyRootInsets(!resources.getWindowSizeClass().isSplitPane()) binding.root.setUseWindowTypes(!resources.getWindowSizeClass().isSplitPane()) disposables.bindTo(viewLifecycleOwner)