I need to implement next UI element:
mutableStateOf creates an observable MutableState<T> , which is an observable type integrated with the compose runtime. interface MutableState<T> : State<T> { override var value: T } Any changes to value will schedule recomposition of any composable functions that read value .
A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.
A Scaffold is a layout which implements the basic material design layout structure. You can add things like a TopBar, BottomBar, FAB or a Drawer.
We can make the Column scrollable by using the verticalScroll() modifier.
You can use FlowRow
from accompanist-flowlayout to implement this. It renders its children horizontally (like Row
) but also wraps them by moving to the new line if they don't fit in the existing line. It also allows to configure horizontal and vertical spacing between items.
To nicely handle very long strings (that will not fit into single line themselves) you can set overflow = TextOverflow.Ellipsis
and maxLines = 1
on Text
.
@Composable
fun HashTagList(hashTags: List<String>) {
FlowRow(
modifier = Modifier.padding(8.dp),
mainAxisAlignment = MainAxisAlignment.Center,
mainAxisSize = SizeMode.Expand,
crossAxisSpacing = 12.dp,
mainAxisSpacing = 8.dp
) {
hashTags.forEach { hashTag ->
Text(
text = hashTag,
modifier = Modifier
.background(
color = colorForHashTag(hashTag),
shape = RoundedCornerShape(4.dp)
)
.padding(8.dp),
overflow = TextOverflow.Ellipsis,
maxLines = 1
)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With