-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de27d5d
commit 40961c7
Showing
4 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
app/src/main/kotlin/cn/super12138/todo/ui/components/Dialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cn.super12138.todo.ui.components | ||
|
||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.FilledTonalButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
|
||
@Composable | ||
fun BasicDialog( | ||
visible: Boolean, | ||
icon: ImageVector, | ||
title: String, | ||
text: @Composable (() -> Unit)? = null, | ||
confirmButton: String, | ||
dismissButton: String, | ||
onConfirm: () -> Unit, | ||
onDismiss: () -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
BasicDialog( | ||
visible = visible, | ||
icon = { | ||
Icon( | ||
imageVector = icon, | ||
contentDescription = null // 会跟下面的文本重复,所以设置为 null | ||
) | ||
}, | ||
title = { | ||
Text(title) | ||
}, | ||
text = text, | ||
confirmButton = { | ||
FilledTonalButton(onClick = onConfirm) { | ||
Text(confirmButton) | ||
} | ||
}, | ||
dismissButton = { | ||
TextButton(onClick = onDismiss) { | ||
Text(dismissButton) | ||
} | ||
}, | ||
onDismissRequest = onDismiss, | ||
modifier = modifier | ||
) | ||
} | ||
|
||
@Composable | ||
fun BasicDialog( | ||
visible: Boolean, | ||
icon: @Composable (() -> Unit)? = null, | ||
title: @Composable () -> Unit, | ||
text: @Composable (() -> Unit)? = null, | ||
confirmButton: (@Composable () -> Unit), | ||
dismissButton: (@Composable () -> Unit)? = null, | ||
onDismissRequest: () -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
if (visible) { | ||
AlertDialog( | ||
icon = icon, | ||
title = title, | ||
text = text, | ||
confirmButton = confirmButton, | ||
dismissButton = dismissButton, | ||
onDismissRequest = onDismissRequest, | ||
modifier = modifier | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters