https://kotlinlang.org logo
#compose
Title
# compose
m

Michal Klimczak

03/21/2022, 1:47 PM
I'm trying to use `BasicTextField`'s
decorationBox
and showing / hiding the texfield itself when its focus / value changes. There is an issue that when it hides, there is an exception. I guess we should not completely get rid of the inner text field in this scenario, rather hide it - so a simple
if
and
AnimatedVisibility
will not work here. What I'm looking for is something like the old
View.GONE
. Or just a possibility to go from wrapContent to 0 height and vice versa. Any hints how to best achieve it?
z

Zach Klippenstein (he/him) [MOD]

03/21/2022, 2:21 PM
The compose equivalent to view.GONE is to not place the placeable. You can do this with a layout modifier.
m

Michal Klimczak

03/21/2022, 2:23 PM
makes sense, searching for
layout
usage then, thanks 🙂
this worked nice
Copy code
Box(modifier = Modifier
                .alpha(labelProgress)
                .layout { measurable, constraints ->
                    val placeable = measurable.measure(constraints)
                    layout(placeable.width, (placeable.height * labelProgress).toInt()) {
                        placeable.placeRelative(0, 0, 0f)
                    }

                }
            ) {
                content()
            }
where
Copy code
val labelProgress by transition.animateFloat(
        label = "LabelProgress",
        transitionSpec = { tween(durationMillis = AnimationDuration) }
    ) {
        when (it) {
            UnfocusedEmpty -> 0f
            UnfocusedNotEmpty, Focused -> 1f
        }
    }
thank you @Zach Klippenstein (he/him) [MOD]!
5 Views