Skip to content

Commit

Permalink
Dismissing on back and escape keys. Voyager back transition buggy.
Browse files Browse the repository at this point in the history
  • Loading branch information
HLCaptain committed Mar 24, 2024
1 parent fcb37a9 commit 890121b
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.LocalNavigator
Expand All @@ -23,6 +29,7 @@ import cafe.adriel.voyager.navigator.currentOrThrow
import cafe.adriel.voyager.transitions.ScreenTransition
import illyan.butler.ui.components.ButlerDialogContentHolder
import illyan.butler.ui.components.ButlerDialogSurface
import io.github.aakira.napier.Napier

val LocalDialogDismissRequest = compositionLocalOf { {} }

Expand All @@ -36,28 +43,35 @@ fun ButlerDialog(
if (isDialogOpen) {
// Don't use exit animations because
// it looks choppy while Dialog resizes due to content change.v
val navigator = LocalNavigator.currentOrThrow
val currentNavigator = LocalNavigator.currentOrThrow
var navigator by remember { mutableStateOf(currentNavigator) }
val onDismissRequest: () -> Unit = {
val currentScreen = navigator.lastItem
val currentScreen = navigator.items.last()
val firstScreen = navigator.items.first()
Napier.d("currentScreen: $currentScreen, firstScreen: $firstScreen")
if (currentScreen == firstScreen) {
onDialogClosed()
} else {
navigator.pop()
}
}
AlertDialog(
properties = DialogProperties(usePlatformDefaultWidth = false),
// Box(propagateMinConstraints = true) {}
Dialog(
onDismissRequest = onDismissRequest,
properties = DialogProperties(
usePlatformDefaultWidth = false,
dismissOnBackPress = true,
dismissOnClickOutside = false
),
) {
ButlerDialogContentHolder(
surface = {
ButlerDialogSurface(
// modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize(),
shape = RoundedCornerShape(0.dp)
) {
Box(
// modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
content = { it() }
)
Expand All @@ -67,7 +81,8 @@ fun ButlerDialog(
CompositionLocalProvider(
LocalDialogDismissRequest provides onDismissRequest,
) {
Navigator(startScreen) {
Navigator(startScreen) { nav ->
navigator = nav
ScreenTransition(
navigator = LocalNavigator.currentOrThrow,
transition = {
Expand Down

0 comments on commit 890121b

Please sign in to comment.