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

Alexander Maryanovsky

03/11/2023, 9:48 PM
Is there a way to emit an element that is ignored for the purposes of layout?
e

ephemient

03/11/2023, 9:53 PM
Copy code
Modifier.size(0.dp).wrapContentSize(unbounded = true)
(untested, but I think something like that may work)
a

Alexander Maryanovsky

03/11/2023, 9:56 PM
Unfortunately that’s not ignored. It’s just 0x0
If you add it to a
Column(verticalArrangement = Arrangement.spacedBy(100.dp)
you will definitely see its effect.
It probably doesn’t exist, but I was hoping maybe there’s some modifier you can tag the element with.
i

Ian Lake

03/12/2023, 12:56 AM
a

Alexander Maryanovsky

03/12/2023, 7:31 AM
Funny you should mention
Popup
. The reason for this question is me trying to address this issue: https://github.com/JetBrains/compose-multiplatform/issues/2729 But looking at the Android code, it seems to suffer from the same problem, because
AndroidPopup
emits the same empty layout whose purpose is to get the parent’s position: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]android.kt;drc=82abb7ed0792545abb32c5a3ae7a12051aed1556;l=309
Confirmed that Android has the same bug.
e

ephemient

03/12/2023, 10:20 PM
hmm. popup position is based on position in the layout, and I don't see a way to get that without being laid out, which will have that spacing effect in row/column
a

Alexander Maryanovsky

03/13/2023, 10:45 AM
Need something like
LocalCoordinates
e

ephemient

03/13/2023, 5:21 PM
how would that work?
Copy code
Layout(content = {
    Foo()
    LocalCoordinates
    Bar()
}, measurePolicy = { measureables, constraints ->
    // custom code
I don't think you can observe the coordinates it would be laid out at, without potentially affecting layout
a

Alexander Maryanovsky

03/13/2023, 5:27 PM
It could work like onGloballyPoisitioned, but without the actual node
Maybe like ‘LocalCoordsProvider.current.onLocalCoordinates{ }`
m

myanmarking

03/13/2023, 10:43 PM
Why cant you create a composable wrapper with an of else and your ignore condition there?
6 Views