Jeff English: Demystifying Module Development - How to Extend Titanium
-
Upload
appcelerator-inc -
Category
Technology
-
view
5.876 -
download
6
description
Transcript of Jeff English: Demystifying Module Development - How to Extend Titanium
Demystifying Module Development
Jeff English
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, Modules [email protected]
Copyright © 1992, Scott Adams
Dilbert, September 8, 1992
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
Life Cycle Events Module loading, proxy loading, view proxy loading
Method Parameters Type validation, type conversion, pass-by-value / reference
Properties Types, getters, settings, property change notifications
Callbacks & Events Event registration, asynchronous notifications, synchronous callbacks
Methods Method signatures / annotations
Miscellaneous Assets, documentation, example, license, manifest, packaging
Module Features
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
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
Basic Module Architecture
JavaScript
Module (TiModule / KrollModule)
Proxy (TiProxy / KrollProxy)
View Proxy (TiViewProxy)
require
create
createView
View (TiUIView)
JavaScript / Module Interactions
var m = require(‘…’);!
m.fooInt = 42;!
m.fooString = ‘Hello World’;!Ti.API.info(m.fooString);!
m.foo({ X: 5, Y: 10 });!
m.addEventListener(! ‘myEvent’,! myHandler);!function myHandler(e) {! Ti.API.info(‘myEvent’);!}!
fooInt property
fooString property
foo method
Signal Event
JavaScript / Proxy Interactions
var m = require(‘…’);!
p.fooInt = 42;!
p.fooString = ‘Hello World’;!Ti.API.info(m.fooString);!
p.foo({ X: 5, Y: 10 });!
p.addEventListener(! ‘myEvent’,! myHandler);!function myHandler(e) {! Ti.API.info(‘myEvent’);!}!
fooInt property
fooString property
foo method
Signal Event
var p = m.createBar(…);! createBar method
JavaScript / ViewProxy Interactions
var m = require(‘…’);!
p.fooInt = 42;!
p.fooString = ‘Hello World’;!Ti.API.info(m.fooString);!
p.foo({ X: 5, Y: 10 });!
p.addEventListener(! ‘myEvent’,! myHandler);!function myHandler(e) {! Ti.API.info(‘myEvent);!}!
fooInt property
fooString property
foo method
Signal Event
var p = m.createView(…);! createView method
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
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
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
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
Miscellaneous
Assets
iOS Build Options titanium.xcconfig
Android Build Options timodule.xml
Manifest
Documentation
Miscellaneous (cont)
LICENSE
Example
Module Development Guide Reference Module
Life Cycle events
Kroll usage
Cut-and-paste example code
Module Load
Module Unload
Proxy Create
Proxy Destroy
ViewProxy Create
ViewProxy Create
Parameters Demo
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
Questions