diff --git a/lib/java/com/google/android/material/slider/BaseSlider.java b/lib/java/com/google/android/material/slider/BaseSlider.java index 9008cc181a8..76885da30ea 100644 --- a/lib/java/com/google/android/material/slider/BaseSlider.java +++ b/lib/java/com/google/android/material/slider/BaseSlider.java @@ -1905,6 +1905,9 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) { for (TooltipDrawable label : labels) { contentViewOverlay.remove(label); } + thisAndAncestorsVisible = false; + } else { + thisAndAncestorsVisible = true; } } @@ -2714,19 +2717,7 @@ private void updateLabels() { private boolean isSliderVisibleOnScreen() { final Rect contentViewBounds = new Rect(); ViewUtils.getContentView(this).getHitRect(contentViewBounds); - return getLocalVisibleRect(contentViewBounds) && isThisAndAncestorsVisible(); - } - - private boolean isThisAndAncestorsVisible() { - // onVisibilityAggregated is only available on N+ devices, so on pre-N devices we check if this - // view and its ancestors are visible each time, in case one of the visibilities has changed. - return (VERSION.SDK_INT >= VERSION_CODES.N) ? thisAndAncestorsVisible : isShown(); - } - - @Override - public void onVisibilityAggregated(boolean isVisible) { - super.onVisibilityAggregated(isVisible); - this.thisAndAncestorsVisible = isVisible; + return getLocalVisibleRect(contentViewBounds) && thisAndAncestorsVisible; } private void ensureLabelsRemoved() {