-
Notifications
You must be signed in to change notification settings - Fork 5
JavaScript API Reference
All API methods accept 2 parameters (options, callback)
The options parameter is an object will contain attributes that are specific to the particular API method.
The callback parameter is a function which will always accept 2 parameters function(error, response).
If an error occurs, the response parameter will be undefined and the error parameter will contain an object with the code and message attributes. Both of these attributes will be specific to the particular method and will be documented in further detail for each mehthod.
With a success condition, the response parameter will be the response from the particular API method (and documented in further detail for each method) and the error parameter will be undefined.
All parameters are required unless they are documented as optional.
An optional callback to invoke after the web view has finished loading and the bridge APIs are ready for use.
example
// wait for the bridge to be ready
function bridgeReady(nativeBridge) {
// web view is loaded and bridge is ready for use
}
if (window.NativeBridge === undefined) {
window.nativeBridgeReady = function(error, nativeBridge) {
bridgeReady(nativeBridge);
}
} else {
bridgeReady(nativeBridge);
}
The web application must explicitly call the animateForward/animateBackward methods whenever the web app chooses to animate browser history changes using native navigation. The native navigation stack will only react to animateForward/animateBackward bridge calls, it will not animate transitions for link clicks (ex: <a href="/">Click Me</a>), form submits, or any other special requests.
Configure the current page state.
options
- title: (string) The title of the page.
example
NativeBridge.updatePageState({title: "Home"});Displays a modal dialog with a title, message and buttons
options
- title: (string) the alert dialog title
- message: (string) the alert dialog main content
- actions: (array) an array of hash values
{id, label}representing the dialog buttons- id: (string) button id for the callback
- label: (string) the button label
response
function(id) executed when any button is clicked.
- id: (string) the id of the button that was clicked
example
NativeBridge.dialog({
title: 'This is the alert dialog title',
message: 'This is the alert dialog message',
actions: [{
id: 'ok',
label: 'Ok'
}, {
id: 'cancel',
label: 'Cancel'
}]
}, function(error, id) {
// there are no dialog specific errors
if (id === 'ok') {
// Ok button was clicked
} else if (id === 'cancel') {
// Cancel button was clicked
}
});Initiates the native share functionality
options
- message: (string) the share message
- url: (string, optional) the url to share
response
boolean value indicating whether the user completed the sharing
FIXME: should we/can we provide an identifier for the application that the messages was shared to?
example
NativeBridge.share({
message: 'This is the message to be shared',
url: 'This is the url to be shared'
}, function(error, shared) {
if (shared) {
// the share was completed
} else {
// the share was not completed
}
});Trigger forward native navigation animation. No other calls to animateForward() or animateBackward() can be made in the duration of the animation transition.
there is time for the pop animation to complete and you will not be able to pop anything while it is still in transition
response
This is a notification only. The response will undefined.
example
NativeBridge.navigation.animateForward();Trigger backward native navigation animation. No other calls to animateForward() or animateBackward() can be made in the duration of the animation transition.
response
This is a notification only. The response will undefined.
example
NativeBridge.navigation.animateBackward();