Cornwall provides a bridge between Titanium WebViews and the Titanium javascript environment.
One application can be to use a webview centric design while exposing the full native Titanium API (much like competing cross-platform frameworks).
In general however it simply provides a more powerful way of intergrating Titanium with WebViews you may use in your app.
Watch the following demo video.
(Initial inspiration was really from here).
Have a look at the included app.js
and index.html
files for
examples. The Cornwall files are in the lib
directory.
In your html file included the Cornwall.js
file as follows:
<script src="lib/Cornwall.js"></script>
Require the CornwallWebView
CommonJS modules and use it as you would
normally do with a Titanium WebView. For example:
var web = new (require("/lib/CornwallWebView"))({
url: "index.html"
});
The following additional boolean property
loadFromContextUrl
can be set to true
if you want to load Cornwall
code from webpages. (See below.)
Also the additional cleanup
method should be called prior to removing
a CornwallWebView or closing a window containing it.
To execute Titanium Code from your webview use the Cornwall.execute
command, e.g.:
Cornwall.execute(function() {
Titanium.Contacts.showContacts({});
});
If you want to return values back to the webview, wrap a function in
your webview with a Cornwall.callback
, for example:
var web_popup = function(a) {
alert("Returned 'a' from Native: " + a.a);
};
Cornwall.execute(function() {
Cornwall.callback(web_popup)({a: "A"});
});
Note that the javascript code that is execute "over the bridge" is evaluated in that context. If you want to pass variables across the bridge follow this example:
var start = new Date();
var text = 'Hello World';
Cornwall.execute(function(start, text) {
alert("Started: " + start + "\Text: " + text);
},start, text);
Currently this feature is iOS only.
If you want to see how to use Cornwall in a webpage look at the example
in the example
directory. Fire up the static webserver enter node server.js
then go to http://[your-ip-address]:8888
in Safari from your
iPhone.
Any cornwall://
links from your browser will be
launched in Cornwall to give you the ability to execute native code
from the web.
It is where Titanium is/was found. To do anything useful you need to get to where Titanium is found.