Skip to content

Commit

Permalink
Add DialogProperties.usePlatformInsets flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MatkovIvan committed Sep 21, 2023
1 parent 01c668d commit 8198e9f
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ private val DefaultScrimColor = Color.Black.copy(alpha = DefaultScrimOpacity)
* dialog's bounds. If true, clicking outside the dialog will call onDismissRequest.
* @property usePlatformDefaultWidth Whether the width of the dialog's content should be limited to
* the platform default, which is smaller than the screen width.
* @property usePlatformInsets Whether the width of the popup's content should be limited by
* platform insets.
* @property scrimColor Color of background fill.
*/
@Immutable
actual class DialogProperties @ExperimentalComposeUiApi constructor(
actual val dismissOnBackPress: Boolean = true,
actual val dismissOnClickOutside: Boolean = true,
actual val usePlatformDefaultWidth: Boolean = true,
val usePlatformInsets: Boolean = true,
val scrimColor: Color = DefaultScrimColor,
) {
// Constructor with all non-experimental arguments.
Expand All @@ -76,7 +79,8 @@ actual class DialogProperties @ExperimentalComposeUiApi constructor(
dismissOnBackPress = dismissOnBackPress,
dismissOnClickOutside = dismissOnClickOutside,
usePlatformDefaultWidth = usePlatformDefaultWidth,
scrimColor = DefaultScrimColor
usePlatformInsets = true,
scrimColor = DefaultScrimColor,
)

actual constructor(
Expand All @@ -97,7 +101,8 @@ actual class DialogProperties @ExperimentalComposeUiApi constructor(
dismissOnBackPress = dismissOnBackPress,
dismissOnClickOutside = dismissOnClickOutside,
usePlatformDefaultWidth = usePlatformDefaultWidth,
scrimColor = DefaultScrimColor
usePlatformInsets = true,
scrimColor = DefaultScrimColor,
)

override fun equals(other: Any?): Boolean {
Expand All @@ -107,6 +112,7 @@ actual class DialogProperties @ExperimentalComposeUiApi constructor(
if (dismissOnBackPress != other.dismissOnBackPress) return false
if (dismissOnClickOutside != other.dismissOnClickOutside) return false
if (usePlatformDefaultWidth != other.usePlatformDefaultWidth) return false
if (usePlatformInsets != other.usePlatformInsets) return false
if (scrimColor != other.scrimColor) return false

return true
Expand All @@ -116,6 +122,7 @@ actual class DialogProperties @ExperimentalComposeUiApi constructor(
var result = dismissOnBackPress.hashCode()
result = 31 * result + dismissOnClickOutside.hashCode()
result = 31 * result + usePlatformDefaultWidth.hashCode()
result = 31 * result + usePlatformInsets.hashCode()
result = 31 * result + scrimColor.hashCode()
return result
}
Expand Down Expand Up @@ -170,7 +177,11 @@ private fun DialogLayout(
onOutsidePointerEvent: ((PointerInputEvent) -> Unit)? = null,
content: @Composable () -> Unit
) {
val platformInsets = platformInsets()
val platformInsets = if (properties.usePlatformInsets) {
platformInsets()
} else {
PlatformInsets.Zero
}
RootLayout(
modifier = modifier,
focusable = true,
Expand Down

0 comments on commit 8198e9f

Please sign in to comment.