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

dimsuz

01/14/2021, 5:36 PM
is there a way to remember a layout height in compose? Use-case: • I have some Box positioned in the screen (it's inside the Column) • User hits some button, some job begins • Now I want to hide the box and show a CircularIndicator positioned at that (now invisible) Box's center In code I do something like
if (isJobRunning) Box() else CircularIndicator()
but that makes progress bar jump. In old View system I would wrap them both in FrameLayout and have the indicator use
layout_gravity=center
while setting
box.visibility = INVISIBLE
. What path should I take in Compose?
v

Vsevolod Ganin

01/14/2021, 6:02 PM
You can do the same, wrapping this code with another
Box
. Box is analogue for
FrameLayout
For
layout_gravity=center
use
Modifier.align
for both children
d

dimsuz

01/14/2021, 8:20 PM
But the thing is that only one child can be visible at one moment. And I want that
Box
to always retain size of the largest child, even if it's not currently in composition. With
FrameLayout
this is solved by having
Invisible
state which retains view size during a layout phase. Not so here...
v

Vsevolod Ganin

01/14/2021, 8:26 PM
Ah, now I get it. AFAIK
INVISIBLE
is
Modifier.opacity(0f)
now
d

dimsuz

01/14/2021, 8:28 PM
I thought about this, but it felt a bit like a hack, so I thought I'd ask if there's a more idiomatic way 🙂
v

Vsevolod Ganin

01/14/2021, 8:32 PM
Yeah it seems strange for me too. Personally I never had to emulate
INVISIBLE
. There was a discussion sometime ago and it seems that community agreed on that is
INVISIBLE
is now
opacity(0f)
. https://kotlinlang.slack.com/archives/CJLTWPH7S/p1594659399205900
There is more interesting solution at the end of the thread, probably you should try it
d

dimsuz

01/15/2021, 12:12 PM
Thank you! 👍
4 Views