material-components / material-components/material-components-android

[BottomSheetBehavior] Allow peek height to be determined by child view

Open
#2,785 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request Widget: BottomSheet
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem? Please describe.
In my app, the bottom sheet has a "bar" view that takes up all of the peek height. However, it seems that the only way to modify the peek height to accommodate the bar is by setting it to a fixed value. This is not ideal, as my bar contains text, and if the text scale is increased enough, it will result in the hard-coded size in DP not lining up with the actual size in DP and SP. This would cause a visual bug as the bar view extends into the navigation bar.

Describe the solution you'd like
I want another option for peekHeight (firstChild perhaps?) that takes the first child in a ViewGroup and uses that to calculate the peek height instead. That way, the height can be automatically determined from the "bar" view, which is the first view in my Bottom Sheet.

Describe alternatives you've considered
I can override the peek height by subclassing the behavior and overriding onLayoutChild as such. I would prefer this to be native to the behavior, however.

override fun onLayoutChild(parent: CoordinatorLayout, child: V, layoutDirection: Int): Boolean {
    val success = super.onLayoutChild(parent, child, layoutDirection)
    (child as? ViewGroup)?.getChildAt(0)?.let {
        peekHeight = it.height
    }
    return success
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with BottomSheetBehavior and its onLayoutChild path, then compare the current peekHeight handling with the subclass override shown in the issue. Done means the behavior can derive the peek height from the first child rather than a fixed value, including content whose height changes with text scaling, without the bar extending into the navigation bar.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.