From 8949b2def6000c648974cbe6c24753711e84ad87 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Sun, 14 May 2017 22:01:20 +0300 Subject: [PATCH] WIP: Allow differentiating touch scroll from DnD (#9309) * Allow differentiating touch scroll from DnD Provide Escalator API to check if a touch scroll is active, and to specify a delay after which a non-moving touch should not scroll. --- .../com/vaadin/client/widgets/Escalator.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index 903b98e000..543808cb18 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -309,6 +309,8 @@ public class Escalator extends Widget public static final String POINTER_EVENT_TYPE_TOUCH = "touch"; + public static final int SIGNIFICANT_MOVE_THRESHOLD = 3; + /** * A SIGNIFICANT_MOVE_THRESHOLD + * SIGNIFICANT_MOVE_THRESHOLD; + } + // allow handling long press differently, without triggering + // scrolling + if (escalator.getDelayToCancelTouchScroll() >= 0 + && !movedSignificantly + && Duration.currentTimeMillis() + - touchStartTime > escalator + .getDelayToCancelTouchScroll()) { + // cancel touch handling, don't prevent event + touching = false; + animation.cancel(); + acceleration = 1; + return; + } xMov.moveTouch(event); yMov.moveTouch(event); xMov.validate(yMov); @@ -5624,6 +5651,8 @@ public class Escalator extends Widget private HeightMode heightMode = HeightMode.CSS; + private double delayToCancelTouchScroll = -1; + private boolean layoutIsScheduled = false; private ScheduledCommand layoutCommand = new ScheduledCommand() { @Override @@ -6649,6 +6678,49 @@ public class Escalator extends Widget return addHandler(handler, ScrollEvent.TYPE); } + /** + * Returns true if the Escalator is currently scrolling by touch, or has not + * made the decision yet whether to accept touch actions as scrolling or + * not. + * + * @see #setDelayToCancelTouchScroll(double) + * + * @return true when the component is touch scrolling at the moment + * @since 8.1 + */ + public boolean isTouchScrolling() { + return scroller.touchHandlerBundle.touching; + } + + /** + * Returns the time after which to not consider a touch event a scroll event + * if the user has not moved the touch. This can be used to differentiate + * between quick touch move (scrolling) and long tap (e.g. context menu or + * drag and drop operation). + * + * @return delay in milliseconds after which to cancel touch scrolling if + * there is no movement, -1 means scrolling is always allowed + * @since 8.1 + */ + public double getDelayToCancelTouchScroll() { + return delayToCancelTouchScroll; + } + + /** + * Sets the time after which to not consider a touch event a scroll event if + * the user has not moved the touch. This can be used to differentiate + * between quick touch move (scrolling) and long tap (e.g. context menu or + * drag and drop operation). + * + * @param delayToCancelTouchScroll + * delay in milliseconds after which to cancel touch scrolling if + * there is no movement, -1 to always allow scrolling + * @since 8.1 + */ + public void setDelayToCancelTouchScroll(double delayToCancelTouchScroll) { + this.delayToCancelTouchScroll = delayToCancelTouchScroll; + } + @Override public boolean isWorkPending() { return body.domSorter.waiting || verticalScrollbar.isWorkPending() -- 2.39.5