Improved alert dialog so that three buttons are arranged vertically
This commit is contained in:
@@ -245,7 +245,6 @@ object CustomElements {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun AlertDialog(
|
fun AlertDialog(
|
||||||
@@ -289,7 +288,56 @@ object CustomElements {
|
|||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
// New logic starts here
|
||||||
if (positiveButtonText.isNotEmpty()) {
|
if (positiveButtonText.isNotEmpty()) {
|
||||||
|
val buttonCount = listOf(positiveButtonText, negativeButtonText, neutralButtonText)
|
||||||
|
.count { it.isNotEmpty() }
|
||||||
|
|
||||||
|
if (buttonCount >= 3) {
|
||||||
|
// Use a Column for 3 buttons, aligned to the end (right)
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalAlignment = Alignment.End
|
||||||
|
) {
|
||||||
|
// The positive button is usually last for emphasis
|
||||||
|
if (negativeButtonText.isNotEmpty()) {
|
||||||
|
TextButton(onClick = {
|
||||||
|
onNegativeClicked()
|
||||||
|
showDialog.value = false
|
||||||
|
}) {
|
||||||
|
Text(
|
||||||
|
text = negativeButtonText.uppercase(),
|
||||||
|
fontSize = 14.sp,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (neutralButtonText.isNotEmpty()) {
|
||||||
|
TextButton(onClick = {
|
||||||
|
onNeutralClicked()
|
||||||
|
showDialog.value = false
|
||||||
|
}) {
|
||||||
|
Text(
|
||||||
|
text = neutralButtonText.uppercase(),
|
||||||
|
fontSize = 14.sp,
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TextButton(onClick = {
|
||||||
|
onPositiveClicked()
|
||||||
|
showDialog.value = false
|
||||||
|
}) {
|
||||||
|
Text(
|
||||||
|
text = positiveButtonText.uppercase(),
|
||||||
|
fontSize = 14.sp,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Use the existing Row for 1 or 2 buttons
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.End
|
horizontalArrangement = Arrangement.End
|
||||||
@@ -333,6 +381,7 @@ object CustomElements {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user