Skip to content

Instantly share code, notes, and snippets.

@iskugor
Created March 13, 2012 10:23
Show Gist options
  • Save iskugor/2028016 to your computer and use it in GitHub Desktop.
Save iskugor/2028016 to your computer and use it in GitHub Desktop.
Titanium prototype-based wrappers
"use strict";
var Ad = require('library/adriatic');
var Window = Ad.require('window', 'ui');
var View = Ad.require('view', 'ui');
var Button = Ad.require('button', 'ui');
var TableView = Ad.require('table_view', 'ui');
var TableViewRow = Ad.require('table_view_row', 'ui');
var win = new Window({ layout: 'vertical' });
var view1 = new View({ height: '10%', backgroundColor: '#000' });
var button1 = new Button({ title: 'Testing' });
var button2 = new Button({ title: 'Testing 2' });
function View2(viewProperties) {
this.setProperties(viewProperties);
}
Ad.extend(View2, View);
View2.prototype.customMethod = function() {
Ti.API.info('customMethod');
};
var view2 = new View2({ backgroundColor: '#fff', height: '20%' });
var table = new TableView({ height: 'auto', backgroundColor: '#ccc' });
var rows = [];
for (var i = 0; i < 50; ++i) {
rows.push(new TableViewRow({ title: 'Row ' + i, color: '#000', className: 'tablerow' }));
}
//uses "setData" in the background
table.appendRows(rows);
win.add(view1, 'View1');
win.add(button1, 'Button1');
win.add(view2, 'View2');
win.add(button2, 'Button2');
win.add(table, 'Table');
win.open();
view2.customMethod(); // prints "customMethod"
Ti.API.info('WTF');
Ti.API.debug(win.getTiElement().children.length); // prints "0"
Ti.API.info('Ou yeah!');
Ti.API.debug(win.getChildren().length); // prints "5"
/*
//this is "extend" function (nothing fancy, nothing new)
var extend = (function() {
var Fn = function() {};
return function(fnSub, fnSuper) {
Fn.prototype = fnSuper.prototype;
fnSub.prototype = new Fn();
fnSub.__parentConstructor = fnSuper;
fnSub.prototype.constructor = fnSub;
};
})();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment