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-packagesat a local SwiftPM package; day-build scans its publicViewstructs and emitscrate::swiftui::MyView(param1, param2)constructors, whileday buildemits the matching provider glue. Apps then never touch this crate’s API beyond the Cargo dependency. - The provider escape hatch: subclass
DaySwiftUIProviderin Swift, name it@objc(DayView_mything), and callswiftui("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@Stateacross unmount/remount with.state_key(...). - Swift
UiProps - Full props (realize).
namepicks the provider class;paramsseeds the JSON the provider’s body first receives (NonewhenSwiftUi::paramswas never called).
Enums§
- Reactive
- A parameter that is either a constant or a reactive source.
get()is a tracked read, so anyReactiveused inside a canvas draw closure makes that shape re-record when the source changes. - Swift
UiPatch - Sparse reconcile patch: only
paramschanges after build (nameis fixed).
Constants§
Traits§
- Into
Reactive - Disjoint-marker conversion (like
IntoText): acceptsT,Signal<T>, orFn() -> T. - Swift
UiBuilder - Builder methods of
SwiftUi, reachable through aDecorated(docs/api-style.md “Typed builders and erasure”): generic modifiers and typed ones chain in any order.