From 07a3c3c07ccff25c8afeb623b9fd3ffee6d02361 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 16 Sep 2015 00:50:50 +0200 Subject: Grid: allow zooming in touch devices. - Since grid was not cancelling scrolling when multiple touches, zooming was not working, this patch fixes "zoom trap". - Prevent default when moving the scroll in touch devices to avoid parent scrolling Change-Id: I47856ef20bc835bb2b310b45f6d2749e950e8e7a --- .../src/com/vaadin/client/widgets/Escalator.java | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index 43eeb7a0ce..881ac7d7ed 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -426,12 +426,8 @@ public class Escalator extends Widget implements RequiresResize, position = scroll.getScrollPos(); // Compute offset, and adjust it with an easing curve so as movement is smoother. offset = F_VEL * velocity * acceleration * easingInOutCos(velocity, MAX_VEL); - // Check that offset does not over-scroll - double minOff = -scroll.getScrollPos(); - double maxOff = scroll.getScrollSize() - scroll.getOffsetSize() + minOff; - offset = Math.min(Math.max(offset, minOff), maxOff); // Enable or disable inertia movement in this axis - run = validSpeed(velocity) && minOff < 0 && maxOff > 0; + run = validSpeed(velocity); if (run) { event.getNativeEvent().preventDefault(); } @@ -493,26 +489,35 @@ public class Escalator extends Widget implements RequiresResize, xMov.startTouch(event); yMov.startTouch(event); touching = true; + } else { + touching = false; + animation.cancel(); + acceleration = 1; } } public void touchMove(final CustomTouchEvent event) { - xMov.moveTouch(event); - yMov.moveTouch(event); - xMov.validate(yMov); - yMov.validate(xMov); - moveScrollFromEvent(escalator, xMov.delta, yMov.delta, event.getNativeEvent()); + if (touching) { + xMov.moveTouch(event); + yMov.moveTouch(event); + xMov.validate(yMov); + yMov.validate(xMov); + event.getNativeEvent().preventDefault(); + moveScrollFromEvent(escalator, xMov.delta, yMov.delta, event.getNativeEvent()); + } } public void touchEnd(final CustomTouchEvent event) { - xMov.endTouch(event); - yMov.endTouch(event); - xMov.validate(yMov); - yMov.validate(xMov); - // Adjust duration so as longer movements take more duration - boolean vert = !xMov.run || yMov.run && Math.abs(yMov.offset) > Math.abs(xMov.offset); - double delta = Math.abs((vert ? yMov : xMov).offset); - animation.run((int)(3 * DURATION * easingOutExp(delta))); + if (touching) { + xMov.endTouch(event); + yMov.endTouch(event); + xMov.validate(yMov); + yMov.validate(xMov); + // Adjust duration so as longer movements take more duration + boolean vert = !xMov.run || yMov.run && Math.abs(yMov.offset) > Math.abs(xMov.offset); + double delta = Math.abs((vert ? yMov : xMov).offset); + animation.run((int)(3 * DURATION * easingOutExp(delta))); + } } private double easingInOutCos(double val, double max) { -- cgit v1.2.3