NestedScrollingChildHelper

Added in 1.1.0

public class NestedScrollingChildHelper


Helper class for implementing nested scrolling child views compatible with Android platform versions earlier than Android 5.0 Lollipop (API 21).

View subclasses should instantiate a final instance of this class as a field at construction. For each View method that has a matching method signature in this class, delegate the operation to the helper instance in an overridden method implementation. This implements the standard framework policy for nested scrolling.

Views invoking nested scrolling functionality should always do so from the relevant androidx.core.view.ViewCompat, androidx.core.view.ViewGroupCompat or androidx.core.view.ViewParentCompat compatibility shim static methods. This ensures interoperability with nested scrolling views on Android 5.0 Lollipop and newer.

Summary

Public constructors

Construct a new helper for a given view.

Public methods

boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)

Dispatch a nested fling operation to the current nested scrolling parent.

boolean
dispatchNestedPreFling(float velocityX, float velocityY)

Dispatch a nested pre-fling operation to the current nested scrolling parent.

boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    @Nullable int[] consumed,
    @Nullable int[] offsetInWindow
)

Dispatch one step of a nested pre-scrolling operation to the current nested scrolling parent.

boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    @Nullable int[] consumed,
    @Nullable int[] offsetInWindow,
    int type
)

Dispatch one step of a nested pre-scrolling operation to the current nested scrolling parent.

boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow
)

Dispatch one step of a nested scrolling operation to the current nested scrolling parent.

boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow,
    int type
)

Dispatch one step of a nested scrolling operation to the current nested scrolling parent.

void
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow,
    int type,
    @Nullable int[] consumed
)

Dispatch one step of a nested scrolling operation to the current nested scrolling parent.

boolean

Check if this view has a nested scrolling parent view currently receiving events for a nested scroll in progress with the type of touch.

boolean

Check if this view has a nested scrolling parent view currently receiving events for a nested scroll in progress with the given type.

boolean

Check if nested scrolling is enabled for this view.

void

View subclasses should always call this method on their NestedScrollingChildHelper when detached from a window.

void

Called when a nested scrolling child stops its current nested scroll operation.

void
setNestedScrollingEnabled(boolean enabled)

Enable nested scrolling.

boolean

Start a new nested scroll for this view.

boolean
startNestedScroll(int axes, int type)

Start a new nested scroll for this view.

void

Stop a nested scroll in progress.

void
stopNestedScroll(int type)

Stop a nested scroll in progress.

Public constructors

NestedScrollingChildHelper

Added in 1.1.0
public NestedScrollingChildHelper(@NonNull View view)

Construct a new helper for a given view.

Public methods

dispatchNestedFling

Added in 1.1.0
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed)

Dispatch a nested fling operation to the current nested scrolling parent.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Returns
boolean

true if the parent consumed the nested fling

dispatchNestedPreFling

Added in 1.1.0
public boolean dispatchNestedPreFling(float velocityX, float velocityY)

Dispatch a nested pre-fling operation to the current nested scrolling parent.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Returns
boolean

true if the parent consumed the nested fling

dispatchNestedPreScroll

Added in 1.1.0
public boolean dispatchNestedPreScroll(
    int dx,
    int dy,
    @Nullable int[] consumed,
    @Nullable int[] offsetInWindow
)

Dispatch one step of a nested pre-scrolling operation to the current nested scrolling parent.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Returns
boolean

true if the parent consumed any of the nested scroll

dispatchNestedPreScroll

Added in 1.1.0
public boolean dispatchNestedPreScroll(
    int dx,
    int dy,
    @Nullable int[] consumed,
    @Nullable int[] offsetInWindow,
    int type
)

Dispatch one step of a nested pre-scrolling operation to the current nested scrolling parent.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild2 interface method with the same signature to implement the standard policy.

Returns
boolean

true if the parent consumed any of the nested scroll

dispatchNestedScroll

Added in 1.1.0
public boolean dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow
)

Dispatch one step of a nested scrolling operation to the current nested scrolling parent.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Returns
boolean

true if the parent consumed any of the nested scroll distance

dispatchNestedScroll

Added in 1.1.0
public boolean dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow,
    int type
)

Dispatch one step of a nested scrolling operation to the current nested scrolling parent.

This is a delegate method. Call it from your NestedScrollingChild2 interface method with the same signature to implement the standard policy.

Returns
boolean

true if the parent consumed any of the nested scroll distance

dispatchNestedScroll

Added in 1.1.0
public void dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow,
    int type,
    @Nullable int[] consumed
)

Dispatch one step of a nested scrolling operation to the current nested scrolling parent.

This is a delegate method. Call it from your NestedScrollingChild3 interface method with the same signature to implement the standard policy.

hasNestedScrollingParent

Added in 1.1.0
public boolean hasNestedScrollingParent()

Check if this view has a nested scrolling parent view currently receiving events for a nested scroll in progress with the type of touch.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Returns
boolean

true if this view has a nested scrolling parent, false otherwise

hasNestedScrollingParent

Added in 1.1.0
public boolean hasNestedScrollingParent(int type)

Check if this view has a nested scrolling parent view currently receiving events for a nested scroll in progress with the given type.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Returns
boolean

true if this view has a nested scrolling parent, false otherwise

isNestedScrollingEnabled

Added in 1.1.0
public boolean isNestedScrollingEnabled()

Check if nested scrolling is enabled for this view.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Returns
boolean

true if nested scrolling is enabled for this view

onDetachedFromWindow

Added in 1.1.0
public void onDetachedFromWindow()

View subclasses should always call this method on their NestedScrollingChildHelper when detached from a window.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

onStopNestedScroll

Added in 1.1.0
public void onStopNestedScroll(@NonNull View child)

Called when a nested scrolling child stops its current nested scroll operation.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Parameters
@NonNull View child

Child view stopping its nested scroll. This may not be a direct child view.

setNestedScrollingEnabled

Added in 1.1.0
public void setNestedScrollingEnabled(boolean enabled)

Enable nested scrolling.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Parameters
boolean enabled

true to enable nested scrolling dispatch from this view, false otherwise

startNestedScroll

Added in 1.1.0
public boolean startNestedScroll(int axes)

Start a new nested scroll for this view.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

Parameters
int axes

Supported nested scroll axes. See startNestedScroll.

Returns
boolean

true if a cooperating parent view was found and nested scrolling started successfully

startNestedScroll

Added in 1.1.0
public boolean startNestedScroll(int axes, int type)

Start a new nested scroll for this view.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild2 interface method with the same signature to implement the standard policy.

Parameters
int axes

Supported nested scroll axes. See startNestedScroll.

int type

type of the scroll.

Returns
boolean

true if a cooperating parent view was found and nested scrolling started successfully

stopNestedScroll

Added in 1.1.0
public void stopNestedScroll()

Stop a nested scroll in progress.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild interface method with the same signature to implement the standard policy.

stopNestedScroll

Added in 1.1.0
public void stopNestedScroll(int type)

Stop a nested scroll in progress.

This is a delegate method. Call it from your View subclass method/androidx.core.view.NestedScrollingChild2 interface method with the same signature to implement the standard policy.