|
1 | 1 | package daily.dayo.presentation.screen.account |
2 | 2 |
|
3 | | -import android.annotation.SuppressLint |
| 3 | +import androidx.compose.animation.core.animateFloatAsState |
| 4 | +import androidx.compose.foundation.background |
| 5 | +import androidx.compose.foundation.clickable |
| 6 | +import androidx.compose.foundation.interaction.MutableInteractionSource |
4 | 7 | import androidx.compose.foundation.layout.Box |
| 8 | +import androidx.compose.foundation.layout.fillMaxSize |
| 9 | +import androidx.compose.foundation.layout.navigationBarsPadding |
5 | 10 | import androidx.compose.foundation.layout.padding |
6 | | -import androidx.compose.material.Scaffold |
| 11 | +import androidx.compose.foundation.layout.systemBarsPadding |
| 12 | +import androidx.compose.material3.BottomSheetScaffold |
7 | 13 | import androidx.compose.material3.ExperimentalMaterial3Api |
| 14 | +import androidx.compose.material3.SheetValue |
8 | 15 | import androidx.compose.material3.SnackbarHost |
9 | 16 | import androidx.compose.material3.SnackbarHostState |
10 | 17 | import androidx.compose.runtime.Composable |
| 18 | +import androidx.compose.runtime.derivedStateOf |
11 | 19 | import androidx.compose.runtime.getValue |
12 | 20 | import androidx.compose.runtime.mutableStateOf |
13 | 21 | import androidx.compose.runtime.remember |
14 | 22 | import androidx.compose.runtime.rememberCoroutineScope |
15 | 23 | import androidx.compose.runtime.setValue |
16 | 24 | import androidx.compose.ui.Modifier |
| 25 | +import androidx.compose.ui.unit.dp |
17 | 26 | import androidx.navigation.compose.NavHost |
| 27 | +import daily.dayo.presentation.theme.Dark |
18 | 28 | import daily.dayo.presentation.view.dialog.getBottomSheetDialogState |
| 29 | +import kotlinx.coroutines.launch |
19 | 30 |
|
20 | | -@SuppressLint("UnusedMaterialScaffoldPaddingParameter") |
21 | 31 | @OptIn(ExperimentalMaterial3Api::class) |
22 | 32 | @Composable |
23 | 33 | internal fun AccountScreen( |
24 | 34 | navigator: AccountNavigator = rememberAccountNavigator() |
25 | 35 | ) { |
26 | 36 | val coroutineScope = rememberCoroutineScope() |
27 | 37 | val snackBarHostState = remember { SnackbarHostState() } |
| 38 | + var bottomSheetContent by remember { mutableStateOf<(@Composable () -> Unit)?>(null) } |
28 | 39 | val bottomSheetState = getBottomSheetDialogState() |
29 | | - var bottomSheet: (@Composable () -> Unit)? by remember { mutableStateOf(null) } |
30 | | - val bottomSheetContent: (@Composable () -> Unit) -> Unit = { |
31 | | - bottomSheet = it |
| 40 | + val bottomSheetDimAlpha by remember { |
| 41 | + derivedStateOf { if (bottomSheetState.bottomSheetState.currentValue == SheetValue.Expanded) 0.6f else 0f } |
32 | 42 | } |
33 | | - Scaffold( |
34 | | - snackbarHost = { SnackbarHost(hostState = snackBarHostState) } |
35 | | - ) { |
36 | | - Scaffold( |
37 | | - bottomBar = { bottomSheet?.let { it() } } |
38 | | - ) { |
39 | | - Scaffold( |
40 | | - content = { innerPadding -> |
41 | | - Box(Modifier.padding(innerPadding)) { |
42 | | - NavHost( |
43 | | - navController = navigator.navController, |
44 | | - startDestination = AccountScreen.SignIn.route |
45 | | - ) { |
46 | | - signInNavGraph( |
47 | | - coroutineScope = coroutineScope, |
48 | | - snackBarHostState = snackBarHostState, |
49 | | - navController = navigator.navController, |
50 | | - onBackClick = { navigator.popBackStack() }, |
51 | | - navigateToSignIn = { navigator.navigateSignIn() }, |
52 | | - navigateToSignInEmail = { navigator.navigateSignInEmail() }, |
53 | | - navigateToResetPassword = { navigator.navigateResetPassword() }, |
54 | | - navigateToSignUpEmail = { navigator.navigateSignUpEmail() }, |
55 | | - navigateToProfileSetting = { navigator.navigateProfileSetting() }, |
56 | | - navigateToRules = { route -> navigator.navigateRules(route) }, |
57 | | - bottomSheetState = bottomSheetState, |
58 | | - bottomSheetContent = bottomSheetContent |
59 | | - ) |
| 43 | + val animatedDimAlpha by animateFloatAsState(targetValue = bottomSheetDimAlpha) |
| 44 | + |
| 45 | + BottomSheetScaffold( |
| 46 | + modifier = Modifier.systemBarsPadding(), |
| 47 | + scaffoldState = bottomSheetState, |
| 48 | + sheetDragHandle = null, |
| 49 | + sheetContent = { |
| 50 | + Box(modifier = Modifier.navigationBarsPadding()) { |
| 51 | + bottomSheetContent?.invoke() |
| 52 | + } |
| 53 | + }, |
| 54 | + sheetPeekHeight = 0.dp, |
| 55 | + snackbarHost = { |
| 56 | + SnackbarHost( |
| 57 | + hostState = snackBarHostState, |
| 58 | + modifier = Modifier.navigationBarsPadding() |
| 59 | + ) |
| 60 | + }, |
| 61 | + content = { innerPadding -> |
| 62 | + Box(Modifier.padding(innerPadding)) { |
| 63 | + NavHost( |
| 64 | + navController = navigator.navController, |
| 65 | + startDestination = AccountScreen.SignIn.route |
| 66 | + ) { |
| 67 | + signInNavGraph( |
| 68 | + coroutineScope = coroutineScope, |
| 69 | + snackBarHostState = snackBarHostState, |
| 70 | + navController = navigator.navController, |
| 71 | + onBackClick = { navigator.popBackStack() }, |
| 72 | + navigateToSignIn = { navigator.navigateSignIn() }, |
| 73 | + navigateToSignInEmail = { navigator.navigateSignInEmail() }, |
| 74 | + navigateToResetPassword = { navigator.navigateResetPassword() }, |
| 75 | + navigateToSignUpEmail = { navigator.navigateSignUpEmail() }, |
| 76 | + navigateToProfileSetting = { navigator.navigateProfileSetting() }, |
| 77 | + navigateToRules = { route -> navigator.navigateRules(route) }, |
| 78 | + bottomSheetState = bottomSheetState, |
| 79 | + bottomSheetContent = { content -> |
| 80 | + bottomSheetContent = content |
60 | 81 | } |
61 | | - } |
62 | | - }) |
| 82 | + ) |
| 83 | + } |
| 84 | + |
| 85 | + if (animatedDimAlpha > 0f) { |
| 86 | + Box( |
| 87 | + modifier = Modifier |
| 88 | + .fillMaxSize() |
| 89 | + .background(Dark.copy(alpha = animatedDimAlpha)) |
| 90 | + .clickable(indication = null, interactionSource = remember { MutableInteractionSource() }) { |
| 91 | + coroutineScope.launch { bottomSheetState.bottomSheetState.hide() } |
| 92 | + } |
| 93 | + ) |
| 94 | + } |
| 95 | + } |
63 | 96 | } |
64 | | - } |
| 97 | + ) |
65 | 98 | } |
66 | 99 |
|
67 | 100 | sealed class AccountScreen(val route: String) { |
|
0 commit comments