public class

NestedScrollingParentHelper

extends java.lang.Object

 java.lang.Object

↳androidx.core.view.NestedScrollingParentHelper

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.15.0-alpha02'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.15.0-alpha02

Artifact androidx.core:core:1.15.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.core:core com.android.support:support-compat

Androidx class mapping:

androidx.core.view.NestedScrollingParentHelper android.support.v4.view.NestedScrollingParentHelper

Overview

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

ViewGroup subclasses should instantiate a final instance of this class as a field at construction. For each ViewGroup 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 ViewCompat, ViewGroupCompat or ViewParentCompat compatibility shim static methods. This ensures interoperability with nested scrolling views on Android 5.0 Lollipop and newer.

Summary

Constructors
publicNestedScrollingParentHelper(ViewGroup viewGroup)

Construct a new helper for a given ViewGroup

Methods
public intgetNestedScrollAxes()

Return the current axes of nested scrolling for this ViewGroup.

public voidonNestedScrollAccepted(View child, View target, int axes)

Called when a nested scrolling operation initiated by a descendant view is accepted by this ViewGroup.

public voidonNestedScrollAccepted(View child, View target, int axes, int type)

Called when a nested scrolling operation initiated by a descendant view is accepted by this ViewGroup.

public voidonStopNestedScroll(View target)

React to a nested scroll operation ending.

public voidonStopNestedScroll(View target, int type)

React to a nested scroll operation ending.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public NestedScrollingParentHelper(ViewGroup viewGroup)

Construct a new helper for a given ViewGroup

Methods

public void onNestedScrollAccepted(View child, View target, int axes)

Called when a nested scrolling operation initiated by a descendant view is accepted by this ViewGroup.

This is a delegate method. Call it from your ViewGroup subclass method/NestedScrollingParent interface method with the same signature to implement the standard policy.

public void onNestedScrollAccepted(View child, View target, int axes, int type)

Called when a nested scrolling operation initiated by a descendant view is accepted by this ViewGroup.

This is a delegate method. Call it from your ViewGroup subclass method/NestedScrollingParent2 interface method with the same signature to implement the standard policy.

public int getNestedScrollAxes()

Return the current axes of nested scrolling for this ViewGroup.

This is a delegate method. Call it from your ViewGroup subclass method/NestedScrollingParent interface method with the same signature to implement the standard policy.

public void onStopNestedScroll(View target)

React to a nested scroll operation ending.

This is a delegate method. Call it from your ViewGroup subclass method/NestedScrollingParent interface method with the same signature to implement the standard policy.

public void onStopNestedScroll(View target, int type)

React to a nested scroll operation ending.

This is a delegate method. Call it from your ViewGroup subclass method/NestedScrollingParent2 interface method with the same signature to implement the standard policy.

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package androidx.core.view;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.view.ViewCompat.NestedScrollType;
import androidx.core.view.ViewCompat.ScrollAxis;

/**
 * Helper class for implementing nested scrolling parent views compatible with Android platform
 * versions earlier than Android 5.0 Lollipop (API 21).
 *
 * <p>{@link android.view.ViewGroup ViewGroup} subclasses should instantiate a final instance
 * of this class as a field at construction. For each <code>ViewGroup</code> 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.</p>
 *
 * <p>Views invoking nested scrolling functionality should always do so from the relevant
 * {@link androidx.core.view.ViewCompat}, {@link androidx.core.view.ViewGroupCompat} or
 * {@link androidx.core.view.ViewParentCompat} compatibility
 * shim static methods. This ensures interoperability with nested scrolling views on Android
 * 5.0 Lollipop and newer.</p>
 */
public class NestedScrollingParentHelper {
    private int mNestedScrollAxesTouch;
    private int mNestedScrollAxesNonTouch;

    /**
     * Construct a new helper for a given ViewGroup
     */
    public NestedScrollingParentHelper(@NonNull ViewGroup viewGroup) {
    }

    /**
     * Called when a nested scrolling operation initiated by a descendant view is accepted
     * by this ViewGroup.
     *
     * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup}
     * subclass method/{@link androidx.core.view.NestedScrollingParent} interface method with
     * the same signature to implement the standard policy.</p>
     */
    public void onNestedScrollAccepted(@NonNull View child, @NonNull View target,
            @ScrollAxis int axes) {
        onNestedScrollAccepted(child, target, axes, ViewCompat.TYPE_TOUCH);
    }

    /**
     * Called when a nested scrolling operation initiated by a descendant view is accepted
     * by this ViewGroup.
     *
     * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup}
     * subclass method/{@link androidx.core.view.NestedScrollingParent2} interface method with
     * the same signature to implement the standard policy.</p>
     */
    public void onNestedScrollAccepted(@NonNull View child, @NonNull View target,
            @ScrollAxis int axes, @NestedScrollType int type) {
        if (type == ViewCompat.TYPE_NON_TOUCH) {
            mNestedScrollAxesNonTouch = axes;
        } else {
            mNestedScrollAxesTouch = axes;
        }
    }

    /**
     * Return the current axes of nested scrolling for this ViewGroup.
     *
     * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup}
     * subclass method/{@link androidx.core.view.NestedScrollingParent} interface method with
     * the same signature to implement the standard policy.</p>
     */
    @ScrollAxis
    public int getNestedScrollAxes() {
        return mNestedScrollAxesTouch | mNestedScrollAxesNonTouch;
    }

    /**
     * React to a nested scroll operation ending.
     *
     * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup}
     * subclass method/{@link androidx.core.view.NestedScrollingParent} interface method with
     * the same signature to implement the standard policy.</p>
     */
    public void onStopNestedScroll(@NonNull View target) {
        onStopNestedScroll(target, ViewCompat.TYPE_TOUCH);
    }

    /**
     * React to a nested scroll operation ending.
     *
     * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup}
     * subclass method/{@link androidx.core.view.NestedScrollingParent2} interface method with
     * the same signature to implement the standard policy.</p>
     */
    public void onStopNestedScroll(@NonNull View target, @NestedScrollType int type) {
        if (type == ViewCompat.TYPE_NON_TOUCH) {
            mNestedScrollAxesNonTouch = ViewGroup.SCROLL_AXIS_NONE;
        } else {
            mNestedScrollAxesTouch = ViewGroup.SCROLL_AXIS_NONE;
        }
    }
}