Merge pull request #1726 from vector-im/feature/bma/improveDialogApi
Improve dialog api
This commit is contained in:
commit
0e84fe1ef3
5 changed files with 67 additions and 40 deletions
|
|
@ -32,17 +32,17 @@ import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
@Composable
|
@Composable
|
||||||
fun ErrorDialog(
|
fun ErrorDialog(
|
||||||
content: String,
|
content: String,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String = ErrorDialogDefaults.title,
|
title: String = ErrorDialogDefaults.title,
|
||||||
submitText: String = ErrorDialogDefaults.submitText,
|
submitText: String = ErrorDialogDefaults.submitText,
|
||||||
onDismiss: () -> Unit = {},
|
|
||||||
) {
|
) {
|
||||||
AlertDialog(modifier = modifier, onDismissRequest = onDismiss) {
|
AlertDialog(modifier = modifier, onDismissRequest = onDismiss) {
|
||||||
ErrorDialogContent(
|
ErrorDialogContent(
|
||||||
title = title,
|
title = title,
|
||||||
content = content,
|
content = content,
|
||||||
submitText = submitText,
|
submitText = submitText,
|
||||||
onSubmitText = onDismiss,
|
onSubmitClicked = onDismiss,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -50,17 +50,17 @@ fun ErrorDialog(
|
||||||
@Composable
|
@Composable
|
||||||
private fun ErrorDialogContent(
|
private fun ErrorDialogContent(
|
||||||
content: String,
|
content: String,
|
||||||
|
onSubmitClicked: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String = ErrorDialogDefaults.title,
|
title: String = ErrorDialogDefaults.title,
|
||||||
submitText: String = ErrorDialogDefaults.submitText,
|
submitText: String = ErrorDialogDefaults.submitText,
|
||||||
onSubmitText: () -> Unit = {},
|
|
||||||
) {
|
) {
|
||||||
SimpleAlertDialogContent(
|
SimpleAlertDialogContent(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
title = title,
|
title = title,
|
||||||
content = content,
|
content = content,
|
||||||
cancelText = submitText,
|
submitText = submitText,
|
||||||
onCancelClicked = onSubmitText,
|
onSubmitClicked = onSubmitClicked,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,6 +76,7 @@ internal fun ErrorDialogPreview() {
|
||||||
DialogPreview {
|
DialogPreview {
|
||||||
ErrorDialogContent(
|
ErrorDialogContent(
|
||||||
content = "Content",
|
content = "Content",
|
||||||
|
onSubmitClicked = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,8 @@ import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ListDialog(
|
fun ListDialog(
|
||||||
onDismissRequest: () -> Unit,
|
|
||||||
onSubmit: () -> Unit,
|
onSubmit: () -> Unit,
|
||||||
|
onDismissRequest: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
subtitle: String? = null,
|
subtitle: String? = null,
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ fun SingleSelectionDialog(
|
||||||
private fun SingleSelectionDialogContent(
|
private fun SingleSelectionDialogContent(
|
||||||
options: ImmutableList<ListOption>,
|
options: ImmutableList<ListOption>,
|
||||||
onOptionSelected: (Int) -> Unit,
|
onOptionSelected: (Int) -> Unit,
|
||||||
onDismissRequest: () -> Unit,
|
|
||||||
dismissButtonTitle: String,
|
dismissButtonTitle: String,
|
||||||
|
onDismissRequest: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
initialSelection: Int? = null,
|
initialSelection: Int? = null,
|
||||||
|
|
@ -88,8 +88,8 @@ private fun SingleSelectionDialogContent(
|
||||||
title = title,
|
title = title,
|
||||||
subtitle = subtitle,
|
subtitle = subtitle,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
cancelText = dismissButtonTitle,
|
submitText = dismissButtonTitle,
|
||||||
onCancelClicked = onDismissRequest,
|
onSubmitClicked = onDismissRequest,
|
||||||
applyPaddingToContents = false,
|
applyPaddingToContents = false,
|
||||||
) {
|
) {
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
|
|
|
||||||
|
|
@ -53,51 +53,51 @@ import kotlin.math.max
|
||||||
@Composable
|
@Composable
|
||||||
internal fun SimpleAlertDialogContent(
|
internal fun SimpleAlertDialogContent(
|
||||||
content: String,
|
content: String,
|
||||||
cancelText: String,
|
submitText: String,
|
||||||
onCancelClicked: () -> Unit,
|
onSubmitClicked: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
subtitle: @Composable (() -> Unit)? = null,
|
subtitle: @Composable (() -> Unit)? = null,
|
||||||
submitText: String? = null,
|
|
||||||
destructiveSubmit: Boolean = false,
|
destructiveSubmit: Boolean = false,
|
||||||
onSubmitClicked: () -> Unit = {},
|
cancelText: String? = null,
|
||||||
|
onCancelClicked: () -> Unit = {},
|
||||||
thirdButtonText: String? = null,
|
thirdButtonText: String? = null,
|
||||||
onThirdButtonClicked: () -> Unit = {},
|
onThirdButtonClicked: () -> Unit = {},
|
||||||
applyPaddingToContents: Boolean = true,
|
applyPaddingToContents: Boolean = true,
|
||||||
icon: @Composable (() -> Unit)? = null,
|
icon: @Composable (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
SimpleAlertDialogContent(
|
SimpleAlertDialogContent(
|
||||||
|
modifier = modifier,
|
||||||
|
icon = icon,
|
||||||
|
title = title,
|
||||||
|
subtitle = subtitle,
|
||||||
content = {
|
content = {
|
||||||
Text(
|
Text(
|
||||||
text = content,
|
text = content,
|
||||||
style = ElementTheme.materialTypography.bodyMedium,
|
style = ElementTheme.materialTypography.bodyMedium,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
cancelText = cancelText,
|
|
||||||
onCancelClicked = onCancelClicked,
|
|
||||||
modifier = modifier,
|
|
||||||
title = title,
|
|
||||||
subtitle = subtitle,
|
|
||||||
submitText = submitText,
|
submitText = submitText,
|
||||||
destructiveSubmit = destructiveSubmit,
|
destructiveSubmit = destructiveSubmit,
|
||||||
onSubmitClicked = onSubmitClicked,
|
onSubmitClicked = onSubmitClicked,
|
||||||
|
cancelText = cancelText,
|
||||||
|
onCancelClicked = onCancelClicked,
|
||||||
thirdButtonText = thirdButtonText,
|
thirdButtonText = thirdButtonText,
|
||||||
onThirdButtonClicked = onThirdButtonClicked,
|
onThirdButtonClicked = onThirdButtonClicked,
|
||||||
icon = icon,
|
|
||||||
applyPaddingToContents = applyPaddingToContents,
|
applyPaddingToContents = applyPaddingToContents,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun SimpleAlertDialogContent(
|
internal fun SimpleAlertDialogContent(
|
||||||
cancelText: String,
|
submitText: String,
|
||||||
onCancelClicked: () -> Unit,
|
onSubmitClicked: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
subtitle: @Composable (() -> Unit)? = null,
|
subtitle: @Composable (() -> Unit)? = null,
|
||||||
submitText: String? = null,
|
|
||||||
destructiveSubmit: Boolean = false,
|
destructiveSubmit: Boolean = false,
|
||||||
onSubmitClicked: () -> Unit = {},
|
cancelText: String? = null,
|
||||||
|
onCancelClicked: () -> Unit = {},
|
||||||
thirdButtonText: String? = null,
|
thirdButtonText: String? = null,
|
||||||
onThirdButtonClicked: () -> Unit = {},
|
onThirdButtonClicked: () -> Unit = {},
|
||||||
applyPaddingToContents: Boolean = true,
|
applyPaddingToContents: Boolean = true,
|
||||||
|
|
@ -121,15 +121,13 @@ internal fun SimpleAlertDialogContent(
|
||||||
onClick = onThirdButtonClicked,
|
onClick = onThirdButtonClicked,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TextButton(
|
if (cancelText != null) {
|
||||||
modifier = Modifier.testTag(
|
TextButton(
|
||||||
if (submitText == null) TestTags.dialogPositive else TestTags.dialogNegative
|
modifier = Modifier.testTag(TestTags.dialogNegative),
|
||||||
),
|
text = cancelText,
|
||||||
text = cancelText,
|
size = ButtonSize.Medium,
|
||||||
size = ButtonSize.Medium,
|
onClick = onCancelClicked,
|
||||||
onClick = onCancelClicked,
|
)
|
||||||
)
|
|
||||||
if (submitText != null) {
|
|
||||||
Button(
|
Button(
|
||||||
modifier = Modifier.testTag(TestTags.dialogPositive),
|
modifier = Modifier.testTag(TestTags.dialogPositive),
|
||||||
text = submitText,
|
text = submitText,
|
||||||
|
|
@ -138,6 +136,15 @@ internal fun SimpleAlertDialogContent(
|
||||||
onClick = onSubmitClicked,
|
onClick = onSubmitClicked,
|
||||||
destructive = destructiveSubmit,
|
destructive = destructiveSubmit,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
TextButton(
|
||||||
|
modifier = Modifier.testTag(TestTags.dialogPositive),
|
||||||
|
text = submitText,
|
||||||
|
enabled = enabled,
|
||||||
|
size = ButtonSize.Medium,
|
||||||
|
onClick = onSubmitClicked,
|
||||||
|
destructive = destructiveSubmit,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -438,8 +445,8 @@ internal fun DialogWithTitleIconAndOkButtonPreview() {
|
||||||
},
|
},
|
||||||
title = "Dialog Title",
|
title = "Dialog Title",
|
||||||
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
|
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
|
||||||
cancelText = "OK",
|
submitText = "OK",
|
||||||
onCancelClicked = {},
|
onSubmitClicked = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -454,8 +461,8 @@ internal fun DialogWithTitleAndOkButtonPreview() {
|
||||||
SimpleAlertDialogContent(
|
SimpleAlertDialogContent(
|
||||||
title = "Dialog Title",
|
title = "Dialog Title",
|
||||||
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
|
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
|
||||||
cancelText = "OK",
|
submitText = "OK",
|
||||||
onCancelClicked = {},
|
onSubmitClicked = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -469,8 +476,8 @@ internal fun DialogWithOnlyMessageAndOkButtonPreview() {
|
||||||
DialogPreview {
|
DialogPreview {
|
||||||
SimpleAlertDialogContent(
|
SimpleAlertDialogContent(
|
||||||
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
|
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
|
||||||
cancelText = "OK",
|
submitText = "OK",
|
||||||
onCancelClicked = {},
|
onSubmitClicked = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -478,7 +485,6 @@ internal fun DialogWithOnlyMessageAndOkButtonPreview() {
|
||||||
|
|
||||||
@Preview(group = PreviewGroup.Dialogs, name = "Dialog with destructive button")
|
@Preview(group = PreviewGroup.Dialogs, name = "Dialog with destructive button")
|
||||||
@Composable
|
@Composable
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
internal fun DialogWithDestructiveButtonPreview() {
|
internal fun DialogWithDestructiveButtonPreview() {
|
||||||
ElementThemedPreview(showBackground = false) {
|
ElementThemedPreview(showBackground = false) {
|
||||||
DialogPreview {
|
DialogPreview {
|
||||||
|
|
@ -488,7 +494,24 @@ internal fun DialogWithDestructiveButtonPreview() {
|
||||||
cancelText = "Cancel",
|
cancelText = "Cancel",
|
||||||
submitText = "Delete",
|
submitText = "Delete",
|
||||||
destructiveSubmit = true,
|
destructiveSubmit = true,
|
||||||
onCancelClicked = {},
|
onSubmitClicked = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(group = PreviewGroup.Dialogs, name = "Dialog with third button")
|
||||||
|
@Composable
|
||||||
|
internal fun DialogWithThirdButtonPreview() {
|
||||||
|
ElementThemedPreview(showBackground = false) {
|
||||||
|
DialogPreview {
|
||||||
|
SimpleAlertDialogContent(
|
||||||
|
title = "Dialog Title",
|
||||||
|
content = "A dialog with a third button",
|
||||||
|
cancelText = "Cancel",
|
||||||
|
submitText = "Delete",
|
||||||
|
thirdButtonText = "Other",
|
||||||
|
onSubmitClicked = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:e465788d3307cc42d3f1c322d926e9088994c6b7a5cd338a74dd95a8dfe2977a
|
||||||
|
size 31190
|
||||||
Loading…
Add table
Add a link
Reference in a new issue