Dismiss long press menu after click on a button

This commit is contained in:
Stypox 2025-02-11 17:29:33 +01:00
parent b727834092
commit ee0f98f9ae
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23

View File

@ -128,8 +128,14 @@ fun LongPressMenu(
// the channel icon goes in the menu header, so do not show a button for it
val actions = longPressActions.toMutableList()
val showChannelAction = actions.popFirst { it.type == ShowChannelDetails }
val ctx = LocalContext.current
val onUploaderClick = actions.popFirst { it.type == ShowChannelDetails }
?.let { showChannelDetailsAction ->
{
showChannelDetailsAction.action(ctx)
onDismissRequest()
}
}
Column {
var actionIndex = -1 // -1 indicates the header
@ -157,7 +163,10 @@ fun LongPressMenu(
LongPressMenuButton(
icon = action.type.icon,
text = stringResource(action.type.label),
onClick = { action.action(ctx) },
onClick = {
action.action(ctx)
onDismissRequest()
},
enabled = action.enabled(false),
modifier = Modifier
.height(buttonHeight)
@ -171,7 +180,7 @@ fun LongPressMenu(
// (i.e. on phones in portrait)
LongPressMenuHeader(
item = longPressable,
onUploaderClickAction = showChannelAction?.action,
onUploaderClick = onUploaderClick,
modifier = Modifier
// leave the height as small as possible, since it's the
// only item on the row anyway
@ -186,7 +195,7 @@ fun LongPressMenu(
// right (i.e. on tablets or on phones in landscape)
LongPressMenuHeader(
item = longPressable,
onUploaderClickAction = showChannelAction?.action,
onUploaderClick = onUploaderClick,
modifier = Modifier
.padding(6.dp)
.heightIn(min = 70.dp)
@ -236,7 +245,7 @@ fun LongPressMenuDragHandle(onEditActions: () -> Unit = {}) {
@Composable
fun LongPressMenuHeader(
item: LongPressable,
onUploaderClickAction: ((context: Context) -> Unit)?,
onUploaderClick: (() -> Unit)?,
modifier: Modifier = Modifier,
) {
val ctx = LocalContext.current
@ -346,7 +355,7 @@ fun LongPressMenuHeader(
val subtitle = getSubtitleAnnotatedString(
item = item,
showLink = onUploaderClickAction != null,
showLink = onUploaderClick != null,
linkColor = MaterialTheme.customColors.onSurfaceVariantLink,
ctx = ctx,
)
@ -356,11 +365,13 @@ fun LongPressMenuHeader(
Text(
text = subtitle,
style = MaterialTheme.typography.bodyMedium,
modifier = if (onUploaderClickAction == null) {
modifier = if (onUploaderClick == null) {
Modifier
} else {
Modifier.clickable { onUploaderClickAction(ctx) }
}.basicMarquee(iterations = Int.MAX_VALUE)
Modifier.clickable(onClick = onUploaderClick)
}
.fillMaxWidth()
.basicMarquee(iterations = Int.MAX_VALUE)
)
}
}