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

Tolriq

12/03/2021, 8:31 PM
Is there a way to have some kind of zIndex working outside of a single parent or some way to handle priority for clickable when there's overlap ?
g

George Mount

12/03/2021, 8:49 PM
zIndex
only works wthin the parent and there isn't any other way to move a child outside of its parent's
zIndex
. You would have to lift the child out of the parent or lift the entire parent. While I don't think
clickable
offers the ability to handle overlapping views, you can do it with the pointer system. You can do something like this to handle it similar to `onInterceptTouchEvent`:
Copy code
Modifier.pointerInput(onClick) {
  forEachGesture {
    awaitPointerEventScope {
      var down: PointerEvent
      do {
        down = awaitPointerEvent(PointerEventPass.Initial)
      } while (!down.all { it.changedToDown() } )
      down.consumeDownChange()
      do {
        val up = awaitPointerEvent(PointerEventPass.Initial)
      } while (!up.all { it.changedToUp() })
      onClick()
    }
  }
}
You can look at some of the internal functions for some robust handling. For example
awaitFirstDownOnPass
.
You'll definitely want to look at the source for a robust example. That was just off the top of my head and is likely to be missing something. The important part is the
PointerEventPass.Initial
t

Tolriq

12/03/2021, 9:24 PM
So that something I need to use on the "lower" clickable to intercept before the "higher" one ?
g

George Mount

12/03/2021, 9:30 PM
That's the idea. I think it will work.
There could be a problem if they are siblings -- siblings can't intercept each other.
t

Tolriq

12/03/2021, 9:38 PM
Ok thanks, no it's a parent fastscroll bar with a large touch zone that for 1,5 seconds before disapear can overlap a button, trigger an unwanted scroll. I'll try but I think it should be ok.
d

Daniele Segato

12/06/2022, 11:38 PM
George may I ask you to have a look at this? I've a similar need, but I am building a vertical scroll view that reveal hidden header / footer when scrolled. I'm sorry to bother you https://kotlinlang.slack.com/archives/CJLTWPH7S/p1670348015304799?thread_ts=1670348015.304799&cid=CJLTWPH7S
5 Views