From fe3e911d167b9e75cc8f130511f672eebe3c8180 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Mon, 12 Apr 2021 17:49:54 +0300 Subject: [PATCH] For #9932 - Introduce an offset in ExpandableLayout If the menu starts as collapsed and it has a sticky footer set the bottom item until which the menu should be collapsed must be shown on top of the sticky item's view. For this the entire menu has to have as offset the height of the sticky item's view. --- .../java/mozilla/components/browser/menu/BrowserMenu.kt | 6 +++++- .../components/browser/menu/view/ExpandableLayout.kt | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/browser/menu/src/main/java/mozilla/components/browser/menu/BrowserMenu.kt b/components/browser/menu/src/main/java/mozilla/components/browser/menu/BrowserMenu.kt index 4b2b76a1a2b..a15fae42582 100644 --- a/components/browser/menu/src/main/java/mozilla/components/browser/menu/BrowserMenu.kt +++ b/components/browser/menu/src/main/java/mozilla/components/browser/menu/BrowserMenu.kt @@ -128,11 +128,15 @@ open class BrowserMenu internal constructor( menuPositioningData.inferredMenuPlacement is BrowserMenuPlacement.AnchoredToBottom.ManualAnchoring) { val collapsingMenuIndexLimit = adapter.visibleItems.indexOfFirst { it.isCollapsingMenuLimit } + val stickyItemHeight = menuList?.layoutManager + ?.getChildAt(adapter.visibleItems.indexOfLast { it.isSticky }) + ?.height ?: 0 if (collapsingMenuIndexLimit > 0) { return ExpandableLayout.wrapContentInExpandableView( view, - collapsingMenuIndexLimit + collapsingMenuIndexLimit, + offset = stickyItemHeight ) { dismiss() } } } else { diff --git a/components/browser/menu/src/main/java/mozilla/components/browser/menu/view/ExpandableLayout.kt b/components/browser/menu/src/main/java/mozilla/components/browser/menu/view/ExpandableLayout.kt index 0f1ce2e3426..cd59cfb4336 100644 --- a/components/browser/menu/src/main/java/mozilla/components/browser/menu/view/ExpandableLayout.kt +++ b/components/browser/menu/src/main/java/mozilla/components/browser/menu/view/ExpandableLayout.kt @@ -35,6 +35,9 @@ internal class ExpandableLayout private constructor(context: Context) : FrameLay @VisibleForTesting internal lateinit var wrappedView: ViewGroup + @VisibleForTesting + internal var heightOffset: Int = 0 + /** * Listener of touches in the empty space left by the collapsed view. */ @@ -312,6 +315,7 @@ internal class ExpandableLayout private constructor(context: Context) : FrameLay } var result = 0 + result += heightOffset result += wrappedView.marginTop result += wrappedView.marginBottom result += wrappedView.paddingTop @@ -362,6 +366,7 @@ internal class ExpandableLayout private constructor(context: Context) : FrameLay internal fun wrapContentInExpandableView( contentView: ViewGroup, lastVisibleItemIndexWhenCollapsed: Int = Int.MAX_VALUE, + offset: Int = 0, blankTouchListener: (() -> Unit)? = null ): ExpandableLayout { @@ -376,6 +381,7 @@ internal class ExpandableLayout private constructor(context: Context) : FrameLay expandableView.addView(contentView, params) expandableView.wrappedView = contentView + expandableView.heightOffset = offset expandableView.blankTouchListener = blankTouchListener expandableView.lastVisibleItemIndexWhenCollapsed = lastVisibleItemIndexWhenCollapsed