From d707aeaa23713e58269ff59c81c95d9a69fceb2e Mon Sep 17 00:00:00 2001 From: Acclorite <140836141+Acclorite@users.noreply.github.com> Date: Mon, 7 Apr 2025 22:16:38 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Add=20secondary=20actio?= =?UTF-8?q?n=20to=20Dialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added optional secondary action to dialog (e.g. "Edit") --- .../core/components/dialog/Dialog.kt | 85 ++++++++++++------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/core/components/dialog/Dialog.kt b/app/src/main/java/ua/acclorite/book_story/presentation/core/components/dialog/Dialog.kt index 8f91d055..cb658cd5 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/core/components/dialog/Dialog.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/core/components/dialog/Dialog.kt @@ -61,6 +61,8 @@ fun Dialog( actionEnabled: Boolean?, onDismiss: () -> Unit, onAction: () -> Unit, + secondaryAction: String? = null, + onSecondaryAction: (() -> Unit)? = null, withContent: Boolean, items: (LazyListScope.() -> Unit) = {} ) { @@ -150,41 +152,66 @@ fun Dialog( modifier = Modifier .fillMaxWidth() .padding(horizontal = 24.dp), - horizontalArrangement = Arrangement.spacedBy(4.dp, Alignment.End) + verticalAlignment = Alignment.CenterVertically ) { - TextButton( - onClick = { - if (disableOnClick) { - actionClicked = true - } - onDismiss() - }, - enabled = !actionClicked - ) { - StyledText( - text = stringResource(id = R.string.cancel), - style = MaterialTheme.typography.labelLarge.copy( - color = MaterialTheme.colorScheme.primary + if (secondaryAction != null && onSecondaryAction != null) { + TextButton( + onClick = { + if (disableOnClick) { + actionClicked = true + } + onSecondaryAction() + }, + enabled = !actionClicked + ) { + StyledText( + text = secondaryAction, + style = MaterialTheme.typography.labelLarge.copy( + color = MaterialTheme.colorScheme.primary + ) ) - ) + } } - TextButton( - onClick = { - if (disableOnClick) { - actionClicked = true - } - onAction() - }, - enabled = actionEnabled == true && !actionClicked + Row( + modifier = Modifier.weight(1f), + horizontalArrangement = Arrangement.spacedBy(4.dp, Alignment.End), + verticalAlignment = Alignment.CenterVertically ) { - StyledText( - text = stringResource(id = R.string.ok), - style = MaterialTheme.typography.labelLarge.copy( - color = if (actionEnabled == true) MaterialTheme.colorScheme.primary - else MaterialTheme.colorScheme.primary.copy(0.5f) + TextButton( + onClick = { + if (disableOnClick) { + actionClicked = true + } + onDismiss() + }, + enabled = !actionClicked + ) { + StyledText( + text = stringResource(id = R.string.cancel), + style = MaterialTheme.typography.labelLarge.copy( + color = MaterialTheme.colorScheme.primary + ) ) - ) + } + + TextButton( + onClick = { + if (disableOnClick) { + actionClicked = true + } + onAction() + }, + enabled = actionEnabled == true && !actionClicked + ) { + StyledText( + text = stringResource(id = R.string.ok), + style = MaterialTheme.typography.labelLarge.copy( + color = if (actionEnabled == true) MaterialTheme.colorScheme.primary + else MaterialTheme.colorScheme.primary.copy(0.5f) + ) + ) + } } } }