Skip to content

Instantly share code, notes, and snippets.

@rblalock
Last active December 15, 2015 03:58
Show Gist options
  • Save rblalock/5197869 to your computer and use it in GitHub Desktop.
Save rblalock/5197869 to your computer and use it in GitHub Desktop.
Dynamic styles for alloy.
/**
* Override createWidget until widget styling is possible in Alloy
*/
Alloy.createWidget = function(id, name, args) {
if ("undefined" != typeof name && null !== name && _.isObject(name) && !_.isString(name)) {
args = name;
name = DEFAULT_WIDGET;
}
var widget = new (require("alloy/widgets/" + id + "/controllers/" + (name || DEFAULT_WIDGET)))(args);
// Workaround for styling widgets until the feature is implemented in Alloy
if (args.styles) {
for(var property in args.styles) {
var value = args.styles[property];
if (typeof value === 'object') {
widget[property].applyProperties(value);
}
}
}
return widget;
};
"#textfield": {
styles: {
textfield: {
width: 300,
hintText: "textfield widget"
}
}
}
<Alloy>
<Window id="window">
<Widget id="textfield" src="uikit" name="textfield" />
</Window>
</Alloy>
<Alloy>
<TextField id="textfield" />
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment