Time to release something new. I’ve been working on a little project to develop an Android app. I’ve chosen Titanium because the app is simple (no network connectivity, sensor interaction, maps, etc.) and the learning curve for Titanium is low.
I had been working with the Android SDK for about a week (very frustrating), and one feature I found to be missing from Titanium is a decent way to scroll through large datasets horizontally. In my case, I had a few dozen pages that needed to be scrolled. I didn’t want to plop all of them into a ScrollableView, since that would put a strain on Android. So, I created this little module.
It is based off of this GitHub gist, though it doesn’t bear much resemblance anymore. Scroll down for links to my project.
VirtualScroller
The module I created is called VirtualScroller, and you use it like this:
// Replace the path as necessary
var VirtualScroller = require('ui/common/VirtualScroller');
var virtualScroller = VirtualScroller({
itemCount: 10,
getView: function(i) {
return Titanium.UI.createLabel({
width: Titanium.UI.FILL,
height: Titanium.UI.FILL,
text: "This is item " + (i + 1)
});
},
infinite: false
});
window.add(virtualScroller);
I’ll steal the description from my BitBucket page, since I don’t feel like writing a new one:
VirtualScroller is an easy to use Titanium module that wraps around a ScrollableView and provides finite and infinite scrolling. All items (which are actually Views) are created on-demand, and only remain in memory when needed. The ScrollableView instance has three Views, which act as containers for the actual items.
This method permits memory-efficient scrolling of large sets of views.
So, if you have a large amount of views to scroll through, but don’t want to load them into memory until they’re needed, check out my module. It supports finite and infinite scrolling, and uses a callback to generate each view only when needed.
On BitBucket:
Wiki (instructions and information)
Downloads