Skip to Content
Octapus

Swift API

The types you use to load bundles, show Octapus screens and observe them.

ModulePlatformImport
OctapusKitiOS 16+import OctapusKit (re-exports OctapusCore)
OctapusAppKitmacOS 14+import OctapusAppKit and import OctapusCore

Preview API

These names reflect the current API and may still change before a first release.

OctapusBundle

A native bundle produced by oct build.

OctapusBundle(directory: url)                        // reads app.hbc, app.ofrm?, app.css?, manifest.json
OctapusBundle(hbc: hbcURL, frame: ofrmURL, css: cssURL)  // explicit files, no manifest check
MemberDescription
hbc, frame, cssFile URLs (frame and css are optional)
hostProtocolFrom the manifest (1 when absent)
incompatibility: String?Why this app cannot run the bundle, or nil
isSupported: Boolincompatibility == nil
static supportedHostProtocolHighest host protocol this version of Octapus understands

iOS views

OctapusViewController

OctapusViewController(bundle: OctapusBundle, hydration: HydrationStrategy = .load,
                      options: OctapusView.Options = .init(),
                      props: [String: Any] = [:], modules: [OctapusModule] = [])

A view controller with one OctapusView (octapusView) pinned to the safe area. It launches in viewDidLoad and stops the runtime when popped or dismissed.

OctapusSurface (SwiftUI)

OctapusSurface(bundle: OctapusBundle, hydration: HydrationStrategy = .load,
               options: OctapusView.Options = .init(),
               props: [String: Any] = [:], modules: [OctapusModule] = [],
               onEvent: ((OctapusRoot.Event) -> Void)? = nil,
               onFrameCache: ((OctapusView.FrameCacheEvent) -> Void)? = nil)

OctapusView (UIView)

OctapusView(bundle: OctapusBundle, hydration: HydrationStrategy = .load, options: Options = Options(),
            props: [String: Any] = [:], modules: [OctapusModule] = [])
MemberDescription
launch()Start. Waits until the view has a width
stop()Stop JavaScript and clear the views. Call when the screen is gone for good
onEventOctapusRoot.Event callback
onFrameCacheFrameCacheEvent callback
rootThe underlying OctapusRoot
scrollView, contentThe scroll view and the view that hosts your page

OctapusView.Options

FieldDefaultDescription
cachesFramestrueKeep the laid-out first screen on device and draw it on the next launch
frameCacheOctapusFrameCache()Where cached first screens are stored (Caches/Octapus/Frames by default)
timeLimitMs0Stop a JavaScript call after this many ms (0 = off). Needs -emit-async-break-check
builtinModulestrueRegister the built-in Platform, Storage and Haptics modules
storageScope"default"Namespace for the Storage module

OctapusView.FrameCacheEvent: .hit(URL, keyMs:), .miss(keyMs:), .stored(URL, bytes:, encodeMs:), .failed(String).

macOS views

OctapusView (SwiftUI)

OctapusView(bundle: OctapusBundle?, hydration: HydrationStrategy = .load,
            props: [String: Any] = [:], modules: [OctapusModule] = [],
            onCreate: ((OctapusHostView) -> Void)? = nil)

onCreate runs once with the host view, before launch.

OctapusHostView (AppKit)

OctapusHostView(hydration: HydrationStrategy = .load, timeLimitMs: UInt32 = 0,
                modules: [OctapusModule] = [], builtinModules: Bool = true, storageScope: String = "default")
host.launch(bundle, props: [String: Any] = [:])

An NSScrollView that hosts your page. root gives access to the OctapusRoot.

HydrationStrategy

CaseTakes over the screen
.loadRight after the snapshot is drawn (default)
.idleWhen the main run loop is next idle
.interactionOn the first input on the snapshot; that input is delivered afterwards
.neverOnly when you call root.hydrate()
.after(milliseconds:)After a fixed delay

OctapusRoot

The runtime behind every Octapus view: one Hermes instance, its thread and the screen it drives. You reach it through a view's root.

MemberDescription
onEventEvent callback (the views forward it)
launch(_:props:)Start a bundle with props for the root component
hydrate()Start hydration now, whatever the strategy
hydrationThe strategy
modulesThe root's native module registry (register(_:), writeSchema(to:))
send(_ name:, _ payload:)Send an event to JS (host.on(name)); callable from any thread
on(_ name:, _ handler:)Receive host.emit(name) from JS on the main thread; returns a subscription to cancel()

Native modules (OctapusModule, Function, AsyncFunction, Constant, value types) are documented in Native modules.

OctapusRoot.Event

CaseSent when
.metrics(LaunchMetrics)The launch moves to a new phase
.batch(BatchLog)An update from your app was applied
.console([String])Your app logged to the console
.error(String)Something failed (bundle refused, snapshot unreadable, JavaScript error)
.eventRoundTrip(Double)A native control event was applied, in ms

LaunchMetrics

FieldMeaning
phase.idle, .frame (snapshot drawn), .hydrating, .adopted, .remounted (snapshot rejected), .mounted (no snapshot), .failed(String)
readNsReading the snapshot
drawNs, viewsDrawn, frameRowsDrawing the snapshot: time, views, rows
jsReadyMsLaunch → your app's first render ready
engineNs, hermesNsCreating the runtime; loading the bytecode and rendering
hydrationDelayMsSnapshot on screen → takeover requested
adoptNs, matched, viewsCreatedOnAdoptTakeover: time, matched rows, views created (expected 0)
mismatchWhere the first render and the snapshot first differed
buffered, replayedTaps held before hydration / delivered after
frameToInteractiveMsSnapshot on screen → interactive

On this page