CommonJS module extending some Ti.UI.create*
factories.
Just replace Ti.UI
with ui
and in Alloy use the module
attribute:
<Alloy>
<View module="ui" />
</Alloy>
var UI = require('ui');
var view = UI.createView();
As documented, background images will be scaled to fit the view's dimensions.
The createView
factory adds support for the background-size:cover property known from CSS. If set, it will resize and then crop the image to make sure it fits the view's dimensions while respecting the aspect ratio of the image.
If you don't set a width
and height
property, it will add a postlayout
event listener to get them when the view is layed out. Of course the resized images are cached, but if you don't want to wait for postlayout
, then use the backgroundTarget
property to pass a string to identify the target, but only if you know for sure the dimensions found using postlayout
would always be the same for that particular view.
<Alloy>
<View module="ui" backgroundImage="images/background.jpg" backgroundSize="cover" backgroundTarget="myView" />
</Alloy>
Its also possible to use the property backgroundRotate
to support the cover background to be rendered for both portrait and landscape layout. Dont mix this with the backgroundTarget
property since it will disable this feature.
<Alloy>
<View module="ui" backgroundImage="images/background.jpg" backgroundSize="cover" backgroundRotate ="true" />
</Alloy>
Adds 2 methods to the Ti.UI.Button
proxy (yeah, I know.. you're not supposed to do that) with extra features for event handling.
Extends the UI Button with a click
event listener that only executes when no previous click is still being handled.
<Button module="xp.ui" id="btnName" />
$.btnName.addEventListenerSingle(onlyFiresWhenPreviousIsDone);
Will only execure the callback once, and remove it afterwards.
$.btnName.addEventListenerOnce("longpress", onlyFiresOnce);