Skip to content

Commit

Permalink
[Slider] Fix slider label not moving
Browse files Browse the repository at this point in the history
Resolves #4104

GIT_ORIGIN_REV_ID=676308a77b429610192b1df80becb656e6053811
PiperOrigin-RevId: 666511279
  • Loading branch information
manabu-nakamura authored and imhappi committed Aug 23, 2024
1 parent 1795035 commit 967dcd5
Showing 1 changed file with 5 additions and 0 deletions.
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

0 comments on commit 967dcd5

Please sign in to comment.