Swift API
The types you use to load bundles and show BakeNative screens on iOS and macOS.
| Module | Platform | Import |
|---|---|---|
BakeNativeKit | iOS 16+ | import BakeNativeKit |
BakeNativeAppKit | macOS 14+ | import BakeNativeAppKit |
Both run the Rust core and re-export the shared Apple host layer (BakeNativeBundle, HydrationStrategy, the native module runtime the generated module contracts use). import BakeNativeCore still compiles: it is a compatibility module that re-exports the same layer.
The public API is only what an app calls or implements; native/swift-public-api.txt in the repository lists every public symbol. On both hosts BakeNativeView is the platform view (UIView, NSView) and BakeNativeSurface the SwiftUI view.
Preview API
These names reflect the current API and may still change before a first release.
BakeNativeBundle
A native bundle produced by bake build.
BakeNativeBundle(directory: url) // reads app.hbc, app.baked?, app.css?, manifest.json
BakeNativeBundle(hbc: hbcURL, frame: frameURL, 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 BakeNative understands |
static prewarm(_:) -> BakeNativePrewarmCancel | Prepare a screen before it opens (iOS guide) |
Native modules
Every view takes its native modules as one registry, modules:. The generated
BakeNativeBundleModules.root(...) returns it: the modules the generated code creates (first-party
and registry modules, a fresh instance per root) plus the app's own modules for that screen, one
parameter each. A module the bundles call unguarded is a required parameter.
BakeNativeView(bundle: bundle, modules: BakeNativeBundleModules.root(orderScreen: OrderScreenModule(screen: self)))Under the registry, every view adds the built-ins Platform, Storage and Haptics. See
Native modules for specs, BakeNativeModuleRegistry and
BakeNativeModuleError.
iOS views
BakeNativeViewController
BakeNativeViewController(bundle: BakeNativeBundle, hydration: HydrationStrategy = .load,
options: BakeNativeView.Options = .init(), props: [String: Any] = [:],
modules: BakeNativeModuleRegistry? = nil, views: [any BakeNativeNativeViewType.Type] = [])A view controller with one BakeNativeView (bakeNativeView) pinned to the safe area. It applies the page's header and tab bar, launches in viewDidLoad and stops the runtime when popped or dismissed.
BakeNativeView (UIView)
BakeNativeView(bundle: BakeNativeBundle, hydration: HydrationStrategy = .load, options: Options = Options(),
props: [String: Any] = [:], modules: BakeNativeModuleRegistry? = nil,
views: [any BakeNativeNativeViewType.Type] = [])| 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 |
reload() | Launch the same bundle and props again |
sendEvent(_:json:) | A host event for the page, received with host.on(name); the payload is JSON text |
onContentHeight, contentHeight | The page's height (with fitsContent) |
onCanvasBackground, canvasBackground | The page's background color |
scrollView | The scroll view that hosts your page |
BakeNativeView.Options
| Field | Default | Description |
|---|---|---|
edgeToEdge | false | The page fills the whole view, under the status bar and the home indicator, and reads the insets from env(safe-area-inset-*) |
fitsContent | false | No scrolling of its own: the view is as tall as its page (a section of a native screen) |
BakeNativeSurface (SwiftUI)
BakeNativeSurface(bundle: BakeNativeBundle, hydration: HydrationStrategy = .load,
options: BakeNativeView.Options = .init(), props: [String: Any] = [:],
modules: BakeNativeModuleRegistry? = nil, views: [any BakeNativeNativeViewType.Type] = [],
onCreate: ((BakeNativeView) -> Void)? = nil)onCreate runs once with the BakeNativeView, before launch: keep it to send host events.
macOS views
BakeNativeView (AppKit)
BakeNativeView(hydration: HydrationStrategy = .load, modules: BakeNativeModuleRegistry? = nil,
views: [any BakeNativeNativeViewType.Type] = [])
host.launch(bundle, props: [String: Any] = [:])An NSScrollView that hosts your page. stop(), reload() and sendEvent(_:json:) work as on iOS.
BakeNativeSurface (SwiftUI)
BakeNativeSurface(bundle: BakeNativeBundle?, hydration: HydrationStrategy = .load,
props: [String: Any] = [:], modules: BakeNativeModuleRegistry? = nil,
views: [any BakeNativeNativeViewType.Type] = [], onCreate: ((BakeNativeView) -> Void)? = nil)onCreate runs once with the BakeNativeView, before launch.
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 |
.after(milliseconds:) | After a fixed delay |
.never | Not on its own (measurement hosts start it themselves) |
JS → native goes through a native module of the screen; native → JS is a host event (sendEvent(_:json:)).