From 9209347d86fdcea28f78efc14f58b7b2f1333d76 Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 1 Sep 2024 17:26:52 +0200 Subject: [PATCH] Added option that dialogs on mobile platforms use more than platform's default dialog width (which makes AddAccount- and EnterTanDialog way better usable) --- .../kotlin/net/codinux/banking/ui/Platform.kt | 6 +++++- .../codinux/banking/ui/dialogs/AddAccountDialog.kt | 1 + .../net/codinux/banking/ui/dialogs/BaseDialog.kt | 11 +++++++---- .../net/codinux/banking/ui/dialogs/EnterTanDialog.kt | 1 + .../ui/extensions/DialogPropertiesExtensions.kt | 9 +++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/net/codinux/banking/ui/extensions/DialogPropertiesExtensions.kt diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt index 5bfcf2e..375732c 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/Platform.kt @@ -18,4 +18,8 @@ enum class PlatformType { Android, iOS, Web -} \ No newline at end of file +} + + +val Platform.isMobile: Boolean + get() = type == PlatformType.iOS || type == PlatformType.Android // TODO: for Web check if it's a mobile browser, but very low priority \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt index 8e3c549..5ad9846 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt @@ -41,6 +41,7 @@ fun AddAccountDialog( confirmButtonTitle = "Hinzufügen", confirmButtonEnabled = isRequiredDataEntered && isAddingAccount == false, showProgressIndicatorOnConfirmButton = isAddingAccount, + useMoreThanPlatformDefaultWidthOnMobile = true, onDismiss = onDismiss, onConfirm = { selectedBank?.let { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/BaseDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/BaseDialog.kt index f56b18f..982337e 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/BaseDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/BaseDialog.kt @@ -15,8 +15,10 @@ import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties import net.codinux.banking.ui.composables.text.HeaderText import net.codinux.banking.ui.config.Colors -import net.codinux.banking.ui.config.Style +import net.codinux.banking.ui.extensions.copy import net.codinux.banking.ui.forms.* +import net.codinux.banking.ui.getPlatform +import net.codinux.banking.ui.isMobile @Composable fun BaseDialog( @@ -24,15 +26,16 @@ fun BaseDialog( confirmButtonTitle: String = "OK", confirmButtonEnabled: Boolean = true, showProgressIndicatorOnConfirmButton: Boolean = false, + useMoreThanPlatformDefaultWidthOnMobile: Boolean = false, onDismiss: () -> Unit, onConfirm: (() -> Unit)? = null, properties: DialogProperties = DialogProperties(), content: @Composable () -> Unit ) { + val overwriteDefaultWidth = useMoreThanPlatformDefaultWidthOnMobile && getPlatform().isMobile - - Dialog(onDismissRequest = onDismiss, properties) { - RoundedCornersCard { + Dialog(onDismissRequest = onDismiss, if (overwriteDefaultWidth) properties.copy(usePlatformDefaultWidth = false) else properties) { + RoundedCornersCard(Modifier.let { if (overwriteDefaultWidth) it.fillMaxWidth(0.95f) else it }) { Column(Modifier.background(Color.White).padding(8.dp)) { Row(Modifier.fillMaxWidth()) { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/EnterTanDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/EnterTanDialog.kt index 29a73dc..567a4de 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/EnterTanDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/EnterTanDialog.kt @@ -50,6 +50,7 @@ fun EnterTanDialog(tanChallengeReceived: TanChallengeReceived, onDismiss: () -> BaseDialog( title = "TAN Eingabe", + useMoreThanPlatformDefaultWidthOnMobile = true, confirmButtonEnabled = enteredTan.length > 2, onConfirm = { tanChallengeReceived.callback(EnterTanResult(enteredTan)) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/extensions/DialogPropertiesExtensions.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/extensions/DialogPropertiesExtensions.kt new file mode 100644 index 0000000..9e3add2 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/extensions/DialogPropertiesExtensions.kt @@ -0,0 +1,9 @@ +package net.codinux.banking.ui.extensions + +import androidx.compose.ui.window.DialogProperties + +fun DialogProperties.copy( + dismissOnBackPress: Boolean = this.dismissOnBackPress, + dismissOnClickOutside: Boolean = this.dismissOnClickOutside, + usePlatformDefaultWidth: Boolean = this.usePlatformDefaultWidth +) = DialogProperties(dismissOnBackPress, dismissOnClickOutside, usePlatformDefaultWidth = usePlatformDefaultWidth) \ No newline at end of file