Skip to content

[HideViewOnScrollBehavior] Add a method to get the HideViewOnScrollBehavior associated with the view #4768

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,24 @@ public void disableOnTouchExploration(boolean disableOnTouchExploration) {
public boolean isDisabledOnTouchExploration() {
return disableOnTouchExploration;
}

/**
* A utility function to get the {@link HideViewOnScrollBehavior} associated with the {@code view}.
*
* @param view The {@link View} with {@link HideViewOnScrollBehavior}.
* @return The {@link HideViewOnScrollBehavior} associated with the {@code view}.
*/
@NonNull
@SuppressWarnings("unchecked")
public static <V extends View> HideViewOnScrollBehavior<V> from(@NonNull V view) {
ViewGroup.LayoutParams params = view.getLayoutParams();
if (!(params instanceof LayoutParams)) {
throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
}
CoordinatorLayout.Behavior<?> behavior = ((LayoutParams) params).getBehavior();
if (!(behavior instanceof HideViewOnScrollBehavior)) {
throw new IllegalArgumentException("The view is not associated with HideViewOnScrollBehavior");
}
return (HideViewOnScrollBehavior<V>) behavior;
}
}