[ALOY-851] Alloy: Setting default ID on first top-level XML view element doesn't take platform attribute into account
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-01-21T22:28:02.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.4.0 |
Components | XML |
Labels | alloy, compiler, conditions, platform, qe-testadded |
Reporter | Mauro Parra-Miranda |
Assignee | Tony Lukasavage |
Created | 2013-10-17T14:33:51.000+0000 |
Updated | 2015-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.
I can confirm the behavior is present as described.
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:
Prior to this fix, the event handler would have showed up twice, one right after the other.
Wow, never noticed that double event handler. Nice to have that fixed ;)