I have been messing around with composing gestures, but I can't achieve what I'm after.
So more general question first - is there a way to build custom gestures from touches? I assume the answer here is no and composition is the only way.
I have a couple of specific problems I'm trying to sort.
This is in an app for planning skydives. The user can drag skydivers or groups of skydivers around the canvas and rotate them as necessary. They should behave like cards on a table.
I'm implementing this with a FormationView that holds a bunch of SkydiverViews
- combining drag and rotation
I'm able to do this with a
DragGesture(minimumDistance: 3) .simultaneously(with: RotationGesture()) .updating ...
this mostly works, but they're strictly consecutive rather than simultaneous, so I can get
-> drag -> rotate
but I can't get
-> drag -> rotate -> drag
(I'd expect to get this case if I drag with one finger, use a second to rotate, then lift up the second finger and continue dragging with the first)
Is there a way to say
Keep going with the drag when the rotation ends and you're back to one finger
I have implemented the drag/rotate at the FormationView level as I want to be able to drag single or multiple selected jumpers around without having to start the drag on the actual jumper
However - this gives me a different problem. I also want to select the jumpers on touchDown
I can get things working on touchUp with TapGesture, or onTapGesture (which presumably just creates a TapGesture, but I can't add a gesture to the skydiverView that recognises a touchDown and doesn't break dragging at the formation level.
I have tried using LongPressGesture(minimumDuration:0) of DragGesture.updating with logic to detect the first result.
The problem is that unlike the TapGesture, both of these disable the DragRotate gesture higher up in the hierarchy.
Is there a way to say
' don't let an ended gesture in the subview make any difference to the gesture in the superview '
My next thought is to leave the top view with the dragRotate gesture, but also give each subview it's own dragRotate gesture which interacts with the @GestureState belonging to the topView - but which also detects the start of the dragUpdate to serve as a touchDown.
I think this will probably work - but it seems crazy complex and bizarrely spaghetti-like
Is there a different way I should be going about this?