Is there a way to add a touch listener to a compos...
# compose
c
Is there a way to add a touch listener to a composable, which is called even if the touch started outside of the composable? i.e. when I press down on a star in a rating bar, and drag my finger to another star, I want to register a touch event in that other star to update the rating.
I read through the gestures documentation and didn't see anything for this use case, but I could be missing something. Seems like an important thing to support, given the old view system does. I suppose I could use a drag listener on the parent and do math based on its width and the width of each star to figure out which star the touch is currently on, but that seems far from an ideal approach.
a
views don't support resuming a gesture already in progress where the ACTION_DOWN happened outside of the view bounds either. The way to approach this is to treat the whole bar as the target, not individual stars.
c
Hmm, I though I achieved the same thing before with
View#setOnTouchListener
, but I could be mistaken. If the whole bar needs to be the target, then I guess the drag listener approach I mentioned is the best way?
a
Drag will do the trick, yes. There's no View
ACTION_
code for resuming a gesture already in progress; all view touch handling code assumes that a valid event stream must start with `ACTION_DOWN`; you can't start receiving
ACTION_MOVE
for a view that a touch didn't begin in
c
Got it, thanks for the help