[ALOY-545] Setting widget view-controller from within XML views
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Resolved |
Resolution | Fixed |
Resolution Date | 2013-03-18T20:50:20.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.1.0, 2013 Sprint 06 |
Components | XML |
Labels | alloy, compiler, controller, views, xml |
Reporter | Fokke Zandbergen |
Assignee | Unknown |
Created | 2013-02-23T22:20:46.000+0000 |
Updated | 2018-03-07T22:25:57.000+0000 |
Description
If you require a widget in a XML view like this:
elements, whose value would be used as the second argument for createWidget. I’ve made the necessary changes to Alloy.Require.js and did a pull request for this:
https://github.com/appcelerator/alloy/pull/111
<widget src="nl.fokkezb.tweetsView" foo="bar" id="myWidget"></widget>
It generates code like this:
$.__views.myWidget = Alloy.createWidget("nl.fokkezb.tweetsView", "widget", {
id: "myWidget",
foo: "bar"
});
Let’s take a look at the code for createWidget in alloy.js:
exports.createWidget = function(id, name, args) {
return new (require("alloy/widgets/" + id + "/controllers/" + (name || "widget")))(args);
};
As you can see, the second argument specifies the controller to require from the widget. You might not have known this, but the docs do mention that widget can contain multiple view-controllers, just like your app does.
Unfortunately, to use this feature you need to create the widget in your controller using code similar to the second fragment above. It’s currently not possible to do this in the view.
This is a missed opportunity to use a singe widget to expose a collection of reusable UI elements:
<view>
<widget src="nl.fokkezb.ui" name="myFancyButton"></widget>
<widget src="nl.fokkezb.ui" name="myCustomView"></widget>
<widget src="nl.fokkezb.ui" name="myHorizontalTable"></widget>
…
</view>
Or create a widget that can be used in multiple contexts:
<tabgroup>
<widget src="nl.fokkezb.tweetsView" name="tab"></widget>
<tab>
<widget src="nl.fokkezb.tweetsView" name="window"></widget>
</tab>
</tabgroup>
So my feature request / improvement would be to support the name attribute for
Also updated widgets/basic test app to use this functionality: https://github.com/appcelerator/alloy/tree/master/test/apps/widgets/basic
Tested the app - https://github.com/appcelerator/alloy/tree/master/test/apps/widgets/basic It is working fine with alloy version 1.1.2.Can close the bug.