Hi all,
Getting a feel for dynamic styles by trying to apply the api doc example to my own project. I want to apply hi-res/low-res styling to my UI elements at runtime rather than building separate views for each possible form-factor and resolution. With that in mind, I modified the api example as follows:
var orient = Ti.UI.getOrientation(); var dimensions = Alloy.Globals.getDimensions(); var screenHeight = dimensions[0]; var screenWidth = dimensions[1]; //low resolution screen dimensions var LOW_RES = 320 * 480; //determine resolution and orientation var args = {}; args.win = ['win-lowRes', 'font-lowRes']; $.home.addEventListener('focus', function(args) { _args = args[0] || {}; if ((screenHeight * screenWidth) > LOW_RES) { if (_args.win) { var style = $.createStyle({ classes : _args.win, apiName : 'Window', font: {fontSize: '24dp', fontWeight: 'bold' } }); } $.home.applyProperties(style); } });However, an error is thrown when executing
$.home.applyProperties(style);
like this:[ERROR] : message = "Invalid type passed to function"; [ERROR] : nativeLocation = "-[TiProxy applyProperties:] (TiProxy.m:1184)"; [ERROR] : nativeReason = "expected: Object, was: NSNull";Not sure why I'm getting an error because my code doesn't stray too far from the original example. Does it have something to do with context since the api example passes the args[] object to another page and Idon't?
What do I have to do to get this to work? Or do I misunderstand the use of dynamic styling? If you have any questions, feel free to ask.
Regards.