Kirin is a cross-platform toolkit for building mobile apps that allows writing UI code in native languages but business logic in JavaScript. It provides device APIs, a Node.js-like environment, and tools to help native and JavaScript developers work together, including an interface description language to define protocols between native and JavaScript code for type-safe calling between the two. Kirin aims to combine the best of native development with the productivity of JavaScript.
12. Titanium
• Designers won’t like:
• UI APIs are always playing catchup
• Trust Titanium to make the right
choices for platform specificity
• Users won’t like:
• JS engine per app
@jhugman
13. Kirin
• Native SDKs. It may be hard to learn.
• Very lightweight
• The whole SDK is there, all the time.
• Use existing JS Engine.
@jhugman
15. Architecture of
Participation
• “the nature of systems
that are designed for
user contribution”
• Tim O’Reilly, 2004
@jhugman
16. Design Principles
• Provide a node.js like environment
• Bind native objects to Javascript
• Help teams work together
• Get out of your way
@jhugman
17. Design Principles
• A node.js like environment
• Bind native objects to Javascript
• Help teams work together
• Get out of your way
@jhugman
18. Common JS modules
• Arrange your code into files
• Each “module” has its own variable
scope
• require() and exports link
modules together
@jhugman
19. Common JS/Modules
In lib/greeter.js
exports.greet = function (person) {
console.log(“Hello ” + person);
};
In lib/entry.js
var greeter = require(“./greeter”);
greeter.greet(“World”); // prints Hello World to console
@jhugman
20. npm:
node.js package manager
• Distributes your library
• Manages your dependencies
• 10,000+ packages available
@jhugman
27. A Typical Kirin App
Native screen
Javascript
screen module
Controller
Model Your app
Device API
Device Access
@jhugman
28. Not just for screens
Custom UI
Screen UI Fragment
component
Javascript Javascript Javascript
App Delegate Service
Javascript Javascript
Javascript API Javascript API
Third Party API +
Device API
UI
@jhugman
29. Consider this JS:
// called from native screen.
exports.importantButtonClicked = function (value) {}
@jhugman
30. Calling Javascript. Part I
public void onUiButtonClick() {
mKirinHelper.jsMethod("importantButtonClicked", 42);
}
- (IBAction) onUiButtonClick: (id) sender {
[self.kirinHelper
jsMethod: @“importantButtonClicked”
withArgs: [NSNumber numberWithInt:42]
];
}
@jhugman
33. Lifecycles in Javascript
var theScreen;
module.exports = {
onLoad: function (ui) {
theScreen = ui;
},
onUnload: function () {
theScreen = null;
},
// applicable called at viewWillAppear
onResume: function () {},
// called by viewWillDisappear
onPause: function () {},
};
@jhugman
34. Lifecycles with objects
function MyScreenModule () {
this.screen = null;
}
module.exports = MyScreenModule;
MyScreenModule.prototype.onLoad = function (ui) {
this.screen = ui;
};
MyScreenModule.prototype.onUnload = function () {
this.screen = null;
};
// applicable called at viewWillAppear
MyScreenModule.prototype.onResume = function () {};
// called by viewWillDisappear
MyScreenModule.prototype. onPause = function () {};
@jhugman
35. Android Lifecycles
public class MyScreenActivity extends KirinActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_screen);
bindScreen("MyScreenModule");
}
}
@jhugman
38. Extensions
• Device access e.g.
• app-preferences
• dev-networking-alpha
• app-databases-alpha
• May include a UI e.g.:
• Twitter, Facebook, Address Book
@jhugman
39. Extension access
• Exposed only to Javascript
• Can be written in JS, Native or a
combination of both
• May have a full-screen or popover UI
var prefs = require(“app-preferences”),
url = prefs.get(“imageServerUrl”);
// applicable called at viewWillAppear
prefs.put(“lastSuccessfulPoll”, Date.now());
• theScreen
prefs.commit();
@jhugman
41. Transparent threading
• You don’t have to know this:
• Extensions run in a thread pool
• JS engine runs in its own thread
• Responsive UI Thread.
@jhugman
42. Design Principles
• A node.js like environment
• Bind native objects to Javascript
• Help teams work together
• Get out of your way
@jhugman
43. Conway’s Law
• “...organizations which design
systems ... are constrained to produce
designs which are copies of the
communication structures of these
organizations.”
• Melvin Conway 1968
@jhugman
44. Native devs value:
• compilers doing work for them
• IDEs doing work for them
• build tools doing work for them
@jhugman
45. Javascript devs value:
• Rapid prototyping and development
• Expressive language constructs
• Garbage collection
@jhugman
50. Calling Native. Part II
In MyScreenModule.js
var theScreen;
function updateUi (data) {
theScreen.displayDataAndEnableUi(data, true);
}
In MyScreenViewController.h
- (void) displayData: (id<IMyScreenRequest>) data
andEnableUi: (BOOL) flag;
In MyScreenActivity.java
public void displayDataAndEnableUi(IMyScreenRequest data,
boolean flag);
@jhugman
66. Summary!
• Native apps with node.js goodness
• JS apps with Native UI
• Tools to design APIs between them
• Tools to design APIs for device
access
@jhugman
67. Things we’ve thought of
to do next
• Building out extensions
• Other platforms: Chrome, WP7
• More IDL, docs
@jhugman
- Hard to finish, to a high quality (webkit bugs, fragmentation)\n - UI isn't good enough yet: only imitating native, not performant.\n - UI tends towards one-size-fits all, not platform specific.\n
+ Easy to start. You don't even need CSS or DOM. \n
Catchup: so difficult to style. Your designer won't like this.\n