Skip to content

Commit

Permalink
For mozilla-mobile#9932 - Introduce an offset in ExpandableLayout
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mugurell committed Apr 12, 2021
1 parent feac126 commit fe3e911
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Expand All @@ -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

Expand Down

0 comments on commit fe3e911

Please sign in to comment.