Added option that dialogs on mobile platforms use more than platform's default dialog width (which makes AddAccount- and EnterTanDialog way better usable)

This commit is contained in:
dankito 2024-09-01 17:26:52 +02:00
parent 7ead4297f8
commit 9209347d86
5 changed files with 23 additions and 5 deletions

View File

@ -18,4 +18,8 @@ enum class PlatformType {
Android,
iOS,
Web
}
}
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

View File

@ -41,6 +41,7 @@ fun AddAccountDialog(
confirmButtonTitle = "Hinzufügen",
confirmButtonEnabled = isRequiredDataEntered && isAddingAccount == false,
showProgressIndicatorOnConfirmButton = isAddingAccount,
useMoreThanPlatformDefaultWidthOnMobile = true,
onDismiss = onDismiss,
onConfirm = {
selectedBank?.let {

View File

@ -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()) {

View File

@ -50,6 +50,7 @@ fun EnterTanDialog(tanChallengeReceived: TanChallengeReceived, onDismiss: () ->
BaseDialog(
title = "TAN Eingabe",
useMoreThanPlatformDefaultWidthOnMobile = true,
confirmButtonEnabled = enteredTan.length > 2,
onConfirm = {
tanChallengeReceived.callback(EnterTanResult(enteredTan))

View File

@ -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)