Skip to main content

Crate day_piece_swiftui

Crate day_piece_swiftui 

Source
Expand description

day-piece-swiftui: custom SwiftUI views inside a Day app, on macos-appkit + ios-uikit only.

The native half resolves a provider class named @objc(DayView_<name>) (dots in name become underscores), asks it for a SwiftUI body, and hosts that body in an NSHostingView (macOS) or a UIHostingController’s view (iOS), returned to Day as an ordinary native handle, framed and snapshotted like any built-in. Two ways in (docs/swiftui.md):

  • Generated bindings (the usual way): point [package.metadata.day.ios/macos] swift-packages at a local SwiftPM package; day-build scans its public View structs and emits crate::swiftui::MyView(param1, param2) constructors, while day build emits the matching provider glue. Apps then never touch this crate’s API beyond the Cargo dependency.
  • The provider escape hatch: subclass DaySwiftUIProvider in Swift, name it @objc(DayView_mything), and call swiftui("mything"), for views that need wiring the binding subset can’t express.

Params ride as a JSON string. A reactive .params(...) re-invokes the provider’s body on every change and swaps the hosting view’s rootView; SwiftUI diffing preserves @State as long as the provider returns the same underlying view type each call.

It’s a growing leaf, so constrain it with .frame(w, h) when it shouldn’t fill the pane.

Modules§

json
Minimal JSON rendering for the params channel, enough for the generated bindings (flat objects of strings/numbers/bools) without a serde dependency. Hand-written params can use it too, or bring their own serializer.

Structs§

SwiftUi
A hosted SwiftUI view. Bind its data reactively with .params(...); keep its @State across unmount/remount with .state_key(...).
SwiftUiProps
Full props (realize). name picks the provider class; params seeds the JSON the provider’s body first receives (None when SwiftUi::params was never called).

Enums§

Reactive
A parameter that is either a constant or a reactive source. get() is a tracked read, so any Reactive used inside a canvas draw closure makes that shape re-record when the source changes.
SwiftUiPatch
Sparse reconcile patch: only params changes after build (name is fixed).

Constants§

KIND

Traits§

IntoReactive
Disjoint-marker conversion (like IntoText): accepts T, Signal<T>, or Fn() -> T.
SwiftUiBuilder
Builder methods of SwiftUi, reachable through a Decorated (docs/api-style.md “Typed builders and erasure”): generic modifiers and typed ones chain in any order.

Functions§

support
Whether this build hosts SwiftUI natively: Native on macos-appkit and ios-uikit, else Unsupported. The gate app code should branch on, never a backend-feature cfg.
swiftui
swiftui("Module.View"): host the SwiftUI view exported as @objc(DayView_Module_View).