Jetpack Compose 1.4 – program!

This version of Jetpack Compose includes new features such as pager and flow layouts, among others. It also improves modifier performance and fixes a number of bugs.

Compose therefore now includes out-of-the-box support for vertical and horizontal paging between different pieces of content. Using VerticalPager or HorizontalPager enables similar functionality as ViewPager in the display system. No more creating adapters or fragments! You can simply embed a composable in the pager:

// show 10 elements
HorizontalPager(pageCount = 10) { Page ->
// Your specific page content as a composable:
Text(
text = “Page: $page”,
edit = Edit.fillMaxWidth()
)
}

FlowRow and FlowColumn, on the other hand, provide a way to arrange items in a container when the size of the items or the container is unknown or dynamic. These containers allow items to be moved to the next row in FlowRow or to the next column in FlowColumn when they run out of storage. These flow layouts also allow for dynamic sizing using weights to distribute items within the container.

Here is an example that implements a list of filters for a real estate application:

@Composable
funFilters() {
val filter = listOf(
“Washer/Dryer”, “Ramp Access”, “Garden”, “Cats OK”, “Dogs OK”, “Smoke Free”
)
FlowLine(
horizontalarray = array.spacedBy(8.dp)
) {
filter.forEach { Title ->
var selected by remember {mutableStateOf(false)}
Val LeadingIcon: @Composable () -> Unit = { Icon(Icons. Default. Check, null) }
FilterChip(
selected,
onClick = { selected = ! selected },
label = { text(title) },
LeadingIcon = if (selected) LeadingIcon otherwise null
)
}
}
}