Built In Commands

Clay Allsopp edited this page Jul 20, 2013 · 2 revisions

HybridKit ships with a few helpful built-in commands. These are enabled by default; you can easily remove the HYDefaultCommandHandlerPack with HYWebViewController#unregisterCommandHandler.

Commands

alert

Displays a native alert (i.e. UIAlertView).

Options:

  • title - String
  • message - String
  • cancel_button_title - String - OPTIONAL
open_url

Opens a URL using the system's behavior (UIApplication#openURL)

Options:

  • url - String
set_url

Sets the current HybridKit controller's URL, without a loading animation (such as if you want to set it to a http://myroot.com/#!javascriptPath URL.

Options:

  • url - String
set_url_refresh

Sets the current HybridKit controller's URL, using a loading animation.

Options:

  • url - String
set_title

Sets the current HybridKit controller's title, which will be visible in the navigation bar.

Options:

  • title - String
set_scroll_enabled

Enables or disables scrolling in the web view.

Options:

  • enabled - Boolean
set_background_color

Sets the background color of the controller, which is visible when the web view scrolls past the limits.

Options:

  • color - String. Can be a hex value like #ff00ff or a reasonable color name like red
deceleration_rate

Sets the deceleration rate of the web view scroll.

Options:

  • deceleration_rate - String, either normal or fast.
trigger_event

Triggers a state-machine event on the web controller, which will change the UI accordingly.

Options:

  • event - String, either start_load (to start the loading animation), load_error (to hide the web view), or finish_load (to show the web view).
javascript

Executes JavaScript.

Options:

  • javascript - String, a JavaScript payload to execute on the same page.

Callbacks

In each command, you can pass an optional callback_javascript option, which is a JavaScript String to be executed after the command has run (whether it succeeded or not)

Ex:

HybridKit.runCommand("set_title", {
  title: "Loading",
  callback_javascript: "window.myFunction()"
});
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.