Swift API
The types you use to load bundles, show Octapus screens and observe them.
| Module | Platform | Import |
|---|---|---|
OctapusKit | iOS 16+ | import OctapusKit (re-exports OctapusCore) |
OctapusAppKit | macOS 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| Member | Description |
|---|---|
hbc, frame, css | File URLs (frame and css are optional) |
hostProtocol | From the manifest (1 when absent) |
incompatibility: String? | Why this app cannot run the bundle, or nil |
isSupported: Bool | incompatibility == nil |
static supportedHostProtocol | Highest 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] = [])| Member | Description |
|---|---|
launch() | Start. Waits until the view has a width |
stop() | Stop JavaScript and clear the views. Call when the screen is gone for good |
onEvent | OctapusRoot.Event callback |
onFrameCache | FrameCacheEvent callback |
root | The underlying OctapusRoot |
scrollView, content | The scroll view and the view that hosts your page |
OctapusView.Options
| Field | Default | Description |
|---|---|---|
cachesFrames | true | Keep the laid-out first screen on device and draw it on the next launch |
frameCache | OctapusFrameCache() | Where cached first screens are stored (Caches/Octapus/Frames by default) |
timeLimitMs | 0 | Stop a JavaScript call after this many ms (0 = off). Needs -emit-async-break-check |
builtinModules | true | Register 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
| Case | Takes over the screen |
|---|---|
.load | Right after the snapshot is drawn (default) |
.idle | When the main run loop is next idle |
.interaction | On the first input on the snapshot; that input is delivered afterwards |
.never | Only 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.
| Member | Description |
|---|---|
onEvent | Event callback (the views forward it) |
launch(_:props:) | Start a bundle with props for the root component |
hydrate() | Start hydration now, whatever the strategy |
hydration | The strategy |
modules | The 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
| Case | Sent 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
| Field | Meaning |
|---|---|
phase | .idle, .frame (snapshot drawn), .hydrating, .adopted, .remounted (snapshot rejected), .mounted (no snapshot), .failed(String) |
readNs | Reading the snapshot |
drawNs, viewsDrawn, frameRows | Drawing the snapshot: time, views, rows |
jsReadyMs | Launch → your app's first render ready |
engineNs, hermesNs | Creating the runtime; loading the bytecode and rendering |
hydrationDelayMs | Snapshot on screen → takeover requested |
adoptNs, matched, viewsCreatedOnAdopt | Takeover: time, matched rows, views created (expected 0) |
mismatch | Where the first render and the snapshot first differed |
buffered, replayed | Taps held before hydration / delivered after |
frameToInteractiveMs | Snapshot on screen → interactive |