1 /*
2  * Copyright 2024 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.material3.internal
18 
19 import androidx.compose.animation.core.CubicBezierEasing
20 import androidx.compose.animation.core.Easing
21 import androidx.compose.runtime.Composable
22 import kotlinx.coroutines.flow.Flow
23 
24 // TODO(b/352352908): Remove once this API will be available in common
25 internal expect class BackEventCompat {
26     val touchX: Float
27     val touchY: Float
28     val progress: Float
29     val swipeEdge: Int
30 
31     companion object {
32         val EDGE_LEFT: Int
33         val EDGE_RIGHT: Int
34     }
35 }
36 
37 // TODO(b/352352908): Remove once this API will be available in common
BackHandlernull38 @Composable internal expect fun BackHandler(enabled: Boolean = true, onBack: () -> Unit)
39 
40 // TODO(b/352352908): Remove once this API will be available in common
41 @Composable
42 internal expect fun PredictiveBackHandler(
43     enabled: Boolean = true,
44     onBack: suspend (progress: Flow<BackEventCompat>) -> Unit
45 )
46 
47 private val PredictiveBackEasing: Easing = CubicBezierEasing(0.1f, 0.1f, 0f, 1f)
48 
49 internal object PredictiveBack {
50     internal fun transform(progress: Float) = PredictiveBackEasing.transform(progress)
51 }
52