Skip to content

Commit ee03e1e

Browse files
committed
feat: support for predictive back gestures
1 parent 3e23723 commit ee03e1e

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
android:label="@string/app_name"
5454
android:supportsRtl="true"
5555
android:theme="@style/Theme.ConnectYou"
56-
tools:targetApi="33">
56+
tools:targetApi="33"
57+
android:enableOnBackInvokedCallback="true">
5758

5859
<activity
5960
android:name=".ui.activities.MainActivity"

app/src/main/java/com/bnyro/contacts/presentation/components/FullscreenDialog.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,57 @@
11
package com.bnyro.contacts.presentation.components
22

3+
import androidx.activity.compose.PredictiveBackHandler
34
import androidx.compose.foundation.layout.fillMaxSize
45
import androidx.compose.material3.Surface
56
import androidx.compose.runtime.Composable
67
import androidx.compose.runtime.LaunchedEffect
8+
import androidx.compose.runtime.getValue
9+
import androidx.compose.runtime.mutableFloatStateOf
10+
import androidx.compose.runtime.remember
11+
import androidx.compose.runtime.setValue
712
import androidx.compose.ui.ExperimentalComposeUiApi
813
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.draw.alpha
915
import androidx.compose.ui.platform.LocalView
1016
import androidx.compose.ui.window.Dialog
1117
import androidx.compose.ui.window.DialogProperties
1218
import androidx.compose.ui.window.DialogWindowProvider
19+
import kotlinx.coroutines.CancellationException
1320

1421
@OptIn(ExperimentalComposeUiApi::class)
1522
@Composable
1623
fun FullScreenDialog(onClose: () -> Unit, content: @Composable () -> Unit) {
24+
var alpha by remember {
25+
mutableFloatStateOf(1f)
26+
}
27+
1728
Dialog(
1829
properties = DialogProperties(
1930
usePlatformDefaultWidth = false,
2031
decorFitsSystemWindows = false
2132
),
2233
onDismissRequest = onClose
2334
) {
35+
PredictiveBackHandler { progress ->
36+
try {
37+
progress.collect { p ->
38+
alpha = 1 - 1.3f * p.progress
39+
}
40+
onClose()
41+
} catch (_: CancellationException) {
42+
alpha = 1f
43+
}
44+
}
45+
2446
val dialogWindowProvider = LocalView.current.parent as DialogWindowProvider
2547
LaunchedEffect(dialogWindowProvider) {
2648
dialogWindowProvider.window.setDimAmount(0f)
2749
}
2850

2951
Surface(
30-
modifier = Modifier.fillMaxSize()
52+
modifier = Modifier
53+
.fillMaxSize()
54+
.alpha(alpha)
3155
) {
3256
content.invoke()
3357
}

0 commit comments

Comments
 (0)