StageXL icon indicating copy to clipboard operation
StageXL copied to clipboard

iOS tap delay

Open mnordine opened this issue 10 years ago • 10 comments

I get the dreaded iOS tap delay, even when trying 3rd party libraries, such as FastClick.

I created a simple web app with stagehand

mnordine avatar Nov 19 '15 21:11 mnordine

At least in that example, using MouseEvent.MOUSE_DOWN (or its touch equivalent) should do the trick.

And in more complex situations: animation on DOWN, 'submit' on UP. If you need dragging: start a listener to ENTER_FRAME after a certain delay on DOWN, and cancel the delay and listener on UP; also only 'submit' if the mousePos didn't change (apply a certain threshold).

nilsdoehring avatar Nov 19 '15 23:11 nilsdoehring

But isn't that exactly what the library should be doing behind the scenes?

mnordine avatar Nov 19 '15 23:11 mnordine

Hi guys. I don't know how or if the FastClick library is working, but the general advice is to register touch-events to get an immediate response on mobile devices. Please check out the StageOptions provided in the static StageXL class.

var isSupported = StageXL.environment.isTouchEventSupported;
StageXL.stageOptions.inputEventMode = InputEventMode.MouseOnly; 

You can use the same event handlers for mouse and touch events, since all MouseEvents and TouchEvents extend the same base class called InputEvent. This should make it pretty easy to get optimal support for mouse and touch.

bp74 avatar Nov 20 '15 07:11 bp74

I tried to set it to InputEventMode.MouseOnly, but same result, still have the delay. I tried all the InputEventModes, actually.

mnordine avatar Nov 20 '15 13:11 mnordine

Seems InputEventMode.MouseOnly is the default anyway.

mnordine avatar Nov 20 '15 13:11 mnordine

yes this was just a copy-paste from an example, if you want to use touch input you have to set it to one of the touch modes. So you have to set the InputEventMode and also register to the touch events, this should give you instant feedback on user input.

bp74 avatar Nov 20 '15 14:11 bp74

You can also look at the example here: https://github.com/bp74/StageXL_Samples/blob/master/example/interactive/drag/index.dart

bp74 avatar Nov 20 '15 15:11 bp74

So, you get instant feedback on iOS if you set to InputEventMode.TouchOnly or InputEventMode.TouchAndMouse and use onTouchBegin. But I don't think this is a good solution, since every developer will have to implement something like @nilsdoehring suggested above for acceptable click behavior on iOS.

It'd be nice if devs could use MouseEvent.CLICK, not have iOS lag, and have it abstracted away for them, so they needn't worry about it.

mnordine avatar Nov 20 '15 15:11 mnordine

Well we could do this, but the solution with a common event handler is not so much harder to implement. You could even use a helper function that adds both event handlers at the same time.

bp74 avatar Nov 20 '15 21:11 bp74

That's why I am in the process of creating the stagexl-commons library, which aims to solve, well, common stuff like this :-) It's not on pub yet, so you need to reference this github repo: https://github.com/blockforest/stagexl-commons/

For your use case, extend the Button class and override downAction and/or upAction. https://github.com/blockforest/stagexl-commons/blob/master/lib/src/view/interact/button/impl/button.dart

Disclaimer: stagexl-commons is not an official part of StageXL. Also, no animals have been harmed during its production.

nilsdoehring avatar Nov 20 '15 23:11 nilsdoehring