Change functionality of NiaTopicTag to navigate to topic when tapped

caren/tag_navigate_to_browse
Caren Chang 2 years ago committed by Caren
parent f68a112cfe
commit 46572d37fa

@ -28,18 +28,11 @@ 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 = {}, onClick: () -> Unit,
onFollowClick: () -> Unit,
onUnfollowClick: () -> Unit,
onBrowseClick: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
enabled: Boolean = true, enabled: Boolean = true,
text: @Composable () -> Unit, text: @Composable () -> Unit,
followText: @Composable () -> Unit = { Text(stringResource(R.string.follow)) },
unFollowText: @Composable () -> Unit = { Text(stringResource(R.string.unfollow)) },
browseText: @Composable () -> Unit = { Text(stringResource(R.string.browse_topic)) }
) { ) {
Box(modifier = modifier) { Box(modifier = modifier) {
@ -49,7 +42,7 @@ fun NiaTopicTag(
MaterialTheme.colorScheme.surfaceVariant MaterialTheme.colorScheme.surfaceVariant
} }
NiaTextButton( NiaTextButton(
onClick = { onDropMenuToggle(true) }, onClick = onClick,
enabled = enabled, enabled = enabled,
small = true, small = true,
colors = NiaButtonDefaults.textButtonColors( colors = NiaButtonDefaults.textButtonColors(
@ -65,25 +58,6 @@ fun NiaTopicTag(
), ),
text = text text = text
) )
NiaDropdownMenu(
expanded = expanded,
onDismissRequest = { onDropMenuToggle(false) },
items = if (followed) listOf(UNFOLLOW, BROWSE) else listOf(FOLLOW, BROWSE),
onItemClick = { item ->
when (item) {
FOLLOW -> onFollowClick()
UNFOLLOW -> onUnfollowClick()
BROWSE -> onBrowseClick()
}
},
itemText = { item ->
when (item) {
FOLLOW -> followText()
UNFOLLOW -> unFollowText()
BROWSE -> browseText()
}
}
)
} }
} }

@ -279,14 +279,10 @@ fun NewsResourceTopics(
) { ) {
for (topic in topics) { for (topic in topics) {
NiaTopicTag( NiaTopicTag(
expanded = expandedTopicId == topic.id,
followed = true, // ToDo: Check if topic is followed followed = true, // ToDo: Check if topic is followed
onDropMenuToggle = { show -> onClick = {
expandedTopicId = if (show) topic.id else null // Navigate to browse topic
}, },
onFollowClick = { }, // ToDo
onUnfollowClick = { }, // ToDo
onBrowseClick = { }, // ToDo
text = { Text(text = topic.name.uppercase(Locale.getDefault())) } text = { Text(text = topic.name.uppercase(Locale.getDefault())) }
) )
} }

Loading…
Cancel
Save