fix multi drop menu open when more than a topic tag clicked in same moment

pull/246/head
Robert 2 years ago
parent a37c06db10
commit c479fd4c20

@ -518,24 +518,30 @@ fun NiaCatalog() {
item { Text("Tags", Modifier.padding(top = 16.dp)) } item { Text("Tags", Modifier.padding(top = 16.dp)) }
item { item {
FlowRow(mainAxisSpacing = 16.dp) { FlowRow(mainAxisSpacing = 16.dp) {
var expandedTopic by remember { mutableStateOf<String?>(null) }
var firstFollowed by remember { mutableStateOf(false) } var firstFollowed by remember { mutableStateOf(false) }
NiaTopicTag( NiaTopicTag(
expanded = expandedTopic == "Topic 1",
followed = firstFollowed, followed = firstFollowed,
onDropMenuToggle = { show -> expandedTopic = if (show) "Topic 1" else null },
onFollowClick = { firstFollowed = true }, onFollowClick = { firstFollowed = true },
onUnfollowClick = { firstFollowed = false }, onUnfollowClick = { firstFollowed = false },
onBrowseClick = {}, onBrowseClick = {},
text = { Text(text = "Topic".uppercase()) }, text = { Text(text = "Topic 1".uppercase()) },
followText = { Text(text = "Follow") }, followText = { Text(text = "Follow") },
unFollowText = { Text(text = "Unfollow") }, unFollowText = { Text(text = "Unfollow") },
browseText = { Text(text = "Browse topic") } browseText = { Text(text = "Browse topic") }
) )
var secondFollowed by remember { mutableStateOf(true) } var secondFollowed by remember { mutableStateOf(true) }
NiaTopicTag( NiaTopicTag(
expanded = expandedTopic == "Topic 2",
followed = secondFollowed, followed = secondFollowed,
onDropMenuToggle = { show -> expandedTopic = if (show) "Topic 2" else null },
onFollowClick = { secondFollowed = true }, onFollowClick = { secondFollowed = true },
onUnfollowClick = { secondFollowed = false }, onUnfollowClick = { secondFollowed = false },
onBrowseClick = {}, onBrowseClick = {},
text = { Text(text = "Topic".uppercase()) }, text = { Text(text = "Topic 2".uppercase()) },
followText = { Text(text = "Follow") }, followText = { Text(text = "Follow") },
unFollowText = { Text(text = "Unfollow") }, unFollowText = { Text(text = "Unfollow") },
browseText = { Text(text = "Browse topic") } browseText = { Text(text = "Browse topic") }

@ -32,7 +32,9 @@ import com.google.samples.apps.nowinandroid.core.designsystem.R
@Composable @Composable
fun NiaTopicTag( fun NiaTopicTag(
expanded : Boolean = false,
followed: Boolean, followed: Boolean,
onDropMenuToggle : (show: Boolean) -> Unit = {},
onFollowClick: () -> Unit, onFollowClick: () -> Unit,
onUnfollowClick: () -> Unit, onUnfollowClick: () -> Unit,
onBrowseClick: () -> Unit, onBrowseClick: () -> Unit,
@ -43,7 +45,7 @@ fun NiaTopicTag(
unFollowText: @Composable () -> Unit = { Text(stringResource(R.string.unfollow)) }, unFollowText: @Composable () -> Unit = { Text(stringResource(R.string.unfollow)) },
browseText: @Composable () -> Unit = { Text(stringResource(R.string.browse_topic)) } browseText: @Composable () -> Unit = { Text(stringResource(R.string.browse_topic)) }
) { ) {
var expanded by remember { mutableStateOf(false) }
Box(modifier = modifier) { Box(modifier = modifier) {
val containerColor = if (followed) { val containerColor = if (followed) {
MaterialTheme.colorScheme.primaryContainer MaterialTheme.colorScheme.primaryContainer
@ -51,7 +53,7 @@ fun NiaTopicTag(
MaterialTheme.colorScheme.surfaceVariant MaterialTheme.colorScheme.surfaceVariant
} }
NiaTextButton( NiaTextButton(
onClick = { expanded = true }, onClick = { onDropMenuToggle(true) },
enabled = enabled, enabled = enabled,
small = true, small = true,
colors = NiaButtonDefaults.textButtonColors( colors = NiaButtonDefaults.textButtonColors(
@ -69,7 +71,7 @@ fun NiaTopicTag(
) )
NiaDropdownMenu( NiaDropdownMenu(
expanded = expanded, expanded = expanded,
onDismissRequest = { expanded = false }, onDismissRequest = { onDropMenuToggle(false) },
items = if (followed) listOf(UNFOLLOW, BROWSE) else listOf(FOLLOW, BROWSE), items = if (followed) listOf(UNFOLLOW, BROWSE) else listOf(FOLLOW, BROWSE),
onItemClick = { item -> onItemClick = { item ->
when (item) { when (item) {

@ -268,13 +268,17 @@ fun NewsResourceTopics(
topics: List<Topic>, topics: List<Topic>,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
var expandedTopic by remember { mutableStateOf<String?>(null) }
Row( Row(
modifier = modifier.horizontalScroll(rememberScrollState()), // causes narrow chips modifier = modifier.horizontalScroll(rememberScrollState()), // causes narrow chips
horizontalArrangement = Arrangement.spacedBy(4.dp), horizontalArrangement = Arrangement.spacedBy(4.dp),
) { ) {
for (topic in topics) { for (topic in topics) {
NiaTopicTag( NiaTopicTag(
expanded = expandedTopic == topic.id,
followed = true, // ToDo: Check if topic is followed followed = true, // ToDo: Check if topic is followed
onDropMenuToggle = { show -> expandedTopic = if (show) topic.id else null },
onFollowClick = { }, // ToDo onFollowClick = { }, // ToDo
onUnfollowClick = { }, // ToDo onUnfollowClick = { }, // ToDo
onBrowseClick = { }, // ToDo onBrowseClick = { }, // ToDo

Loading…
Cancel
Save