From fbca7e57f42bdcbd9db693814d33c3561e3b61dc Mon Sep 17 00:00:00 2001 From: Sergey Budkin Date: Tue, 30 Sep 2014 14:58:30 +0300 Subject: [PATCH] Action on click button contained in table is called two times on iOS 8.0 (#14632) Added suppression of second phantom click event. Change-Id: I97d01831b09f0a41976bbefef389f47a0271fc70 --- client/src/com/vaadin/client/ui/VButton.java | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/client/src/com/vaadin/client/ui/VButton.java b/client/src/com/vaadin/client/ui/VButton.java index 2e5494ec18..dcc364c1da 100644 --- a/client/src/com/vaadin/client/ui/VButton.java +++ b/client/src/com/vaadin/client/ui/VButton.java @@ -95,6 +95,7 @@ public class VButton extends FocusWidget implements ClickHandler { private HandlerRegistration focusHandlerRegistration; private HandlerRegistration blurHandlerRegistration; + private long lastClickTime = 0; public VButton() { super(DOM.createDiv()); @@ -163,13 +164,29 @@ public class VButton extends FocusWidget implements ClickHandler { int type = DOM.eventGetType(event); switch (type) { case Event.ONCLICK: - // If clicks are currently disallowed, keep it from bubbling or - // being passed to the superclass. - if (disallowNextClick) { + // fix for #14632 - on mobile safari 8, if we press the button long + // enough, we might get two click events, so we are suppressing + // second if it is too soon + boolean isPhantomClickPossible = BrowserInfo.get().isSafari() + && BrowserInfo.get().isTouchDevice() + && BrowserInfo.get().getBrowserMajorVersion() == 8; + long clickTime = isPhantomClickPossible ? System + .currentTimeMillis() : 0; + // If clicks are currently disallowed or phantom, keep it from + // bubbling or being passed to the superclass. + if (disallowNextClick || isPhantomClickPossible + && (clickTime - lastClickTime < 100)) { // the maximum + // interval observed + // for phantom click + // is 69, with + // majority under + // 50, so we select + // 100 to be safe event.stopPropagation(); disallowNextClick = false; return; } + lastClickTime = clickTime; break; case Event.ONMOUSEDOWN: if (DOM.isOrHasChild(getElement(), DOM.eventGetTarget(event))) { -- 2.39.5