Skip to content

Commit

Permalink
[BottomSheet] Do not find scrolling child that's not visible
Browse files Browse the repository at this point in the history
Resolves #1834

PiperOrigin-RevId: 452813746
  • Loading branch information
drchen committed Jun 3, 2022
1 parent 71bfaca commit 1fe1618
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -1424,6 +1424,9 @@ boolean shouldHide(@NonNull View child, float yvel) {
@Nullable
@VisibleForTesting
View findScrollingChild(View view) {
if (view.getVisibility() != View.VISIBLE) {
return null;
}
if (ViewCompat.isNestedScrollingEnabled(view)) {
return view;
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.fail;

import android.content.Context;
Expand All @@ -32,6 +33,7 @@
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
Expand Down Expand Up @@ -961,6 +963,20 @@ public void testFindScrollingChildEnabled() {
assertThat(scrollingChild, is((View) enabledChild));
}

@Test
@SmallTest
public void testWontFindScrollingChildInvisible() {
Context context = activityTestRule.getActivity();
FrameLayout parent = new FrameLayout(context);
NestedScrollView invisibleChild = new NestedScrollView(context);
invisibleChild.setNestedScrollingEnabled(true);
invisibleChild.setVisibility(View.INVISIBLE);
parent.addView(invisibleChild);

View scrollingChild = getBehavior().findScrollingChild(parent);
assertThat(scrollingChild, nullValue());
}

private void checkSetState(final int state, Matcher<View> matcher) throws Throwable {
registerIdlingResourceCallback();
try {
Expand Down

0 comments on commit 1fe1618

Please sign in to comment.