Skip to content
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

[Slider] Fix slider label not moving #4104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/java/com/google/android/material/slider/BaseSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ abstract class BaseSlider<
@NonNull
private final ViewTreeObserver.OnScrollChangedListener onScrollChangedListener =
this::updateLabels;
@NonNull
private final ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener =
this::updateLabels;

/**
* Determines the behavior of the label which can be any of the following.
Expand Down Expand Up @@ -1883,6 +1886,7 @@ public void setEnabled(boolean enabled) {
protected void onAttachedToWindow() {
super.onAttachedToWindow();
getViewTreeObserver().addOnScrollChangedListener(onScrollChangedListener);
getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
// The label is attached on the Overlay relative to the content.
for (TooltipDrawable label : labels) {
attachLabelToContentView(label);
Expand All @@ -1904,6 +1908,7 @@ protected void onDetachedFromWindow() {
detachLabelFromContentView(label);
}
getViewTreeObserver().removeOnScrollChangedListener(onScrollChangedListener);
getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
super.onDetachedFromWindow();
}

Expand Down