Skip to Content
Octapus

Quick start

Build a small app for web, macOS and iOS, and see its first screen appear before JavaScript runs.

This walks through one app from source to a native screen. It assumes you finished Installation.

Write the app

Create a project with one component. oct looks for src/App.tsrx and uses its App export (or the default export, or the first exported function).

src/App.tsrx
import { useState } from 'octane';

export function App() @{
  const [count, setCount] = useState(0);

  <main class="page">
    <h1>Hello from Octapus</h1>
    <button onClick={() => setCount(count + 1)}>{'Count: ' + count}</button>
  </main>
}
src/styles.css
.page {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  font-family: system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  body { background: #16181d; color: #f4eee8; }
}

src/styles.css is optional. When present it applies on every target, like a global stylesheet on the web.

Build it

pnpm oct build --target web,ios,mac --bake
dist/
  web/        index.html + assets   open it in a browser
  ios/        app.hbc  app.css  app.ofrm  manifest.json
  mac/        app.hbc  app.css  app.ofrm  manifest.json

Each native folder is a bundle: your app as Hermes bytecode (app.hbc), its global CSS, the first-screen snapshot (app.ofrm, written because of --bake), and a manifest that ties them together. Copy the folder into your app as is.

Show it in a macOS app

Add dist/mac to your app target as a folder reference (so it keeps its name inside the app bundle), then:

import OctapusAppKit
import OctapusCore
import SwiftUI

struct ContentView: View {
  let bundle = OctapusBundle(directory: Bundle.main.url(forResource: "mac", withExtension: nil)!)

  var body: some View {
    OctapusView(bundle: bundle)
      .frame(minWidth: 480, minHeight: 360)
  }
}

Show it in an iOS app

Add dist/ios the same way and push an Octapus screen from anywhere in your app:

import OctapusKit

let url = Bundle.main.url(forResource: "ios", withExtension: nil)!
let screen = OctapusViewController(bundle: OctapusBundle(directory: url))
navigationController?.pushViewController(screen, animated: true)

In SwiftUI, use OctapusSurface(bundle:) instead. See Embed in an iOS app for the other options.

Check the launch

Each Octapus view reports what happened at launch. Log it to see the snapshot at work:

func logLaunch(_ event: OctapusRoot.Event) {
  if case .metrics(let m) = event, m.phase == .adopted {
    print("interactive after \(m.frameToInteractiveMs) ms, \(m.viewsCreatedOnAdopt) views created")
  }
}

// iOS
screen.octapusView.onEvent = logLaunch

// macOS
OctapusView(bundle: bundle) { host in host.root.onEvent = logLaunch }

adopted with 0 views created means the first screen came from the snapshot and Hermes took it over without rebuilding anything. Tap the button: from here on it is your Octane app, running natively.

Next

On this page