material-components / material-components/material-components-android
[HideBottomViewOnScrollBehaviour] BottomView doesn't slide off (or on) when the main fragment can't scroll
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Description: If you have a fragment whose content varies as to whether it's scrollable or not, using the below XML for the BottomNavigationView, it's possible to 'scroll off' the BottomNavigationView when it has sufficient content to scroll. Then if the content changes so it's no longer scrollable, the BottomNavigationView can't be scrolled back on.
Expected behavior: BottomNavigationView should scroll off/on screen for non-scrollable content too.
Source code:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/white"
app:labelVisibilityMode="labeled"
app:menu="@menu/menu_bottom_navigation_main"
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior">
</com.google.android.material.bottomnavigation.BottomNavigationView>
Looking at (in HideBottomViewOnScrollBehavior.java) :
@Override
public void onNestedScroll(
CoordinatorLayout coordinatorLayout,
@NonNull V child,
View target,
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed) {
if (dyConsumed > 0) {
slideDown(child);
} else if (dyConsumed < 0) {
slideUp(child);
}
}
In the scenario where the content can't scroll, dyConsumed is 0, but dyUnconsumed is non-0, so I'd propose changing it to:
if (dyConsumed > 0) {
slideDown(child);
} else if (dyConsumed < 0) {
slideUp(child);
} else if (dyUnconsumed > 0) {
slideDown(child);
} else if (dyUnconsumed < 0) {
slideUp(child);
}
Android API version: 28
Material Library version: 1.1.0-beta01
Device: Motorola One
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in HideBottomViewOnScrollBehavior.java, especially onNestedScroll, and reproduce the case where dyConsumed is zero while dyUnconsumed is non-zero. Verify that BottomNavigationView slides off when content becomes scrollable and slides back on when the content is no longer scrollable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100