Skip to content

[Slider] label is gone with slider #4320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/java/com/google/android/material/slider/BaseSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ abstract class BaseSlider<
private final ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener =
this::updateLabels;

private boolean isVisible;

/**
* Determines the behavior of the label which can be any of the following.
*
Expand Down Expand Up @@ -1886,6 +1888,7 @@ public void setEnabled(boolean enabled) {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
isVisible = isShown();
getViewTreeObserver().addOnScrollChangedListener(onScrollChangedListener);
getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
// The label is attached on the Overlay relative to the content.
Expand Down Expand Up @@ -2681,7 +2684,17 @@ private void updateLabels() {
private boolean isSliderVisibleOnScreen() {
final Rect contentViewBounds = new Rect();
ViewUtils.getContentView(this).getHitRect(contentViewBounds);
return getLocalVisibleRect(contentViewBounds);
return getLocalVisibleRect(contentViewBounds) && isVisible();
}

private boolean isVisible() {
return (VERSION.SDK_INT >= VERSION_CODES.N) ? isVisible : isShown();
}

@Override
public void onVisibilityAggregated(boolean isVisible) {
super.onVisibilityAggregated(isVisible);
this.isVisible = isVisible;
}

private void ensureLabelsRemoved() {
Expand Down