Skip to content

Commit

Permalink
Attemps to fix conflict between Pinch and Drag&Drop (#3758)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasH99 committed Nov 1, 2023
1 parent 3f6ba7c commit d3f5b30
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions CodenameOne/src/com/codename1/ui/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -4662,11 +4662,42 @@ private double distance(int[] x, int[] y) {
protected void pinchReleased(int x, int y) {

}


/**
* Invoked by subclasses interested in handling pinch to do their own actions based on the position of the two fingers, if true is returned
* other drag events will not be broadcast
*
* @param x the pointer x coordinate
* @param y the pointer y coordinate
* @return false by default, true if pinch is handled
*/
protected boolean pinch(int[] x, int[] y) {
return false;
}

private boolean pinchBlocksDragAndDrop;

/**
* If a component supports pinch as well as drag and drop the two may conflict (if one finger is placed a bit before the other, the drag
* timer will be initiated and may trigger drag even if the second finger has been placed before).
* Setting setPinchBlocksDragAndDrop to true will prevent drag from triggering.
* @param block if true will prevent drag and drop to trigger if two fingers are placed to pinch before the drag is initiated
*/
public void setPinchBlocksDragAndDrop(boolean block) {
pinchBlocksDragAndDrop = block;
}

/**
* returns true if pinch will block drag and drop
*/
public boolean isPinchBlocksDragAndDrop() {
return pinchBlocksDragAndDrop;
}

/**
* If this Component is focused, the pointer dragged event
* will call this method
*
*
* @param x the pointer x coordinate
* @param y the pointer y coordinate
*/
Expand All @@ -4679,8 +4710,11 @@ public void pointerDragged(int[] x, int[] y) {
pinchDistance = currentDis;
}
double scale = currentDis / pinchDistance;
if (pinch((float)scale)) {
boolean pinchXY = pinch(x, y); // ensure that both pinch(scale) and pinch(x,y) are called
if (pinch((float) scale) || pinchXY) {
inPinch = true;
if (pinchBlocksDragAndDrop)
dragActivated = false;
return;
}
} else {
Expand Down

0 comments on commit d3f5b30

Please sign in to comment.