Titanium Quality of Life: Arguments in Views
Once in a while you just need a good reminder the Titanium SDK, and especially the Alloy framework, has some good Quality of Life features.
This time I want to bring the attention to a quite recent addition to Alloy, arguments you can use in the View files.
And honestly for me it is absolutely a great Quality of life improvement. Just imagine you have this code:
Alloy.createController("subWindow")
You probably already know you can pass data to this controller, by using the 2nd parameter:
Alloy.createController("subWindow", {title: "Hello!"})
But what you probably did with the passed data in the subWindow
controller, was probably using the controller to set the data to the property you want, like this:
$.win.title = $.args.title
But… did you know, you can actually do this directly in the xml?
<Window title="$.args.title">
That way, you don’t need anything in your controller file for specifying properties like this.
And it doesn’t just work with plain properties either, it also works with things like callbacks
Alloy.createController("subWindow", {clicker: (e) => {})
And then in your subWindow
View:
<View onClick="$.args.clicker" />
Or you can even customize views
Alloy.createController("subWindow", {hideLabel: true})
And then in the View:
<Label if="!$.args.hideLabel" />
Very useful right? Hope it helps you customize and develop your apps faster!