Stylianos Gakis
06/18/2024, 2:45 PMStylianos Gakis
06/18/2024, 2:45 PMephemient
06/18/2024, 2:52 PMephemient
06/18/2024, 2:52 PMIf the user will need to have a larger unclipped area for some reason they can always add the needed padding inside the scrollable area.
Stylianos Gakis
06/18/2024, 2:59 PMStylianos Gakis
06/18/2024, 3:02 PMBox {
Box(
Modifier
.align(Alignment.TopCenter)
.matchParentSize()
.requiredHeight(0.dp)
.wrapContentHeight(Alignment.Bottom, true)
.requiredHeight(72.dp)
.border(1.dp, Color.Red),
propagateMinConstraints = true,
) {
AnimationItem()
}
Chip(item)
}
So the Chip at the bottom is the one that takes the real size, and the animation item above is just supposed to start from right above it in the middle, and go up as much as it needs, hence the wrapContentHeight(Alignment.Bottom, true)
but this plan was foiled by this non-optional modifier in there when I made my container be scrollable.
The problem is that I understand why the clip is there on the main axis. But why is there a clip on the cross axis? If someone wants to add taller items than fit in the horizontal list, I do not see how the clip would make them look good anyway. Is it a limitation since they can not add a clip on the main axis without adding some clip on the cross axis too? Since they can't perhaps just add an infinite value thereephemient
06/18/2024, 3:14 PMpadding
doesn't take negative values but you can make your own
Modifier.layout { measurable, constraints ->
val placeable = measurable.measure(constraints.offset(start + end, top + bottom))
val width = constraints.constrainWidth(placeable.width - start - end)
val height = constraints.constrainHeight(placeable.height - top - bottom)
layout(width, height) { placeable.placeRelative(-start, -top) }
}
Stylianos Gakis
06/18/2024, 3:36 PM@Composable
fun SlackTest() {
Box(Modifier.fillMaxSize(), Alignment.Center) {
Row {
Hack(withHack = false)
Hack(withHack = true)
}
}
}
@Composable
fun Hack(withHack: Boolean) {
Column {
Column(
if (withHack) Modifier.paddingAllowingNegatives(bottom = animationLayoutHeight) else Modifier
) {
Text("I am text that might be hidden tbh")
Text("Me too!")
Text("Me three!")
}
val scrollState = rememberScrollState()
Row(
Modifier
.border(1.dp, Color.Black)
.horizontalScroll(scrollState)
) {
for (item in items) {
Column {
if (withHack) {
Spacer(Modifier.height(animationLayoutHeight))
}
Box {
Box(
Modifier
.align(Alignment.TopCenter)
.matchParentSize()
.requiredHeight(0.dp)
.wrapContentHeight(Alignment.Bottom, true)
.requiredHeight(animationLayoutHeight)
.border(1.dp, Color.Red),
propagateMinConstraints = true,
) {
AnimationItem()
}
Chip(item)
}
}
}
}
}
}
@Composable
private fun Chip(item: String, modifier: Modifier = Modifier) {
// Replace with real chip content
Card(modifier, shape = CircleShape) {
Text(item, modifier = Modifier.padding(vertical = 8.dp, horizontal = 24.dp))
}
}
@Composable
fun AnimationItem(modifier: Modifier = Modifier) {
// Here would be the Lottie thing instead
Box(modifier.background(Color.Cyan)) {
Text("AA")
}
}
I get this result [pic] and well, I suppose it works, with the caveat of putting everything in the right spot and very carefully 😄Stylianos Gakis
06/18/2024, 3:44 PM