Skip to content

Commit

Permalink
[commonization] ui. popup. Expect `androidx.compose.material3.AlertDi…
Browse files Browse the repository at this point in the history
…alog` in common (#710)

* Expect AlertDialog in common

* Revert Android formatting

* Add comment about binary compatibility
  • Loading branch information
MatkovIvan authored and igordmn committed Nov 14, 2023
1 parent 2bec7a5 commit 7b04ee9
Showing 1 changed file with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,126 @@ import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.Placeable
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import kotlin.math.max


/**
* <a href="https://m3.material.io/components/dialogs/overview" class="external" target="_blank">Material Design basic dialog</a>.
*
* Dialogs provide important prompts in a user flow. They can require an action, communicate
* information, or help users accomplish a task.
*
* ![Basic dialog image](https://developer.android.com/images/reference/androidx/compose/material3/basic-dialog.png)
*
* The dialog will position its buttons, typically [TextButton]s, based on the available space.
* By default it will try to place them horizontally next to each other and fallback to horizontal
* placement if not enough space is available.
*
* Simple usage:
* @sample androidx.compose.material3.samples.AlertDialogSample
*
* Usage with a "Hero" icon:
* @sample androidx.compose.material3.samples.AlertDialogWithIconSample
*
* @param onDismissRequest called when the user tries to dismiss the Dialog by clicking outside
* or pressing the back button. This is not called when the dismiss button is clicked.
* @param confirmButton button which is meant to confirm a proposed action, thus resolving what
* triggered the dialog. The dialog does not set up any events for this button so they need to be
* set up by the caller.
* @param modifier the [Modifier] to be applied to this dialog
* @param dismissButton button which is meant to dismiss the dialog. The dialog does not set up any
* events for this button so they need to be set up by the caller.
* @param icon optional icon that will appear above the [title] or above the [text], in case a
* title was not provided.
* @param title title which should specify the purpose of the dialog. The title is not mandatory,
* because there may be sufficient information inside the [text].
* @param text text which presents the details regarding the dialog's purpose.
* @param shape defines the shape of this dialog's container
* @param containerColor the color used for the background of this dialog. Use [Color.Transparent]
* to have no color.
* @param iconContentColor the content color used for the icon.
* @param titleContentColor the content color used for the title.
* @param textContentColor the content color used for the text.
* @param tonalElevation when [containerColor] is [ColorScheme.surface], a translucent primary color
* overlay is applied on top of the container. A higher tonal elevation value will result in a
* darker color in light theme and lighter color in dark theme. See also: [Surface].
* @param properties typically platform specific properties to further configure the dialog.
*/
@Composable
expect fun AlertDialog(
onDismissRequest: () -> Unit,
confirmButton: @Composable () -> Unit,
modifier: Modifier = Modifier,
dismissButton: @Composable (() -> Unit)? = null,
icon: @Composable (() -> Unit)? = null,
title: @Composable (() -> Unit)? = null,
text: @Composable (() -> Unit)? = null,
shape: Shape = AlertDialogDefaults.shape,
containerColor: Color = AlertDialogDefaults.containerColor,
iconContentColor: Color = AlertDialogDefaults.iconContentColor,
titleContentColor: Color = AlertDialogDefaults.titleContentColor,
textContentColor: Color = AlertDialogDefaults.textContentColor,
tonalElevation: Dp = AlertDialogDefaults.TonalElevation,
properties: DialogProperties = DialogProperties()
)

/**
* <a href="https://m3.material.io/components/dialogs/overview" class="external" target="_blank">Basic alert dialog dialog</a>.
*
* Dialogs provide important prompts in a user flow. They can require an action, communicate
* information, or help users accomplish a task.
*
* ![Basic dialog image](https://developer.android.com/images/reference/androidx/compose/material3/basic-dialog.png)
*
* This basic alert dialog expects an arbitrary content that is defined by the caller. Note that
* your content will need to define its own styling.
*
* By default, the displayed dialog has the minimum height and width that the Material Design spec
* defines. If required, these constraints can be overwritten by providing a `width` or `height`
* [Modifier]s.
*
* @sample androidx.compose.material3.samples.AlertDialogWithCustomContentSample
*
* @param onDismissRequest called when the user tries to dismiss the Dialog by clicking outside
* or pressing the back button. This is not called when the dismiss button is clicked.
* @param modifier the [Modifier] to be applied to this dialog's content.
* @param properties typically platform specific properties to further configure the dialog.
* @param content the content of the dialog
*/
@ExperimentalMaterial3Api
@Composable
expect fun AlertDialog(
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
properties: DialogProperties = DialogProperties(),
content: @Composable () -> Unit
)


/**
* Contains default values used for [AlertDialog]
*/
expect object AlertDialogDefaults {
/** The default shape for alert dialogs */
val shape: Shape

/** The default container color for alert dialogs */
val containerColor: Color

/** The default icon color for alert dialogs */
val iconContentColor: Color

/** The default title color for alert dialogs */
val titleContentColor: Color

/** The default text color for alert dialogs */
val textContentColor: Color

/** The default tonal elevation for alert dialogs */
val TonalElevation: Dp
}

@Composable
internal fun AlertDialogContent(
buttons: @Composable () -> Unit,
Expand Down

0 comments on commit 7b04ee9

Please sign in to comment.