The document discusses Titanium Native Modules, including:
1. It provides an overview of what Titanium modules look like and their key components, including TiModule, TiProxy, and TiUIView.
2. It explains the important parts of implementing a TiModule, including using annotations and extending the KrollModule class.
3. It covers implementing methods and properties in a module using annotations and converting between native and JavaScript types.
4. It discusses creating a TiProxy by extending KrollProxy and implementing the lifecycle methods, as well as creating the associated TiUIView.
13. @Kroll.method
public void demoMethodNoReturn()
public int demoMethodNumberInt(Object[] args)
public float demoMethodNumberFloat(Object[] args)
public String demoMethodString(Object[] args)
public HashMap demoMethodDictionary(Object args)
public Date demoMethodDate(HashMap hm)
public Object[] demoMethodArray(Object[] args)
15. Methods things to consider
Most native arguments are converted, ie strings
More complex arguments are converted to NSDictionary
BOOL return results much be converted to numbers
NUMBOOL(NO)
20. TiModule the important parts
@Kroll.module(name="TiLight", id="ti.light")
public class TiLightModule extends KrollModule
{
..
public TiLightModule()
{
super();
}
}
Decorate module so Kroll
knows what to do
Extend
KrollModule
21. TiModule Example
@Kroll.module(name="Tilight", id="ti.light")
public class TilightModule extends KrollModule
{
public TilightModule()
{
super();
}
@Kroll.method
public void toggle()
{
if (isLighOn) {
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
isLighOn = false;
} else {
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
isLighOn = true;
}
}
}
22. TiModule the important parts
#import "TiModule.h"
@interface TiLightModule : TiModule {
}
@end
Import TiModule.h
Implement the
TiModule interface
26. TiProxy the important parts
@Kroll.proxy(creatableInModule = BasicgeoModule.class)
public class GeocoderProxy extends KrollProxy {
{
..
public GeocoderProxy()
{
super();
}
}
Decorate so Kroll
knows what to do
Extend
KrollProxy
27. TiProxy Life Cycle
TiProxy Life Cycle overrideable elements
public void handleCreationDict(KrollDict options)
public void handleCreationArgs(KrollModule
createdInModule, Object[] args)
* Javas native constructor and other life cycle
elements also apply
28. TiProxy Example
@Kroll.proxy(creatableInModule = BasicgeoModule.class)
public class GeocoderProxy extends KrollProxy {
public GeocoderProxy() {
super();
}
@Kroll.method
public boolean isSupported(){
return CommonHelpers.reverseGeoSupported();
}
}
29. TiProxy the important parts
#import "TiProxy.h"
@interface BencodingBasicgeoGeocoderProxy:
TiProxy{
}
@end
Import TiProxy.h
Implement the
TiProxy interface
34. TiUIView + TiViewProxy Relationship
TiUIView
Native object,
ie UIView
TiViewProxy
Model / Controller for the
paired TiUIView
35. TiViewProxy the important parts
Kroll.proxy(creatableInModule = TisqModule.class)
public class ViewProxy extends TiViewProxy {
{
..
public ViewProxy ()
{
super();
}
@Override
public TiUIView createView(Activity activity)
{
..
}
}
Decorate
Extend
TiViewProxy
Create the TiIUView
36. TiUIView the important parts
public class View extends TiUIView
{
..
public View(TiViewProxy proxy)
{
super(proxy);
..
setNativeView(calendar);
}
}
Extend TiUIView
TiViewProxy passed
to constructor
Set as native view
37. Life Cycle
TiUIView
public void processProperties(KrollDict props)
public void propertyChanged(String key, Object oldValue,
Object newValue, KrollProxy proxy)
TiViewProxy
public TiUIView createView(Activity activity)
public void handleCreationDict(KrollDict options)
38. TiViewProxy Example
@Kroll.proxy(creatableInModule = TisqModule.class)
public class ViewProxy extends TiViewProxy {
public ViewProxy() {
super();
}
@Kroll.getProperty()
public Date getValue(){
ti.sq.View demoView = (ti.sq.View)view;
return demoView.getValue();
}
}
39. TiUiView Example
public class View extends TiUIView{
..
public Date getValue(){
CalendarPickerView square = (CalendarPickerView)getNativeView();
return square.getSelectedDate();
}
public void setValue(HashMap hm){
Date newValue = convertHMtoDate(hm);
CalendarPickerView square = (CalendarPickerView)getNativeView();
square.selectDate(newValue);
}
..
}
40. TiViewProxy the important parts
#import " TiViewProxy.h "
@interface TiSqViewProxy : TiViewProxy {
..
}
@end
Import
TiViewProxy.h
Implement the
TiViewProxy interface
41. TiUIView the important parts
#import "TiUIView.h"
@interface TiSqView :
TiUIView<TSQCalendarViewDelegate>{
..
}
@end
Import TiUIView.h
Implement the
TiUIView interface