]> source.dussan.org Git - vaadin-framework.git/commitdiff
Action on click button contained in table is called two times on iOS 8.0 (#14632)
authorSergey Budkin <sergey@vaadin.com>
Tue, 30 Sep 2014 11:58:30 +0000 (14:58 +0300)
committerMarkus Koivisto <markus@vaadin.com>
Tue, 14 Oct 2014 14:57:30 +0000 (17:57 +0300)
Added suppression of second phantom click event.

Change-Id: I97d01831b09f0a41976bbefef389f47a0271fc70

client/src/com/vaadin/client/ui/VButton.java

index 2e5494ec1825dc6f5159f46e7a7a2bf8674690a7..dcc364c1da448986230cdad9a97524420d1a9b6e 100644 (file)
@@ -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))) {