Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Lots of fixes around Dialog #1384

Merged
merged 5 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

package app.tivi.overlays

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import app.tivi.common.compose.TiviDialog
import app.tivi.common.compose.rememberCoroutineScope
import app.tivi.common.compose.ui.AlertDialog
import app.tivi.common.compose.ui.AlertDialogDefaults
import com.slack.circuit.foundation.CircuitContent
import com.slack.circuit.overlay.Overlay
import com.slack.circuit.overlay.OverlayHost
Expand All @@ -18,17 +21,24 @@ class DialogOverlay<Model : Any, Result : Any>(
private val onDismiss: () -> Result,
private val content: @Composable (Model, OverlayNavigator<Result>) -> Unit,
) : Overlay<Result> {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
override fun Content(navigator: OverlayNavigator<Result>) {
val coroutineScope = rememberCoroutineScope()
TiviDialog(
AlertDialog(
onDismissRequest = { navigator.finish(onDismiss()) },
) {
// Delay setting the result until we've finished dismissing
content(model) { result ->
// This is the OverlayNavigator.finish() callback
coroutineScope.launch {
navigator.finish(result)
Surface(
shape = AlertDialogDefaults.shape,
color = AlertDialogDefaults.containerColor,
tonalElevation = AlertDialogDefaults.TonalElevation,
) {
// Delay setting the result until we've finished dismissing
content(model) { result ->
// This is the OverlayNavigator.finish() callback
coroutineScope.launch {
navigator.finish(result)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/ui/compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ kotlin {
api(libs.insetsx)

implementation(libs.materialdialogs.core)
implementation(libs.materialdialogs.datetime)
implementation(projects.thirdparty.composeMaterialDialogs.datetime)

implementation(libs.uuid)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,11 @@

package app.tivi.common.compose

import androidx.compose.foundation.BorderStroke
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import com.vanpra.composematerialdialogs.MaterialDialog
import com.vanpra.composematerialdialogs.MaterialDialogButtons
import com.vanpra.composematerialdialogs.MaterialDialogProperties
import com.vanpra.composematerialdialogs.MaterialDialogScope
import com.vanpra.composematerialdialogs.MaterialDialogState
import com.vanpra.composematerialdialogs.rememberMaterialDialogState

@Composable
expect fun Dialog(
Expand All @@ -29,49 +16,6 @@ expect fun Dialog(
content: @Composable () -> Unit,
)

@Composable
fun TiviDialog(
onDismissRequest: () -> Unit,
properties: DialogProperties = DialogProperties(),
content: @Composable () -> Unit,
) {
Dialog(onDismissRequest, properties) {
Surface(
shape = MaterialTheme.shapes.large,
color = MaterialTheme.colorScheme.surfaceColorAtElevation(6.dp),
) {
content()
}
}
}

@Composable
fun Material3Dialog(
dialogState: MaterialDialogState = rememberMaterialDialogState(),
properties: MaterialDialogProperties = MaterialDialogProperties(),
backgroundColor: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(6.dp),
shape: Shape = MaterialTheme.shapes.large,
border: BorderStroke? = null,
elevation: Dp = 0.dp,
autoDismiss: Boolean = true,
onCloseRequest: (MaterialDialogState) -> Unit = { it.hide() },
buttons: @Composable MaterialDialogButtons.() -> Unit = {},
content: @Composable MaterialDialogScope.() -> Unit,
) {
MaterialDialog(
dialogState = dialogState,
properties = properties,
backgroundColor = backgroundColor,
shape = shape,
border = border,
elevation = elevation,
autoDismiss = autoDismiss,
onCloseRequest = onCloseRequest,
buttons = buttons,
content = content,
)
}

@Immutable
data class DialogProperties(
val dismissOnBackPress: Boolean = true,
Expand Down
Loading