Skip to content

Instantly share code, notes, and snippets.

@balanza
Created July 27, 2015 15:04
Show Gist options
  • Save balanza/a1efa05e17c7a6872276 to your computer and use it in GitHub Desktop.
Save balanza/a1efa05e17c7a6872276 to your computer and use it in GitHub Desktop.
Templated Alloy component
<!-- 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>
//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