Awesome
NOTE: The module this widget wraps currently doesn't work in Titanium 3.3 and up.
Alloy Android ViewPager Widget
This is a widget for the Alloy MVC framework of Appcelerator's Titanium platform.
It wraps the Android ViewPager Module module by Navid Ghahramani, which exposes the native ViewPager found in apps like Google Play.
Example
[]
Usage
-
Install the Android ViewPager Module module for Android via gitTio:
gittio install com.navid.tabs
-
Install this widget via gitTio:
gittio install nl.fokkezb.viewpager
-
In your
app/views/index.xml
use it like this:<Alloy> <Window> <Widget id="pager" src="nl.fokkezb.viewpager"> <View backgroundColor="red" title="Red tab" /> <View backgroundColor="green" title="Green tab" /> <View backgroundColor="blue" title="Blue tab" /> <View backgroundColor="yellow" title="Yellow tab" /> </Widget> </Window> </Alloy>
-
In your
app/styles/index.tss
style it like this:"#pager": { backgroundColor: 'white', alignment: 'ALIGNMENT_RIGHT', current: 2 }
NOTE: You don't need to group the properties in a
tab
object like the module requires and thealignment
constant can be set as a string. -
In your
app/controlers/index.js
use it like this:$.index.open(); $.pager.add(Ti.UI.createView({ title: 'Dynamic tab', backgroundColor: 'white' }));
NOTE: Any ViewPager property or method can be get, set or called via the widget, but you can also access the module and instance directly via
$.pager.module
and$.pager.instance
.
Events
The module uses constants like module.PAGE_SCROLLED_EVENT_NAME
for the event names. The widget supports adding event listeners in the following ways:
index.xml
<Widget src="nl.fokkezb.viewpager" onPAGE_SCROLLED_EVENT_NAME="myListener" />
index.js
$.pager.on('PAGE_SCROLLED_EVENT_NAME', myListener);
Of course you can also refer to the actual constant with $.pager.module.PAGE_SCROLLED_EVENT_NAME
or the string pageScrolled
the constant stands for.