1 /*
2  * Copyright 2021 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 package androidx.compose.foundation.gestures
18 
19 import androidx.compose.runtime.Stable
20 
21 /**
22  * Interface to specify fling behavior.
23  *
24  * When drag has ended with velocity in [scrollable], [performFling] is invoked to perform fling
25  * animation and update state via [ScrollScope.scrollBy]
26  */
27 @Stable
28 interface FlingBehavior {
29     /**
30      * Perform settling via fling animation with given velocity and suspend until fling has
31      * finished.
32      *
33      * This functions is called with [ScrollScope] to drive the state change of the
34      * [androidx.compose.foundation.gestures.ScrollableState] via [ScrollScope.scrollBy].
35      *
36      * This function must return correct velocity left after it is finished flinging in order to
37      * guarantee proper nested scroll support.
38      *
39      * @param initialVelocity velocity available for fling in the orientation specified in
40      *   [androidx.compose.foundation.gestures.scrollable] that invoked this method.
41      * @return remaining velocity after fling operation has ended
42      */
performFlingnull43     suspend fun ScrollScope.performFling(initialVelocity: Float): Float
44 }
45