Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Demystifying Module Development            Jeff English
Jeff English•  30+ years of software   development•  Cross-platform SDKs, operating   system development, games,   mobile ...
Dilbert, September 8, 1992                             Copyright © 1992, Scott Adams
What Are Modules? Extensions to the core Titanium platform Titanium itself is written as a collection of modules Written i...
Module Features    Life Cycle Events                     Method Parameters    Module loading, proxy loading, view   Type v...
Basic Module Development (iOS) Create a module titanium create --platform=iphone --type=module --dir=. --name=calc --id=co...
Basic Module Development (Android) Create a module titanium create --platform=android --type=module --dir=. --name=calc --...
Basic Module Architecture               require               Module                             (TiModule / KrollModule) ...
JavaScript / Module Interactionsvar m = require(‘…’);!m.fooInt = 42;!                 fooInt propertym.fooString = ‘Hello ...
JavaScript / Proxy Interactionsvar m = require(‘…’);!var p = m.createBar(…);!        createBar methodp.fooInt = 42;!      ...
JavaScript / ViewProxy Interactionsvar m = require(‘…’);!var p = m.createView(…);!       createView methodp.fooInt = 42;! ...
Proxy Properties Properties can be set in the constructor Setter is automatically called Properties can be set directly af...
Proxy Methods Module methods can be exposed to JS iOS – Signature determines availability (id)methodName:(id)args (void)me...
Method Parameters Parameters can be passed from JS to your methods iOS All parameters are passed in an NSArray object Use ...
Callbacks and Events Methods exist for notifying JS of module events Recommended to use events rather than callbacks when ...
Miscellaneous Assets iOS Build Options titanium.xcconfig Android Build Options timodule.xml Manifest Documentation
Miscellaneous (cont) LICENSE Example
Module DevelopmentGuide ReferenceModuleLife Cycle eventsKroll usageCut-and-paste example code
Module LoadModule Unload
Proxy CreateProxy Destroy
ViewProxy Create
ViewProxy Create
Parameters Demo
Module Development Resources Module Development Guide for iOS Module Development Guide for Android Open source modules ava...
Questions
Upcoming SlideShare
Loading in …5
×

Jeff English: Demystifying Module Development - How to Extend Titanium

6,932 views

Published on

The ability to extend your application with custom functionality, whether an external library or your own custom library, opens up numerous possibilities for what you can create. Titanium enables this with what are called 'modules'. Modules provide a bridge between your Javascript application code and your native library code. Getting started writing your own modules can seem confusing, but once your understand the architecture of a module and how it integrates with the Titanium platform you will be able to add your own functionality in short order.

In this session you will learn:

How to create your module project
How to call methods and pass parameters to your module from your Javascript code
How to make callbacks into your Javascript code from your module

This session is for anyone interested in understanding module development and how to get started.

Jeff English is the Modules Development Manager at Appcelerator. Jeff and his team designed and developed many of the Appcelerator modules found in the Marketplace.

Published in: Technology
  • Be the first to comment

