[ALOY-1283] ActionView views with an ID cannot be found under $ because they are created after merge
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-10-16T00:38:14.000+0000 |
Affected Version/s | Alloy 1.6.2, alloy 1.7.17 |
Fix Version/s | Release 5.1.0, alloy 1.7.18 |
Components | XML |
Labels | n/a |
Reporter | Fokke Zandbergen |
Assignee | Feon Sua Xin Miao |
Created | 2015-06-25T10:16:10.000+0000 |
Updated | 2015-11-10T23:35:36.000+0000 |
Description
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*
<Alloy>
<Window>
<Menu>
<MenuItem title="Open" showAsAction="Titanium.Android.SHOW_AS_ACTION_ALWAYS">
<ActionView>
<View id="myViewInActionView" backgroundColor="red">
<Button onClick="changeColor">Change Color</Button>
</View>
</ActionView>
</MenuItem>
</Menu>
</Window>
</Alloy>
*index.js*
$.index.open();
function changeColor() {
$.myViewInActionView.backgroundColor = 'green';
}
Comments
- Feon Sua Xin Miao 2015-10-15 PR: https://github.com/appcelerator/alloy/pull/732
- 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:
And sincefunction __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" }); $.__views.myViewInActionView.add($.__views.__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."); } }
onCreateOptionsMenu
executes _after__.extend($, $.__views);
the above has no effect anymore on$
. So whatever happens insideonCreateOptionsMenu
needs to write directly to$
or merge its views with it at the end. - Feon Sua Xin Miao 2015-10-15
It's interesting that the generated code is different for me.
$.__views.myViewInActionView.add($.__views.__alloyId3); 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" };
- Fokke Zandbergen 2015-10-15 Sorry [~fmiao], my fault.. patched the wrong (global) alloy. Verified fixed.
- Feon Sua Xin Miao 2015-10-16 PR merged.
- Eric Wieber 2015-11-10
Verified fixed, using:
MacOS 10.11.2 (15C31f)
Studio 4.4.0.201511040454
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 $. .