Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to disable insets in Popup/Dialog #833

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ import androidx.compose.ui.unit.round
* @property dismissOnClickOutside Whether the popup can be dismissed by clicking outside the
* popup's bounds. If true, clicking outside the popup will call onDismissRequest.
* @property clippingEnabled Whether to allow the popup window to extend beyond the bounds of the
* screen. By default the window is clipped to the screen boundaries. Setting this to false will
* screen. By default, the window is clipped to the screen boundaries. Setting this to false will
* allow windows to be accurately positioned.
* The default value is true.
* @property usePlatformDefaultWidth Whether the width of the dialog's content should be limited to
* @property usePlatformDefaultWidth Whether the width of the popup'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.
*/
@Immutable
actual class PopupProperties @ExperimentalComposeUiApi constructor(
Expand All @@ -71,6 +73,7 @@ actual class PopupProperties @ExperimentalComposeUiApi constructor(
actual val dismissOnClickOutside: Boolean = true,
actual val clippingEnabled: Boolean = true,
val usePlatformDefaultWidth: Boolean = false,
val usePlatformInsets: Boolean = true,
) {
// Constructor with all non-experimental arguments.
constructor(
Expand All @@ -84,6 +87,7 @@ actual class PopupProperties @ExperimentalComposeUiApi constructor(
dismissOnClickOutside = dismissOnClickOutside,
clippingEnabled = clippingEnabled,
usePlatformDefaultWidth = false,
usePlatformInsets = true,
)

actual constructor(
Expand All @@ -107,6 +111,7 @@ actual class PopupProperties @ExperimentalComposeUiApi constructor(
dismissOnClickOutside = dismissOnClickOutside,
clippingEnabled = clippingEnabled,
usePlatformDefaultWidth = false,
usePlatformInsets = true,
)

override fun equals(other: Any?): Boolean {
Expand All @@ -118,6 +123,7 @@ actual class PopupProperties @ExperimentalComposeUiApi constructor(
if (dismissOnClickOutside != other.dismissOnClickOutside) return false
if (clippingEnabled != other.clippingEnabled) return false
if (usePlatformDefaultWidth != other.usePlatformDefaultWidth) return false
if (usePlatformInsets != other.usePlatformInsets) return false

return true
}
Expand All @@ -128,6 +134,7 @@ actual class PopupProperties @ExperimentalComposeUiApi constructor(
result = 31 * result + dismissOnClickOutside.hashCode()
result = 31 * result + clippingEnabled.hashCode()
result = 31 * result + usePlatformDefaultWidth.hashCode()
result = 31 * result + usePlatformInsets.hashCode()
return result
}
}
Expand Down Expand Up @@ -421,7 +428,11 @@ private fun PopupLayout(
onOutsidePointerEvent: ((PointerInputEvent) -> Unit)? = null,
content: @Composable () -> Unit
) {
val platformInsets = platformInsets()
val platformInsets = if (properties.usePlatformInsets) {
platformInsets()
} else {
PlatformInsets.Zero
}
var layoutParentBoundsInWindow: IntRect? by remember { mutableStateOf(null) }
EmptyLayout(Modifier.parentBoundsInWindow { layoutParentBoundsInWindow = it })
RootLayout(
Expand Down