Titanium JIRA Archive
Alloy (ALOY)

[ALOY-851] Alloy: Setting default ID on first top-level XML view element doesn't take platform attribute into account

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-01-21T22:28:02.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.4.0
ComponentsXML
Labelsalloy, compiler, conditions, platform, qe-testadded
ReporterMauro Parra-Miranda
AssigneeTony Lukasavage
Created2013-10-17T14:33:51.000+0000
Updated2015-10-12T08:08:02.000+0000

Description

The compiler sets the id of the first top-level XML view element to the default (the controller name) *before* the platform conditions are evaluated. Now if you have a view in which you use the platform attribute to select which top-level element should be used for each platform, this leads to unpredictable behavior. Only the first (conditional) top-level element will get the default id.

Steps to reproduce

1. Create new project: titanium create -p ios,android -n defaultid --id ti.defaultid -d . 2. Initialize Alloy: cd defaultid && alloy new 3. Replace contents of index.xml with:
    <Alloy>
        <Window platform="ios" class="container">
            <Label id="label" onClick="doClick">Hello, World</Label>
        </Window>
        <Window platform="android" class="container">
            <Label id="label" onClick="doClick">Hello, World</Label>
        </Window>
    </Alloy>
    
4. Compile for iOS: alloy compile -c platform=ios 5. Open Resources/alloy/controllers/index.js and see that the window has correctly been given index as id. 4. Compile for Android: alloy compile -c platform=android 5. Open Resources/alloy/controllers/index.js and see that the window has *not* been given index as id.

Comments

  1. Tim Poulsen 2014-01-21

    I can confirm the behavior is present as described.
       $.__views.index = Ti.UI.createWindow({
           id: "index"
       });
       
       $.__views.index = Ti.UI.createWindow({
           id: "__alloyId0"
       });
       
  2. Tony Lukasavage 2014-01-21

    I'm going to solve 2 for 1 here, since in addition to this, the event handler is rendered twice, once for each platform despite that only one should be generated. PR: https://github.com/appcelerator/alloy/pull/304 Functional testing should be the same as noted in the description and previous comments. In addition to validating that the default id gets applied in the android case, also assert that in both cases that only one event handler gets assigned. You can assert this by making sure there is on;y one line like this at the bottom of the generated controllers:
       __defers["$.__views.label!click!doClick"] && $.__views.label.addEventListener("click", doClick);
       
    Prior to this fix, the event handler would have showed up twice, one right after the other.
  3. Fokke Zandbergen 2014-01-22

    Wow, never noticed that double event handler. Nice to have that fixed ;)

JSON Source