|
1 | 1 | package com.bnyro.contacts.presentation.components |
2 | 2 |
|
| 3 | +import androidx.activity.compose.PredictiveBackHandler |
3 | 4 | import androidx.compose.foundation.layout.fillMaxSize |
4 | 5 | import androidx.compose.material3.Surface |
5 | 6 | import androidx.compose.runtime.Composable |
6 | 7 | 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 |
7 | 12 | import androidx.compose.ui.ExperimentalComposeUiApi |
8 | 13 | import androidx.compose.ui.Modifier |
| 14 | +import androidx.compose.ui.draw.alpha |
9 | 15 | import androidx.compose.ui.platform.LocalView |
10 | 16 | import androidx.compose.ui.window.Dialog |
11 | 17 | import androidx.compose.ui.window.DialogProperties |
12 | 18 | import androidx.compose.ui.window.DialogWindowProvider |
| 19 | +import kotlinx.coroutines.CancellationException |
13 | 20 |
|
14 | 21 | @OptIn(ExperimentalComposeUiApi::class) |
15 | 22 | @Composable |
16 | 23 | fun FullScreenDialog(onClose: () -> Unit, content: @Composable () -> Unit) { |
| 24 | + var alpha by remember { |
| 25 | + mutableFloatStateOf(1f) |
| 26 | + } |
| 27 | + |
17 | 28 | Dialog( |
18 | 29 | properties = DialogProperties( |
19 | 30 | usePlatformDefaultWidth = false, |
20 | 31 | decorFitsSystemWindows = false |
21 | 32 | ), |
22 | 33 | onDismissRequest = onClose |
23 | 34 | ) { |
| 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 | + |
24 | 46 | val dialogWindowProvider = LocalView.current.parent as DialogWindowProvider |
25 | 47 | LaunchedEffect(dialogWindowProvider) { |
26 | 48 | dialogWindowProvider.window.setDimAmount(0f) |
27 | 49 | } |
28 | 50 |
|
29 | 51 | Surface( |
30 | | - modifier = Modifier.fillMaxSize() |
| 52 | + modifier = Modifier |
| 53 | + .fillMaxSize() |
| 54 | + .alpha(alpha) |
31 | 55 | ) { |
32 | 56 | content.invoke() |
33 | 57 | } |
|
0 commit comments