Before writing any code
As mentioned earlier in this chapter, Titanium does not provide any means to give a nice curly effect to the pages while swiping our finger across the screen. There are two ways around this:
- Develop the desired effect using JavaScript by playing with canvas, rotations, and animations. Such an approach would require some fairly complex code and there is also the risk that the performance may be poor depending on the use cases.
- Use a piece of software that uses native code to achieve the desired effect, but still allows us to use it with JavaScript, similar to other Titanium components such as
Button
,Label
,View
, and so on. This piece of software is a called aTitanium Native
module.
A native module
When using a framework, there will come a time when you will need more than what it has to offer. This may happen progressively as you use the framework more often. The engineers behind Titanium, keeping this in mind, allowed the developers to extend Titanium using native code of their own.
We won't go over the details of developing a Titanium module (we could devote an entire book to this subject). But essentially, it is a piece of code that adheres to a specific set of standards and conventions with additional metadata. Once compiled and packaged properly, Titanium will be able to recognize the module and interact with it using JavaScript, just as if it was any other component of the framework. Modules act as a bridge between your JavaScript code and the platform underneath. Most of the OS functionalities are exposed through the modules.
Note
Not many people know this, but the entire Titanium framework is based on the same principle. Button, Network connections, and Geolocation are all developed as modules under the hood.
Developing a native module will require a pretty good knowledge of the underneath platform. It also should be developed using a specific programming language in order to interact with the native SDK (for example, Objective C for iOS, or Java for Android). So, it is usually destined for more experienced developers. A module is also tied to the platform it is targeting, meaning that if you want a specific feature on different platforms, you will have to implement it on each target platform.
Where do I get it?
Now that we have a better understanding of what a module is and what it can do for us, we will need to actually retrieve it and get it installed on our development machine. There are many ways to retrieve a native module. Some open source modules can be found online, but it usually implies that we need to build them from source.
Another way to get access to the modules is through Appcelerator Marketplace. It has about 320 modules at the time of writing this book, with one module being added every second day. For our e-book application, we want to retrieve Page Flip Module developed by Appcelerator at the following URL: http://bit.ly/1bykJjd
Once logged into the site with your developer account, simply click on the Download button.
Note
One important thing to note is that once you have downloaded the module using an account, you will have to use that same account when creating your project later on. Failing to do so will generate an error when running the application thereafter. Also, it is important to create your project after the module has been purchased from the marketplace. This can seem to be a hassle, but it is important to keep in mind, since this is how Appcelerator keeps track of it.