Allow specification of whether we utilize windowTypes to lay out inset guidelines.

This commit is contained in:
Alex Hart
2025-04-15 10:50:23 -03:00
committed by Cody Henthorne
parent b46d891183
commit bd03f21cdf
2 changed files with 23 additions and 0 deletions

View File

@@ -66,7 +66,11 @@ open class InsetAwareConstraintLayout @JvmOverloads constructor(
private var previousKeyboardHeight: Int = 0
private var applyRootInsets: Boolean = false
private var insets: WindowInsetsCompat? = null
private var windowTypes: Int = InsetAwareConstraintLayout.windowTypes
private val windowInsetsListener = androidx.core.view.OnApplyWindowInsetsListener { _, insets ->
this.insets = insets
applyInsets(windowInsets = insets.getInsets(windowTypes), keyboardInsets = insets.getInsets(keyboardType))
insets
}
@@ -100,6 +104,23 @@ open class InsetAwareConstraintLayout @JvmOverloads constructor(
private fun insetTarget(): View = if (applyRootInsets) rootView else this
/**
* 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
* constraint layout as a full-window view or as a framed view.
*/
fun setUseWindowTypes(useWindowTypes: Boolean) {
windowTypes = if (useWindowTypes) {
InsetAwareConstraintLayout.windowTypes
} else {
0
}
if (insets != null) {
applyInsets(insets!!.getInsets(windowTypes), insets!!.getInsets(keyboardType))
}
}
fun addKeyboardStateListener(listener: KeyboardStateListener) {
keyboardStateListeners += listener
}

View File

@@ -590,6 +590,8 @@ class ConversationFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding.toolbar.isBackInvokedCallbackEnabled = false
binding.root.setUseWindowTypes(resources.getWindowSizeClass().isCompact())
disposables.bindTo(viewLifecycleOwner)
if (requireActivity() is ConversationActivity) {