pub struct ComposedView {
pub metadata: *const c_void,
pub witness_table: *const c_void,
pub id: i64,
/* private fields */
}Expand description
A runtime-built Swift view type with any mix of property wrappers.
use swiftui_native::state::{ComposedBuilder, ColorSchemeKey};
use swiftui_native::views;
let mut b = ComposedBuilder::new();
let count = b.state(0_i64);
let dark = b.app_storage::<bool>("dark", false);
let scheme = b.environment::<ColorSchemeKey>();
let v = b.build(move |p| {
views::text(&format!("{} {} {:?}", p.state(count), p.stored(dark), p.env(scheme)))
});
v.set_state(count, 1);Reading a property as the wrong kind, or at the wrong type, does not compile — which is what the handles buy over addressing properties by number:
use swiftui_native::state::ComposedBuilder;
use swiftui_native::views;
let mut b = ComposedBuilder::new();
let count = b.state(0_i64);
let v = b.build(|_| views::text("x"));
let _: bool = v.stored(count); // a `@State` is not a `StoredProp`Each of StatefulView, StoredView and EnvironmentView is the
one-property case of this; they are kept because they are simpler to use
when one is all that is wanted.
Fields§
§metadata: *const c_void§witness_table: *const c_void§id: i64Implementations§
Source§impl ComposedView
impl ComposedView
Sourcepub fn set_state<T: StateValue>(&self, prop: StateProp<T>, value: T) -> bool
pub fn set_state<T: StateValue>(&self, prop: StateProp<T>, value: T) -> bool
Write the @State at index i, re-running the body.
Returns false before the first body evaluation, when there is no
binding to write through yet — the same contract as
StatefulView::set.
Sourcepub fn stored<T: StoredValue>(&self, prop: StoredProp<T>) -> T
pub fn stored<T: StoredValue>(&self, prop: StoredProp<T>) -> T
Read an @AppStorage from outside the body.
Sourcepub fn set_stored<T: StoredValue>(&self, prop: StoredProp<T>, value: T)
pub fn set_stored<T: StoredValue>(&self, prop: StoredProp<T>, value: T)
Write an @AppStorage, which persists and re-runs the body.
Sourcepub fn set_focus(&self, prop: FocusProp, value: bool) -> bool
pub fn set_focus(&self, prop: FocusProp, value: bool) -> bool
Move focus to — or away from — the @FocusState at index i.
Writing true focuses the field the property is attached to, which is
what @FocusState var focused: Bool; focused = true does in Swift.
Returns false before the first body evaluation, when there is no
installed property to write to yet.
Sourcepub fn focus(&self, prop: FocusProp) -> bool
pub fn focus(&self, prop: FocusProp) -> bool
Whether the @FocusState at index i has focus, read from outside the
body.
Sourcepub fn as_view(&self) -> ViewHandle
pub fn as_view(&self) -> ViewHandle
Wrap the instance so it can be hosted like any other view.