How to Implement Pull to Refresh in BlackBerry 10 CascadesSun 20 January 2013 by Xitij Ritesh Patel
Over the last little bit, I’ve been doing a lot of work on some apps for BlackBerry 10. With January 30th fast approaching, I was coding like a madman to try and meet the deadline, so I can get my hands on some awesome swag.
One of the apps I built uses a UI paradigm called “Pull to Refresh.” If the user is viewing a stream of data, they can pull down on the list and reveal a hidden item that notifies them they can refresh the stream contents by releasing their touch. A number of people have asked me how to implement this.
Again, because of the speed of development that’s possible with BB Tart, I was able to put together a crude, but workable sample demonstrating how to implement this feature. Furthermore, I even integrated it with ADN’s global feed. I simply pulled a couple of libraries from Github and putting the building blocks together. I went from idea to functioning sample in 12 hours, with 6 hours of sleep in between.
As you can see, everything you need is in the blackberry-py-pulltorefresh GitHub repo. The app was built on top of my blackberry-py-bootstrap repo. I’d be more than willing to accept help/pull requests on the project to help improve it for all developers. The file you should look at in particular is PullToRefresh.qml.
You’ll note that I implemented a LayoutUpdateHandler to monitor changes in the item. If the Y-coordinate is equal to exactly 0, then it fires the refreshTriggered() signal. In my testing, this works relatively well since the control will snap to 0 when it is released past the threshold. However, it can sometimes be triggered while the user is still interacting with the control. Therefore, a better way would be to detect if the user is touching the control, and only firing if they’re not.
I hope that helps most of you BlackBerry 10 developers looking to implement this in your app. When I first got this working, I couldn’t stop playing with it! Hopefully this gives you the jumpstart you need. Oh and take a look through the rest of the repository, there’s some good stuff in there including a way to asynchronously load remote images.
Google Chromebook and Ubuntu
I got my Google ARM Chromebook!
I was really excited for this device. I’ve been using a thick, heavy, and relatively underpowered Acer laptop for the last 5 years. I really wanted something thin and light to do my development work on that I could use on the go ...read more
Migrating to Amazon EC2
I’ve been pining over the Google Chromebook lately, as I’ve been wanting to become more mobile with my developer setup. In an effort to make this a reality, I started looking at my options for a VPS.
I currently have two VPSes running, one with prgmr and one ...read more
Why I Like BlackBerry 10 and Why I Don’t Hate iOS/Android
Building a FreeNAS Box
I’ve been having a lot of trouble lately trying to figure out the best solution for backing up my data. Recently, I’ve been accumulating a large number of files, photos, and videos that I’d like to keep safe. Moreover, I’d like this data to be accessible ...read more
Compiling tesseract for BlackBerry 10
I’ve been on a hiatus from the blog for some time, so I figure I’ll write something up that should be useful to a few people.
Recently, I had an idea for an app, and part of it would utilize some OCR capabilities. Some quick Google searching revealed ...read more
Signing up with prgmr
I’ve used several different VPS providers in the past. My first experience was with Slicehost, with whom I was happy with until about 1.5 years ago. I decided that I was fed up with their lack of competitiveness against other providers.
I switched to Linode, which I use ...read more