Skip to content

Instantly share code, notes, and snippets.

@animecyc
Created July 27, 2015 15:39
Show Gist options
  • Save animecyc/093901bf4f94396efa7f to your computer and use it in GitHub Desktop.
Save animecyc/093901bf4f94396efa7f to your computer and use it in GitHub Desktop.
Wrapping controller example
(function(opts) {
'use strict';
// Override MyComponent
$.MyComponent = $.content;
// Append all the children
var children = opts.children || [];
if (OS_ANDROID) {
for (var i = 0; i < children.length; i++) {
$.content.add(children[i]);
}
} else {
$.content.add(children);
}
// Swizzle the methods that export the root
_.extend(exports, {
/* Swizzling getTopLevelViews */
getTopLevelViewsOrig: exports.getTopLevelViews,
getTopLevelViews: function() {
return [$.content];
},
/* Swizzling getView */
getViewOrig: exports.getView,
getView: function() {
if (!arguments.length) {
return $.content;
}
return this.getViewOrig.apply(this, arguments);
}
});
}(arguments[0] || {}));
"#MyComponent": {
layout: 'vertical'
},
"#content": {
height: Ti.UI.SIZE
}
<Alloy>
<View>
<Label text="I'm the wrapper!"/>
<View id="content"/>
</View>
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment