An introduction the big picture of the Appcelerator Platform and the architecture and principles behind Titanium and Alloy to get you started. Created and presented by myself and Pierre van de Velde at meetup.com/TitaniumNL.
23. Hello World
var window = Ti.UI.createWindow({
backgroundColor: “white"
});
var label = Ti.UI.createLabel({
text: “Hello World”
});
label.addEventListener(“click”,
function open() {
alert(“Hello World”);
}
);
window.add(label);
window.open();
Ti API
48. Get your code organised
You can organise controllers in subfolders.
Use CommonJS modules
module.exports = {
property: value,
util: function() {}
};
module.js
Drop modules .zip files in root directory
49. Don’t repeat yourself
Use Alloy.CFG to get your config in one place
"global": {
"COLORS": { "WHITE": “#fff" },
"FONTS": { "FONT_FAMILY_LIGHT": “Montserrat-Light" },
"SIZES": { "MARGIN_XSMALL": “5” }
}
config.json
".container": {
top: Alloy.CFG.SIZES.MARGIN_XSMALL,
backgroundColor: Alloy.CFG.COLORS.WHITE
}
style.tss
50. Use global styling
Create Global styling to be applied everywhere
".Compact": { height: Ti.UI.SIZE, width: Ti.UI.SIZE }
".Left" : { left: 0 }
".Top" : { top: 0 }
".Error" : {
backgroundColor: Alloy.CFG.COLORS.WHITE,
color: Alloy.CFG.COLORS.RED,
}
app.tss
<Label class="Bottom Hidden Error" /> view.xml
51. Platform specifics
Phones are not fixed size, use layouts
<View class="container" layout="vertical"> view.xml
Use platform specific styling
"ActivityIndicator[platform=android]":{
style: Ti.UI.ActivityIndicatorStyle.DARK
}
"ActivityIndicator[platform=ios]":{
style: Ti.UI.iPhone.ActivityIndicatorStyle.DARK
}
style.tss
Specifics folders for platform & density