1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 package androidx.core.view;
19 
20 import android.view.View;
21 
22 import org.jspecify.annotations.NonNull;
23 import org.jspecify.annotations.Nullable;
24 
25 /**
26  * This interface should be implemented by {@link View View} subclasses that wish
27  * to support dispatching nested scrolling operations to a cooperating parent
28  * {@link android.view.ViewGroup ViewGroup}.
29  *
30  * <p>Classes implementing this interface should create a final instance of a
31  * {@link NestedScrollingChildHelper} as a field and delegate any View methods to the
32  * <code>NestedScrollingChildHelper</code> methods of the same signature.</p>
33  *
34  * <p>Views invoking nested scrolling functionality should always do so from the relevant
35  * {@link ViewCompat}, {@link ViewGroupCompat} or {@link ViewParentCompat} compatibility
36  * shim static methods. This ensures interoperability with nested scrolling views on all versions
37  * of Android.</p>
38  */
39 public interface NestedScrollingChild3 extends NestedScrollingChild2 {
40 
41     /**
42      * Dispatch one step of a nested scroll in progress.
43      *
44      * <p>Implementations of views that support nested scrolling should call this to report
45      * info about a scroll in progress to the current nested scrolling parent. If a nested scroll
46      * is not currently in progress or nested scrolling is not
47      * {@link #isNestedScrollingEnabled() enabled} for this view this method does nothing.
48      *
49      * <p>Compatible View implementations should also call
50      * {@link #dispatchNestedPreScroll(int, int, int[], int[], int) dispatchNestedPreScroll} before
51      * consuming a component of the scroll event themselves.
52      *
53      * <p>The original nested scrolling child (where the input events were received to start the
54      * scroll) must provide a non-null <code>consumed</code> parameter with values {0, 0}.
55      *
56      * @param dxConsumed Horizontal distance in pixels consumed by this view during this scroll step
57      * @param dyConsumed Vertical distance in pixels consumed by this view during this scroll step
58      * @param dxUnconsumed Horizontal scroll distance in pixels not consumed by this view
59      * @param dyUnconsumed Horizontal scroll distance in pixels not consumed by this view
60      * @param offsetInWindow Optional. If not null, on return this will contain the offset
61      *                       in local view coordinates of this view from before this operation
62      *                       to after it completes. View implementations may use this to adjust
63      *                       expected input coordinate tracking.
64      * @param type the type of input which cause this scroll event
65      * @param consumed Output. Upon this method returning, will contain the original values plus any
66      *                 scroll distances consumed by all of this view's nested scrolling parents up
67      *                 the view hierarchy. Index 0 for the x dimension, and index 1 for the y
68      *                 dimension
69      *
70      * @see NestedScrollingParent3#onNestedScroll(View, int, int, int, int, int, int[])
71      */
dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int @Nullable [] offsetInWindow, @ViewCompat.NestedScrollType int type, int @NonNull [] consumed)72     void dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed,
73             int @Nullable [] offsetInWindow, @ViewCompat.NestedScrollType int type,
74             int @NonNull [] consumed);
75 }
76