Jeff English: Demystifying Module Development - How to Extend Titanium

  1. 1. Demystifying Module Development Jeff English
  2. 2. Jeff English•  30+ years of software development•  Cross-platform SDKs, operating system development, games, mobile encryption management, et. al.•  50+ consumer, commercial, and enterprise applications•  “Real-World Programming for OS/2”Engineering Manager, Modulesjenglish@appcelerator.com
  3. 3. Dilbert, September 8, 1992 Copyright © 1992, Scott Adams
  4. 4. What Are Modules? Extensions to the core Titanium platform Titanium itself is written as a collection of modules Written in native code iOS (Objective-C), Android(Java), JavaScript (JavaScript) Provide a bridge between JS and native code Methods, Properties, Notifications, Data Types, Assets
  5. 5. Module Features Life Cycle Events Method Parameters Module loading, proxy loading, view Type validation, type conversion, proxy loading pass-by-value / reference Properties Callbacks & Events Types, getters, settings, property Event registration, asynchronous change notifications notifications, synchronous callbacks Methods Miscellaneous Method signatures / annotations Assets, documentation, example, license, manifest, packaging
  6. 6. Basic Module Development (iOS) Create a module titanium create --platform=iphone --type=module --dir=. --name=calc --id=com.companyname.calc Build a module ./build.py Test a module titanium run Deploy a module Copy module zip file into system folder or application folder
  7. 7. Basic Module Development (Android) Create a module titanium create --platform=android --type=module --dir=. --name=calc --id=org.companyname.calc --android=/usr/android-sdk Build a module ant Test a module ant run Deploy a module Copy module zip file into system folder or application folder
  8. 8. Basic Module Architecture require Module (TiModule / KrollModule) create Proxy (TiProxy / KrollProxy) JavaScript createView View Proxy (TiViewProxy) View (TiUIView)
  9. 9. JavaScript / Module Interactionsvar m = require(‘…’);!m.fooInt = 42;! fooInt propertym.fooString = ‘Hello World’;!Ti.API.info(m.fooString);! fooString propertym.foo({ X: 5, Y: 10 });! foo methodm.addEventListener(! ‘myEvent’,! myHandler);!function myHandler(e) {! Signal Event Ti.API.info(‘myEvent’);!}!
  10. 10. JavaScript / Proxy Interactionsvar m = require(‘…’);!var p = m.createBar(…);! createBar methodp.fooInt = 42;! fooInt propertyp.fooString = ‘Hello World’;!Ti.API.info(m.fooString);! fooString propertyp.foo({ X: 5, Y: 10 });! foo methodp.addEventListener(! ‘myEvent’,! myHandler);!function myHandler(e) {! Signal Event Ti.API.info(‘myEvent’);!}!
  11. 11. JavaScript / ViewProxy Interactionsvar m = require(‘…’);!var p = m.createView(…);! createView methodp.fooInt = 42;! fooInt propertyp.fooString = ‘Hello World’;!Ti.API.info(m.fooString);! fooString propertyp.foo({ X: 5, Y: 10 });! foo methodp.addEventListener(! ‘myEvent’,! myHandler);!function myHandler(e) {! Signal Event Ti.API.info(‘myEvent);!}!
  12. 12. Proxy Properties Properties can be set in the constructor Setter is automatically called Properties can be set directly after proxy creation Many primitive values are automatically converted iOS Properties Getters and Setters can be defined by using @property or property signatures Android Properties Getters and Setters can be defined by using @Kroll.getProperty and @Kroll.setProperty annotations
  13. 13. Proxy Methods Module methods can be exposed to JS iOS – Signature determines availability (id)methodName:(id)args (void)methodName:(id)args Android – Annotations determine availability @KrollMethod Use KrollInvocation if your method requires the current activity
  14. 14. Method Parameters Parameters can be passed from JS to your methods iOS All parameters are passed in an NSArray object Use TiUtils methods to get correct datatype Android All parameters are passed as defined – KrollDict recommended Use validation methods (e.g. TiConvert) to get correct datatype
  15. 15. Callbacks and Events Methods exist for notifying JS of module events Recommended to use events rather than callbacks when possible iOS fireEvent and _fireEventToListener call Android fireEvent and fireSingleEvent callAsync and callSync
  16. 16. Miscellaneous Assets iOS Build Options titanium.xcconfig Android Build Options timodule.xml Manifest Documentation
  17. 17. Miscellaneous (cont) LICENSE Example
  18. 18. Module DevelopmentGuide ReferenceModuleLife Cycle eventsKroll usageCut-and-paste example code
  19. 19. Module LoadModule Unload
  20. 20. Proxy CreateProxy Destroy
  21. 21. ViewProxy Create
  22. 22. ViewProxy Create
  23. 23. Parameters Demo
  24. 24. Module Development Resources Module Development Guide for iOS Module Development Guide for Android Open source modules available on GitHub https://github.com/appcelerator/titanium_modules Module Development Guide reference module moddevguide
  25. 25. Questions

×