Remove expect/actual dropdown menu

This commit is contained in:
Syer10
2023-12-01 19:36:50 -05:00
parent 0bbfe85aba
commit 519769bc9a
11 changed files with 13 additions and 279 deletions

View File

@@ -1,72 +0,0 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package ca.gosyer.jui.uicore.components
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.window.PopupProperties as AndroidPopupProperties
import androidx.compose.ui.window.SecureFlagPolicy as AndroidSecureFlagPolicy
@Composable
internal actual fun RealDropdownMenu(
expanded: Boolean,
onDismissRequest: () -> Unit,
modifier: Modifier,
offset: DpOffset,
properties: PopupProperties,
content: @Composable ColumnScope.() -> Unit,
) = androidx.compose.material.DropdownMenu(
expanded = expanded,
onDismissRequest = onDismissRequest,
properties = properties.toAndroidProperties(),
modifier = modifier,
offset = offset,
content = content,
)
@Composable
internal actual fun RealDropdownMenuItem(
onClick: () -> Unit,
modifier: Modifier,
enabled: Boolean,
contentPadding: PaddingValues,
interactionSource: MutableInteractionSource,
content: @Composable RowScope.() -> Unit,
) = androidx.compose.material.DropdownMenuItem(
onClick = onClick,
modifier = modifier,
enabled = enabled,
contentPadding = contentPadding,
interactionSource = interactionSource,
content = content,
)
@Stable
fun PopupProperties.toAndroidProperties() =
AndroidPopupProperties(
focusable = focusable,
dismissOnBackPress = dismissOnBackPress,
dismissOnClickOutside = dismissOnClickOutside,
securePolicy = securePolicy.toAndroidSecureFlagPolicy(),
excludeFromSystemGesture = excludeFromSystemGesture,
clippingEnabled = clippingEnabled,
usePlatformDefaultWidth = usePlatformDefaultWidth,
)
@Stable
fun SecureFlagPolicy.toAndroidSecureFlagPolicy() =
when (this) {
SecureFlagPolicy.Inherit -> AndroidSecureFlagPolicy.Inherit
SecureFlagPolicy.SecureOn -> AndroidSecureFlagPolicy.SecureOn
SecureFlagPolicy.SecureOff -> AndroidSecureFlagPolicy.SecureOff
}

View File

@@ -1,99 +0,0 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package ca.gosyer.jui.uicore.components
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.MenuDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
/**
* Policy on setting [WindowManager.LayoutParams.FLAG_SECURE] on a window.
*/
@Stable
enum class SecureFlagPolicy {
/**
* Inherit [WindowManager.LayoutParams.FLAG_SECURE] from the parent window and pass it on the
* window that is using this policy.
*/
Inherit,
/**
* Forces [WindowManager.LayoutParams.FLAG_SECURE] to be set on the window that is using this
* policy.
*/
SecureOn,
/**
* No [WindowManager.LayoutParams.FLAG_SECURE] will be set on the window that is using this
* policy.
*/
SecureOff,
}
@Immutable
data class PopupProperties
@ExperimentalComposeUiApi
constructor(
val focusable: Boolean = false,
val dismissOnBackPress: Boolean = true,
val dismissOnClickOutside: Boolean = true,
val securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit,
val excludeFromSystemGesture: Boolean = true,
val clippingEnabled: Boolean = true,
@property:ExperimentalComposeUiApi
val usePlatformDefaultWidth: Boolean = false,
)
@Composable
internal expect fun RealDropdownMenu(
expanded: Boolean,
onDismissRequest: () -> Unit,
modifier: Modifier,
offset: DpOffset,
properties: PopupProperties,
content: @Composable ColumnScope.() -> Unit,
)
@Composable
fun DropdownMenu(
expanded: Boolean,
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
offset: DpOffset = DpOffset(0.dp, 0.dp),
properties: PopupProperties = PopupProperties(focusable = true),
content: @Composable ColumnScope.() -> Unit,
) = RealDropdownMenu(expanded, onDismissRequest, modifier, offset, properties, content)
@Composable
internal expect fun RealDropdownMenuItem(
onClick: () -> Unit,
modifier: Modifier,
enabled: Boolean,
contentPadding: PaddingValues,
interactionSource: MutableInteractionSource,
content: @Composable RowScope.() -> Unit,
)
@Composable
fun DropdownMenuItem(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
contentPadding: PaddingValues = MenuDefaults.DropdownMenuItemContentPadding,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable RowScope.() -> Unit,
) = RealDropdownMenuItem(onClick, modifier, enabled, contentPadding, interactionSource, content)

View File

@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.size
import androidx.compose.material.DropdownMenu
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue

View File

@@ -14,6 +14,8 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
@@ -29,6 +31,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.util.fastForEachIndexed
@Composable
fun Spinner(
@@ -58,7 +61,7 @@ fun Spinner(
onDismissRequest = { expanded = false },
modifier = Modifier.align(Alignment.CenterEnd),
) {
items.forEachIndexed { index, item ->
items.fastForEachIndexed { index, item ->
DropdownMenuItem(
onClick = {
expanded = false

View File

@@ -1,49 +0,0 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package ca.gosyer.jui.uicore.components
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpOffset
@Composable
internal actual fun RealDropdownMenu(
expanded: Boolean,
onDismissRequest: () -> Unit,
modifier: Modifier,
offset: DpOffset,
properties: PopupProperties,
content: @Composable ColumnScope.() -> Unit,
) = androidx.compose.material.DropdownMenu(
expanded = expanded,
onDismissRequest = onDismissRequest,
focusable = properties.focusable,
modifier = modifier,
offset = offset,
content = content,
)
@Composable
internal actual fun RealDropdownMenuItem(
onClick: () -> Unit,
modifier: Modifier,
enabled: Boolean,
contentPadding: PaddingValues,
interactionSource: MutableInteractionSource,
content: @Composable RowScope.() -> Unit,
) = androidx.compose.material.DropdownMenuItem(
onClick = onClick,
modifier = modifier,
enabled = enabled,
contentPadding = contentPadding,
interactionSource = interactionSource,
content = content,
)

View File

@@ -1,50 +0,0 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package ca.gosyer.jui.uicore.components
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpOffset
@Composable
internal actual fun RealDropdownMenu(
expanded: Boolean,
onDismissRequest: () -> Unit,
modifier: Modifier,
offset: DpOffset,
properties: PopupProperties,
content: @Composable ColumnScope.() -> Unit,
) = Unit/* TODO androidx.compose.material.DropdownMenu(
expanded = expanded,
onDismissRequest = onDismissRequest,
properties = properties,
modifier = modifier,
offset = offset,
content = content
)*/
@Composable
internal actual fun RealDropdownMenuItem(
onClick: () -> Unit,
modifier: Modifier,
enabled: Boolean,
contentPadding: PaddingValues,
interactionSource: MutableInteractionSource,
content: @Composable RowScope.() -> Unit,
) = Unit/* TODO androidx.compose.material.DropdownMenuItem(
onClick = onClick,
modifier = modifier,
enabled = enabled,
contentPadding = contentPadding,
interactionSource = interactionSource,
content = content
)
*/