NOTE: The module this widget wraps currently doesn't work in Titanium 3.3 and up.
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.
-
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
.
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.
Copyright 2014 Fokke Zandbergen Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.