When `detectVerticalDragGestures` and `detectHoriz...
# compose
s
When
detectVerticalDragGestures
and
detectHorizontalDragGestures
overlap (i.e. they belong to different composables, but share the same touch source), how I can dispatch events to
detectHorizontalDragGestures
only when the drag is very horizontal? When scrolling with our thumb, vertical swipes tend to be detected as horizontal ones (images in thread)
1
message has been deleted
a
Looks awesome 🙂
s
fraction
is the tangent of the alpha angle. full code: gist
a
Should probably define the magic number a private const at the top of the file 😉
j
in the gist there are a few imports missing
Copy code
import androidx.compose.foundation.gestures.HorizontalPointerDirectionConfig
import androidx.compose.foundation.gestures.PointerDirectionConfig
import androidx.compose.foundation.gestures.pointerSlop
import androidx.compose.ui.util.fastFirstOrNull
is it because of a different compose version? i’m on 1.3.0
s
Did you add
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
? Also, for`fastFirstOrNull` you need
androidx.compose.ui:ui-util
j
I’ve been playing around with this and it looks great, in a sandbox. However I’m not able to apply this on swipe to dismiss within a lazylist. 😕
s
Yeah, it doesn't work when the other component relies on
Modifier.scrollable
, which uses a different logic to handle gestures.
j
as far as I understand, the composable higher up the hierarchy will get the touch events first, which in my case the swipe to dismiss component would be. so if I’d copy everything down to the draggable event, I would probably be able to not consume vertical events with your logic there. if not consumed the scroll listener of the lazylist should get the event
s
I honestly don't know. If you consider this:
Copy code
Box(
  modifier = Modifier
   .pointerInput(Unit) {
     detectHorizontalDragGestures(...)
   }
) {
  Row(
    modifier = Modifier
      .horizontalScrollable(...)
  ) {
    // ...
  }
}
Horizontal scroll are sometimes handled by
Row
, but some other times by
Box
. So yeah, a piece of code is definitely missing... It works fine with
detectVerticalDragGestures
and
detectHorizontalDragGestures
, thought.
However, I do not see weird results when applied to lazycolumn items...
167 Views