Fix NodeChip click handling (#3278)

This commit is contained in:
Phil Oliver authored and GitHub committed 2025-10-01 20:12:26 +00:00
1 parent 0847598d38
commit 7a899528bf
2 files changed
+40 -64

No files matched your search

@@ -17,19 +17,18 @@
package com.geeksville.mesh.ui.node.components
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.AssistChipDefaults
import androidx.compose.material3.ElevatedAssistChip
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
@@ -44,51 +43,36 @@ import com.geeksville.mesh.TelemetryProtos
import org.meshtastic.core.database.model.Node
@Composable
fun NodeChip(
modifier: Modifier = Modifier,
node: Node,
onClick: (Node) -> Unit = {},
onLongClick: (() -> Unit)? = {},
interactionSource: MutableInteractionSource? = null,
) {
val isIgnored = node.isIgnored
fun NodeChip(modifier: Modifier = Modifier, node: Node, onClick: ((Node) -> Unit)? = null) {
val (textColor, nodeColor) = node.colors
val inputChipInteractionSource = interactionSource ?: remember { MutableInteractionSource() }
Box(modifier = modifier) {
ElevatedAssistChip(
modifier =
Modifier.width(IntrinsicSize.Min).defaultMinSize(minWidth = 72.dp).semantics {
contentDescription = node.user.shortName.ifEmpty { "Node" }
},
elevation = AssistChipDefaults.elevatedAssistChipElevation(),
colors =
AssistChipDefaults.elevatedAssistChipColors(
containerColor = Color(nodeColor),
labelColor = Color(textColor),
),
label = {
Text(
modifier = Modifier.fillMaxWidth(),
text = node.user.shortName.ifEmpty { "???" },
fontSize = MaterialTheme.typography.labelLarge.fontSize,
textDecoration = TextDecoration.LineThrough.takeIf { isIgnored },
textAlign = TextAlign.Center,
maxLines = 1,
)
},
onClick = {},
interactionSource = inputChipInteractionSource,
)
val colors = CardDefaults.cardColors(containerColor = Color(nodeColor), contentColor = Color(textColor))
val content: @Composable () -> Unit = {
Box(
modifier =
Modifier.matchParentSize()
.combinedClickable(
onLongClick = onLongClick,
onClick = { onClick(node) },
interactionSource = inputChipInteractionSource,
indication = null,
),
)
Modifier.width(IntrinsicSize.Min)
.defaultMinSize(minWidth = 72.dp, minHeight = 32.dp)
.padding(horizontal = 8.dp)
.semantics { contentDescription = node.user.shortName.ifEmpty { "Node" } },
contentAlignment = Alignment.Center,
) {
Text(
modifier = Modifier.fillMaxWidth(),
text = node.user.shortName.ifEmpty { "???" },
fontSize = MaterialTheme.typography.labelLarge.fontSize,
textDecoration = TextDecoration.LineThrough.takeIf { node.isIgnored },
textAlign = TextAlign.Center,
maxLines = 1,
)
}
}
if (onClick == null) {
Card(modifier = modifier, shape = MaterialTheme.shapes.small, colors = colors) { content() }
} else {
Card(modifier = modifier, shape = MaterialTheme.shapes.small, colors = colors, onClick = { onClick(node) }) {
content()
}
}
}
@@ -19,7 +19,6 @@ package com.geeksville.mesh.ui.node.components
import android.content.res.Configuration
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.FlowRow
@@ -109,23 +108,13 @@ fun NodeItem(
}
}
val interactionSource = remember { MutableInteractionSource() }
Card(
modifier =
modifier
.combinedClickable(onClick = onClick, onLongClick = onLongClick, interactionSource = interactionSource)
.fillMaxWidth()
.defaultMinSize(minHeight = 80.dp),
colors = cardColors,
) {
Column(modifier = Modifier.fillMaxWidth().padding(8.dp)) {
Card(modifier = modifier.fillMaxWidth().defaultMinSize(minHeight = 80.dp), colors = cardColors) {
Column(
modifier =
Modifier.combinedClickable(onClick = onClick, onLongClick = onLongClick).fillMaxWidth().padding(8.dp),
) {
Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
NodeChip(
node = thatNode,
onClick = { onClick() },
onLongClick = onLongClick,
interactionSource = interactionSource,
)
NodeChip(node = thatNode)
NodeKeyStatusIcon(
hasPKC = thatNode.hasPKC,
@@ -151,6 +140,9 @@ fun NodeItem(
isConnected = isConnected,
)
}
Spacer(modifier = Modifier.height(4.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,