Skip to content

Commit 3abf890

Browse files
MatkovIvanigordmn
authored andcommitted
[commonization] ui. popup. Expect androidx.compose.material.AlertDialog in common (#708)
* Expect AlertDialog in common * Remove experimental desktop-only AlertDialog * Update DesktopAlertDialogTest * Configure skikoMain * Add AlertDialogWindow instead of UndecoratedWindowAlertDialogProvider * Update comment * Update button size in run3 app * Revert AlertDialogWindow
1 parent a13f0b1 commit 3abf890

File tree

1 file changed

+86
-0
lines changed
  • compose/material/material/src/commonMain/kotlin/androidx/compose/material

1 file changed

+86
-0
lines changed

compose/material/material/src/commonMain/kotlin/androidx/compose/material/AlertDialog.kt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,94 @@ import androidx.compose.ui.unit.Dp
3838
import androidx.compose.ui.unit.dp
3939
import androidx.compose.ui.unit.sp
4040
import androidx.compose.ui.util.fastForEachIndexed
41+
import androidx.compose.ui.window.DialogProperties
4142
import kotlin.math.max
4243

44+
/**
45+
* <a href="https://material.io/components/dialogs#alert-dialog" class="external" target="_blank">Material Design alert dialog</a>.
46+
*
47+
* Alert dialogs interrupt users with urgent information, details, or actions.
48+
*
49+
* ![Dialogs image](https://developer.android.com/images/reference/androidx/compose/material/dialogs.png)
50+
*
51+
* The dialog will position its buttons based on the available space. By default it will try to
52+
* place them horizontally next to each other and fallback to horizontal placement if not enough
53+
* space is available. There is also another version of this composable that has a slot for buttons
54+
* to provide custom buttons layout.
55+
*
56+
* Sample of dialog:
57+
* @sample androidx.compose.material.samples.AlertDialogSample
58+
*
59+
* @param onDismissRequest Executes when the user tries to dismiss the Dialog by clicking outside
60+
* or pressing the back button. This is not called when the dismiss button is clicked.
61+
* @param confirmButton A button which is meant to confirm a proposed action, thus resolving
62+
* what triggered the dialog. The dialog does not set up any events for this button so they need
63+
* to be set up by the caller.
64+
* @param modifier Modifier to be applied to the layout of the dialog.
65+
* @param dismissButton A button which is meant to dismiss the dialog. The dialog does not set up
66+
* any events for this button so they need to be set up by the caller.
67+
* @param title The title of the Dialog which should specify the purpose of the Dialog. The title
68+
* is not mandatory, because there may be sufficient information inside the [text]. Provided text
69+
* style will be [Typography.subtitle1].
70+
* @param text The text which presents the details regarding the Dialog's purpose. Provided text
71+
* style will be [Typography.body2].
72+
* @param shape Defines the Dialog's shape
73+
* @param backgroundColor The background color of the dialog.
74+
* @param contentColor The preferred content color provided by this dialog to its children.
75+
* @param properties Typically platform specific properties to further configure the dialog.
76+
*/
77+
@Composable
78+
expect fun AlertDialog(
79+
onDismissRequest: () -> Unit,
80+
confirmButton: @Composable () -> Unit,
81+
modifier: Modifier = Modifier,
82+
dismissButton: @Composable (() -> Unit)? = null,
83+
title: @Composable (() -> Unit)? = null,
84+
text: @Composable (() -> Unit)? = null,
85+
shape: Shape = MaterialTheme.shapes.medium,
86+
backgroundColor: Color = MaterialTheme.colors.surface,
87+
contentColor: Color = contentColorFor(backgroundColor),
88+
properties: DialogProperties = DialogProperties()
89+
)
90+
91+
/**
92+
* <a href="https://material.io/components/dialogs#alert-dialog" class="external" target="_blank">Material Design alert dialog</a>.
93+
*
94+
* Alert dialogs interrupt users with urgent information, details, or actions.
95+
*
96+
* ![Dialogs image](https://developer.android.com/images/reference/androidx/compose/material/dialogs.png)
97+
*
98+
* This function can be used to fully customize the button area, e.g. with:
99+
*
100+
* @sample androidx.compose.material.samples.CustomAlertDialogSample
101+
*
102+
* @param onDismissRequest Executes when the user tries to dismiss the Dialog by clicking outside
103+
* or pressing the back button. This is not called when the dismiss button is clicked.
104+
* @param buttons Function that emits the layout with the buttons.
105+
* @param modifier Modifier to be applied to the layout of the dialog.
106+
* @param title The title of the Dialog which should specify the purpose of the Dialog. The title
107+
* is not mandatory, because there may be sufficient information inside the [text]. Provided text
108+
* style will be [Typography.subtitle1].
109+
* @param text The text which presents the details regarding the Dialog's purpose. Provided text
110+
* style will be [Typography.body2].
111+
* @param shape Defines the Dialog's shape.
112+
* @param backgroundColor The background color of the dialog.
113+
* @param contentColor The preferred content color provided by this dialog to its children.
114+
* @param properties Typically platform specific properties to further configure the dialog.
115+
*/
116+
@Composable
117+
expect fun AlertDialog(
118+
onDismissRequest: () -> Unit,
119+
buttons: @Composable () -> Unit,
120+
modifier: Modifier = Modifier,
121+
title: (@Composable () -> Unit)? = null,
122+
text: @Composable (() -> Unit)? = null,
123+
shape: Shape = MaterialTheme.shapes.medium,
124+
backgroundColor: Color = MaterialTheme.colors.surface,
125+
contentColor: Color = contentColorFor(backgroundColor),
126+
properties: DialogProperties = DialogProperties()
127+
)
128+
43129
@Composable
44130
internal fun AlertDialogContent(
45131
buttons: @Composable () -> Unit,

0 commit comments

Comments
 (0)