[ALOY-1283] ActionView views with an ID cannot be found under $ because they are created after merge

GitHub Issuen/a
Resolution Date2015-10-16T00:38:14.000+0000
Affected Version/sAlloy 1.6.2, alloy 1.7.17
Fix Version/sRelease 5.1.0, alloy 1.7.18
ReporterFokke Zandbergen
AssigneeFeon Sua Xin Miao


ALOY-1175 fixed this issue for IDs set on <MenuItem> but it is still an issue for views under <ActionView>. Because they are created after the controller merges $.__views with $ you cannot access the views via $.<id>. *index.xml*
            <MenuItem title="Open" showAsAction="Titanium.Android.SHOW_AS_ACTION_ALWAYS">
                    <View id="myViewInActionView" backgroundColor="red">
                    	<Button onClick="changeColor">Change Color</Button>
function changeColor() {
  $.myViewInActionView.backgroundColor = 'green';


  1. Feon Sua Xin Miao 2015-10-15 PR: https://github.com/appcelerator/alloy/pull/732
  2. Fokke Zandbergen 2015-10-15 [~fmiao] I updated the test case to make it simpler but the PR doesn't fix it. The above - with your PR - compiles to:
           function __alloyId4() {
               $.__views.index.removeEventListener("open", __alloyId4);
               if ($.__views.index.activity) $.__views.index.activity.onCreateOptionsMenu = function(e) {
                   $.__views.myViewInActionView = Ti.UI.createView({
                       id: "myViewInActionView",
                       backgroundColor: "red"
                   $.__views.__alloyId2 = Ti.UI.createButton({
                       title: "Change Color",
                       id: "__alloyId2"
                   changeColor ? $.addListener($.__views.__alloyId2, "click", changeColor) : __defers["$.__views.__alloyId2!click!changeColor"] = true;
                   var __alloyId3 = {
                       title: "Open",
                       showAsAction: Titanium.Android.SHOW_AS_ACTION_ALWAYS,
                       id: "__alloyId1"
                   $.__views.myViewInActionView && (__alloyId3.actionView = $.__views.myViewInActionView);
                   $.__views.__alloyId1 = e.menu.add(_.pick(__alloyId3, Alloy.Android.menuItemCreateArgs));
                   $.__views.__alloyId1.applyProperties(_.omit(__alloyId3, Alloy.Android.menuItemCreateArgs));
                   $.__alloyId1 = $.__views.__alloyId1;
               }; else {
                   Ti.API.warn("You attempted to attach an Android Menu to a lightweight Window");
                   Ti.API.warn("or other UI component which does not have an Android activity.");
                   Ti.API.warn("Android Menus can only be opened on TabGroups and heavyweight Windows.");
    And since onCreateOptionsMenu executes _after_ _.extend($, $.__views); the above has no effect anymore on $. So whatever happens inside onCreateOptionsMenu needs to write directly to $ or merge its views with it at the end.
  3. Feon Sua Xin Miao 2015-10-15 It's interesting that the generated code is different for me.
                   changeColor ? $.addListener($.__views.__alloyId3, "click", changeColor) : __defers["$.__views.__alloyId3!click!changeColor"] = true;
                   $.myViewInActionView = $.__views.myViewInActionView; // <---- missing
                   var __alloyId4 = {
                       title: "Open",
                       showAsAction: Titanium.Android.SHOW_AS_ACTION_ALWAYS,
                       id: "__alloyId1"
  4. Fokke Zandbergen 2015-10-15 Sorry [~fmiao], my fault.. patched the wrong (global) alloy. Verified fixed.
  5. Feon Sua Xin Miao 2015-10-16 PR merged.
  6. Eric Wieber 2015-11-10 Verified fixed, using: MacOS 10.11.2 (15C31f) Studio Ti SDK 5.1.0.v20151110110428 Appc NPM 4.2.1 Appc CLI 5.1.0-45 Ti CLI 5.0.5 Alloy 1.7.24 Arrow 1.3.19 Xcode 7.2 (7C46t) Node v0.12.7 Java 1.7.0_80 production ActionViews can be accessed with $., as expected. Used the provided test code. ActionView properties/methods can be accessed during runtime with the standard $..

JSON Source