OnTouchUp/Down fired twice

43 views
Skip to first unread message

Alan Hendry

unread,
Sep 18, 2022, 2:14:56 PM9/18/22
to DroidScript
HI,
Pretty sure I ran across this before, but I can't find the post.
I have a simulatetouch that seems to trigger the ontouch (up or down) twice
Regards, ah

"use strict";
function OnStart() {
    var lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
    var tg1 = qtoggle(lay)
    app.AddLayout( lay );
} // fn
function qtoggle(lay) {
    var qlay = app.AddLayout(lay,"Linear","Horizontal,Touchspy")
    qlay.SetOnTouchUp(function (event) {
        alert(event.action)
    })
    var qbtn = app.AddText(qlay,"[fa-minus]",-1,-1,"fontawesome")
    app.SimulateTouch(qlay,0,0,"up")
    return qlay
} // fn


Right2TheV0id

unread,
Sep 18, 2022, 4:38:09 PM9/18/22
to DroidScript
I suppose it is because SimulateTouch fires before the text element is effectively added to qlay.
It is added in the correct order in the code, but somehow DS or Android seems to add it a bit later, asynchronously.
Therefore SimulateTouch fires too early and touches qlay directly (not qbtn).
OnTouchUp is fired twice because the layout "spies itself" as I stated here:

Adding a little delay removes the problem: 
setTimeout( function() { app.SimulateTouch(qlay,0,0,"up") }, 1 );

Alan Hendry

unread,
Sep 19, 2022, 1:09:49 PM9/19/22
to DroidScript
Hi,
Not sure I understand at all.
In your example you create layout (with Touchspy), add touchdown, add layout, 
and it invokes the callback twice when the user touches.
I create layout, set layout on touch, add text, simulate touch on layout, 
and seems to invoke the callback twice for the simulate, 
but when the user touches it only does it once (correctly).  
I've run across other "timing problems" (for example AddCamera and SetOnReady).
Regards, ah

Reply all
Reply to author
Forward
0 new messages