Titanium JIRA Archive
Alloy (ALOY)

[ALOY-596] Function is being called twice When adding alternate Window platform="android" on view.xml

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionDuplicate
Resolution Date2014-05-01T20:25:17.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsalloy
ReporterMardo Del Cid
AssigneeTim Poulsen
Created2013-03-31T20:03:14.000+0000
Updated2014-05-01T20:25:17.000+0000

Description

app/controllers/home.js: ////////////////////////////////////////// var openBrowserOverlay; openBrowserOverlay = function() { alert("Clicked!"); }; ////////////////////////////////////////// app/views/home.xml: ////////////////////////////////////////// ////////////////////////////////////////// When clicking "addButton" the function is called 2 times (alert appears 2 times) However, changing app/controllers/home.js to: ////////////////////////////////////////// function openBrowserOverlay() { alert("Clicked!"); }; ////////////////////////////////////////// Solves the problem. It's only happening when defining the function with "var" (BTW, it's the way coffeescript defines functions, that's why i noticed) and having an alternate Window with platform="android".

Comments

  1. Tony Lukasavage 2013-04-02

    It looks like on android you'll have 2 windows/buttons right on top of each other, and the buttons will both have the id "addButton". This would likely account for the alert being called twice. I'm going to close this for now and will re-open if more details are provided.
  2. Mardo Del Cid 2013-04-02

    Hello Tony, I'm testing on the iOS Simulator, not on Android. Also, i would like to remark that works OK when using the standard way to define a function:
       function openBrowserOverlay() { 
           alert("Clicked!"); 
       };
       
    But it's called twice when defining the function as a variable:
       var openBrowserOverlay;
       openBrowserOverlay = function() { 
           alert("Clicked!"); 
       };
       
    To easily replicate the issue, create a new alloy app and change *index.js* to:
       var doClick = function(e) {  
           alert($.label.text);
       }
       
       $.index.open();
       
    *index.xml* to:
       <Alloy>
       	<Window class="container" platform="ios">
       		<Label id="label" onClick="doClick">Hello, World</Label>
       	</Window>
       	<Window id="self" platform="android">
       		<Label id="label" onClick="doClick">Hello, World</Label>
       	</Window>
       </Alloy>
       
    // Note that i added *platform="ios"* to the first Window And run it with iOS Simulator: titanium build -p ios P.S. Thanks for the great framework!
  3. Tim Poulsen 2014-02-26

    This appears to be resolved by the fix for ALOY-691.
  4. Tim Poulsen 2014-05-01

    Tested and confirmed that this is no longer an issue thanks to the changes made in ALOY-691.

JSON Source