Created
May 3, 2011 17:44
-
-
Save jonalter/953810 to your computer and use it in GitHub Desktop.
Creating Reusable Factories and Using Ti.App with a Namespace
This file contains 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
// Please note that this is a dirty solution. | |
// It does work, but Appcelerator does not support it (adding things to the Ti namespace). | |
// There is a very good chance that it will not be possible in future releases. | |
var ui = {}; | |
var labels = {}; | |
Ti.include('ui.js'); | |
Ti.include('labels.js'); | |
// Build the namespace | |
var NS = { | |
ui:ui, | |
labels:labels | |
}; | |
// Make namespace globally available | |
Ti.App.NS = NS; | |
var win = Ti.App.NS.ui.createCustomWindow(); | |
var button = Ti.App.NS.ui.createCustomButton(); | |
win.add(button); | |
var myLabel = Ti.App.NS.labels.createCustomLabel(); | |
win.add(myLabel); | |
win.open(); |
This file contains 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
(function(){ | |
labels = { | |
createCustomLabel: function(){ | |
var label = Ti.UI.createLabel({ | |
top: 10, | |
height: 60, | |
width: 200, | |
text: 'I am a Label' | |
}); | |
return label; | |
} | |
}; | |
})(); |
This file contains 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
(function() { | |
ui = { | |
createCustomWindow: function() { | |
var win = Ti.UI.createWindow({ | |
backgroundColor: 'green' | |
}); | |
return win; | |
} | |
}; | |
ui.createCustomButton = function() { | |
var button = Ti.UI.createButton({ | |
title: 'Button', | |
height: 60, | |
width: 150 | |
}); | |
return button; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment