Lilly
04/21/2022, 8:38 PMjava.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed.
...
val scrollState = rememberScrollState()
Column(
modifier = Modifier
.fillMaxHeight()
.verticalScroll(scrollState)
) {
Card(modifier = Modifier.fillMaxWidth())
Card(modifier = Modifier.fillMaxWidth()) {
LazyVerticalGrid() {}
}
}
The parent is the content slot of BottomSheetScaffold
. I know it has to do with the LazyVerticalGrid
, but both Cards measure the height by its content so I don't understand what the problem is.
EDIT:
Card(modifier = Modifier.fillMaxWidth().weight(1f, false))
Card(modifier = Modifier.fillMaxWidth().weight(1f, false)) {
LazyVerticalGrid() {}
}
Applying weight
on both Cards solves the exception but now the LazyVerticalGrid
is scrollable. I would like to wrap content height of the latter Card
, is this possible?Chris Sinco [G]
04/21/2022, 10:32 PMLilly
04/21/2022, 11:38 PMCard
to use the scroll ability of the parent Column
? Now the Card's height ends at the bottom of the screen (see screenshot) but the intend of the scrollable Column is to avoid this and give the latter Card the height it needs for its content.
val scrollState = rememberScrollState()
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
.border(2.dp, Color.Blue)
.verticalScroll(scrollState)
) {
Card(modifier = Modifier.height(300.dp).fillMaxWidth()) {
Column(modifier = Modifier.fillMaxWidth().background(Color.Red)) {}
}
DashboardCard(onNavigation = { navigation = it })
}
Lilly
04/21/2022, 11:47 PMChris Sinco [G]
04/21/2022, 11:52 PMLilly
04/22/2022, 12:11 AMLazyColumn
did you mean LazyVerticalGrid
?Lilly
04/22/2022, 12:12 AMChris Sinco [G]
04/22/2022, 12:37 AMChris Sinco [G]
04/22/2022, 12:39 AMLilly
04/22/2022, 12:40 AMChris Sinco [G]
04/22/2022, 12:42 AMitem { Card(…) }
, then emit items
with the list of the longer list of things. I’m not entirely sure how well that will work in a bottom sheet though.Chris Sinco [G]
04/22/2022, 12:45 AMChris Sinco [G]
04/22/2022, 12:47 AM@Composable
fun PokemonList(
loading: Boolean = false,
pokemon: List<Pokemon>,
onPokemonSelected: (Pokemon) -> Unit = {}
) {
LazyVerticalGrid(
cells = GridCells.Fixed(2),
verticalArrangement = Arrangement.spacedBy(4.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
contentPadding = PaddingValues(32.dp),
content = {
item({ GridItemSpan(2) }) {
Text(
text = "Pokedex",
style = MaterialTheme.typography.h4,
modifier = Modifier.padding(
top = 64.dp, bottom = 24.dp
)
)
}
if (loading) {
item({ GridItemSpan(2) }) {
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
CircularProgressIndicator(
color = Color.Black,
modifier = Modifier
.size(48.dp)
.padding(vertical = 24.dp)
)
}
}
} else {
items(pokemon) { pokemon ->
PokeDexCard(
pokemon = pokemon,
onPokemonSelected = onPokemonSelected
)
}
}
}
)
}
Chris Sinco [G]
04/22/2022, 12:48 AMLilly
04/22/2022, 12:50 AMLilly
04/25/2022, 2:25 AMitem {
Card() { // Main Card
items {
CardGridItem() {} // GridItems
}
}
}
I can't compose the GridItems into the DashboardCard.
I have a question about the weight
modifier. When I have a parent Column(modifier.fillMaxSize().verticalScroll())
with 2 siblings where one of them has a weight of 1f, the non-weighted sibling will be content wrapped and the weighted sibling will occupy the remaining height, i.e. fill the screen height, correct? And is it also true that the weight will prevent the verticalScroll
form working in any case?