Dialogs
Use these Compose Multiplatform Dialog components to prompt your users about an important decision they have to take in order to move forward.
Start aligned when large
/** * Add the following dependency to your build.gradle.kts: * * dependencies { * implementation("com.composables:core:1.11.2") * } */ val state = rememberDialogState(visible = true) LaunchedEffect(state.visible) { if (state.visible.not()) { delay(1000) state.visible = true } } BoxWithConstraints { val isCompact = maxWidth <= 600.dp Dialog(state) { Scrim(enter = fadeIn(), exit = fadeOut(), scrimColor = Color.Black.copy(0.3f)) DialogPanel( modifier = Modifier.systemBarsPadding() .padding(16.dp) .shadow(8.dp, ComposeTheme.shapes.roundL) .background(Color.White, ComposeTheme.shapes.round) .padding(24.dp), enter = scaleIn(initialScale = 0.8f) + fadeIn(tween(durationMillis = 250)), exit = scaleOut(targetScale = 0.6f) + fadeOut(tween(durationMillis = 150)) ) { Column( modifier = Modifier.let { if (isCompact) it.fillMaxWidth() else it.widthIn(min = 280.dp, max = 520.dp) }, horizontalAlignment = if (isCompact) Alignment.CenterHorizontally else Alignment.Start ) { BasicText( text = "Are you sure?", style = ComposeTheme.textStyles.base.copy( fontWeight = FontWeight.Medium, color = ComposeTheme.colors.gray900, textAlign = if (isCompact) TextAlign.Center else TextAlign.Start ) ) Spacer(Modifier.height(16.dp)) BasicText( text = "This action cannot be undone. Choose wisely.", style = ComposeTheme.textStyles.base.copy( fontWeight = FontWeight.Normal, color = ComposeTheme.colors.gray600, textAlign = if (isCompact) TextAlign.Center else TextAlign.Start ) ) Spacer(Modifier.height(24.dp)) Row( horizontalArrangement = Arrangement.spacedBy(8.dp, alignment = Alignment.End), modifier = Modifier.fillMaxWidth() ) { Box(Modifier.clip(ComposeTheme.shapes.roundL) .clickable(role = Role.Button) { state.visible = false } .border(1.dp, Color(0xFFBDBDBD), ComposeTheme.shapes.roundL) .padding(horizontal = 14.dp, vertical = 10.dp) .let { if (isCompact) it.weight(1f) else it }, contentAlignment = Alignment.Center ) { BasicText( text = "Cancel", style = ComposeTheme.textStyles.base.copy( color = Color(0xFF424242), fontWeight = FontWeight.Medium ) ) } Box( Modifier.clip(ComposeTheme.shapes.roundL) .clickable(role = Role.Button) { state.visible = false }.background(Color(0xFF212121)) .padding(horizontal = 14.dp, vertical = 10.dp) .let { if (isCompact) it.weight(1f) else it }, contentAlignment = Alignment.Center ) { BasicText( text = "Continue", style = ComposeTheme.textStyles.base.copy( color = Color.White, fontWeight = FontWeight.Medium ) ) } } } } } }
@Composable
fun NiceTry(){
Column {
BasicText("Nice try. Use code COMPOSE10 for a 10% discount on checkout ;)")
}
}
@Composable
fun NiceTry(){
Column {
BasicText("Nice try. Use code COMPOSE10 for a 10% discount on checkout ;)")
}
}
@Composable
fun NiceTry(){
Column {
BasicText("Nice try. Use code COMPOSE10 for a 10% discount on checkout ;)")
}
}
@Composable
fun NiceTry(){
Column {
BasicText("Nice try. Use code COMPOSE10 for a 10% discount on checkout ;)")
}
}
Phone
Sit tight. We are loading your preview
Start aligned when large