Last active
September 18, 2015 21:12
-
-
Save zo0m/0166cb2772e2d5ea8280 to your computer and use it in GitHub Desktop.
Titanium UI Factory example
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
/** | |
* Inside controller : | |
* | |
* var customGUIManager = new CustomGUIManager($); | |
* | |
* customGUIManager.createLabel('sampleUIClassName', 'SampleText', { left : '15dp'}), | |
* | |
*/ | |
function CustomGUIManager(controller) { | |
this.styleCache = {}; | |
this.createStyleByClass = function(className, apiName) { | |
if (apiName) { | |
return controller.createStyle ({ classes : className, apiName: apiName}); | |
} | |
return controller.createStyle ({ classes : className }); | |
}; | |
this.getCachedStyleIfExists = function(className, apiName) { | |
if (!this.styleCache[className]) | |
{ | |
this.styleCache[className] = this.createStyleByClass(className, apiName); | |
} | |
return this.styleCache[className]; | |
}; | |
this.createUI = function (styleName, apiName, addionalParams, createElementWithStyleFunction) { | |
var style = this.getCachedStyleIfExists(styleName); | |
var element = createElementWithStyleFunction(style, apiName); | |
if (addionalParams) { | |
for (var key in addionalParams) { | |
element[key] = addionalParams[key]; | |
} | |
} | |
return element; | |
}; | |
this.createView = function(styleName, content, addionalParams) { | |
var view = this.createUI(styleName, 'View', addionalParams, Ti.UI.createView); | |
if (content) { | |
var contentArray = content; | |
if (content.constructor !== Array) | |
{ | |
contentArray = [content]; | |
} | |
contentArray.forEach(function(item) { | |
view.add(item); | |
}); | |
} | |
return view; | |
}; | |
this.createTextField = function(styleName, value, hintText, addionalParams) { | |
if (!addionalParams) { | |
addionalParams = {}; | |
} | |
if (value) addionalParams.value = value; | |
if (hintText) addionalParams.hintText = hintText; | |
return this.createUI(styleName, 'TextField', addionalParams, Ti.UI.createTextField); | |
}; | |
this.createLabel = function(styleName, text, addionalParams) { | |
if (!addionalParams) { | |
addionalParams = {}; | |
} | |
if (text) addionalParams.text = text; | |
return this.createUI(styleName, 'Label', addionalParams, Ti.UI.createLabel); | |
}; | |
this.createButton = function(styleName, title, addionalParams) { | |
if (!addionalParams) { | |
addionalParams = {}; | |
} | |
if (text) addionalParams.title = title; | |
return this.createUI(styleName, 'Button', addionalParams, Ti.UI.createButton); | |
}; | |
this.createTableViewRow = function(styleName, content, addionalParams) { | |
if (!addionalParams) { | |
addionalParams = {}; | |
} | |
var tableViewRow = this.createUI(styleName, 'TableViewRow', addionalParams, Ti.UI.createTableViewRow); | |
if (content) { | |
var contentArray = content; | |
if (content.constructor !== Array) | |
{ | |
contentArray = [content]; | |
} | |
contentArray.forEach(function(item) { | |
tableViewRow.add(item); | |
}); | |
} | |
return tableViewRow; | |
}; | |
this.Update = { | |
updateLabel : function(label, params) | |
{ | |
if (label.baseText) | |
{ | |
label.text = label.baseText.printf(params); | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While trying to integrate
customGUIManager
into my project I get these errors.I'm passing a controller
$
in which I have some Android specific controls, inside a condition like thisif (Ti.Platform.Android) { ... }
When running the app without
customGUIManager
it works.I'm calling
customGUIManager
like this:Do you have any ideas? Thank's!
EDIT:
The same problem occurs when trying this in the controller itself:
I guess then it is a problem with Appcelerator and the way
createStyle
works..PS Appcelerator Studio SDK 4.0.0.GA on Mac Yosemite building to iOS 4S Simulator