Created
July 27, 2015 15:04
-
-
Save balanza/a1efa05e17c7a6872276 to your computer and use it in GitHub Desktop.
Templated Alloy component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- that's the pursued implementation --> | |
<Alloy> | |
<MyComponent ns="require('myui')" id="mc1" foo="bar"> | |
<Label>That's my precious content!</Label> | |
</MyComponent> | |
<MyComponent ns="require('myui')" id="mc2" foo="bar"> | |
<Label>Another precious content!</Label> | |
</MyComponent> | |
</Alloy> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//that's the component implementation | |
exports.createMyComponent = function(args){ | |
/* | |
I Want a structure like: | |
<View id="viewA"> | |
<Label>Some prepended default content</Label> | |
<View id="viewB"> <!-- here where I want content!! --> </View> | |
<Button>Some common action button</Button> | |
</View> | |
ViewB is actually a placeholder | |
*/ | |
// I create the elements | |
var viewA = Ti.UI.createView({layout: 'vertical'}); //this is my "wrapper view" | |
var viewB = Ti.UI.createView(); | |
var label = Ti.UI.createView({title : 'Some prepended default content'}); | |
var button = Ti.UI.createView({text : 'Some common action button'}); | |
// I compose the structure | |
viewA.add(label); | |
viewA.add(viewB); | |
viewA.add(button); | |
//here's where I override the 'add()' method | |
viewA.add = viewB.add; | |
return viewA; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment