1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
//! Files, services, the environment and preferences.
//!
//! Part of [`crate::view::View`]'s chainable API; Rust allows a type's
//! inherent methods to be split across modules, and 400 of them in one file
//! was a file nobody could find anything in.
use super::{View};
use crate::views;
impl View {
// ── Files ──
//
// All three are bound: the flag that shows the panel is Rust's, so
// dismissing it writes `false` back rather than leaving the two sides to
// disagree about whether a panel is up.
/// `.fileExporter(isPresented:item:contentTypes:defaultFilename:onCompletion:onCancellation:)`
pub fn file_exporter(
self,
state: &views::BoundState<bool>,
item: Option<&str>,
kinds: &[views::ContentType],
default_filename: Option<&str>,
completion: impl Fn(views::FileOutcome) + 'static,
cancellation: impl Fn() + 'static,
) -> Self {
Self::new(views::file_exporter(
&self.handle,
state,
item,
kinds,
default_filename,
completion,
cancellation,
))
}
/// `.fileImporter(isPresented:allowedContentTypes:onCompletion:)`
pub fn file_importer(
self,
state: &views::BoundState<bool>,
kinds: &[views::ContentType],
completion: impl Fn(views::FileOutcome) + 'static,
) -> Self {
Self::new(views::file_importer(&self.handle, state, kinds, completion))
}
/// `.fileMover(isPresented:file:onCompletion:)`
pub fn file_mover(
self,
state: &views::BoundState<bool>,
file: Option<&str>,
completion: impl Fn(views::FileOutcome) + 'static,
) -> Self {
Self::new(views::file_mover(&self.handle, state, file, completion))
}
// ── Services and item providers ──
/// `.itemProvider(_:)` — what this view offers to a drag or a service.
pub fn item_provider(self, item: Option<&str>) -> Self {
Self::new(views::item_provider(&self.handle, item))
}
/// `.exportsItemProviders(_:items:onEdit:)`
pub fn exports_item_providers(
self,
kinds: &[views::ContentType],
items: &[&str],
edit: impl Fn(&[views::ItemProvider]) -> bool + 'static,
) -> Self {
Self::new(views::exports_item_providers(&self.handle, kinds, items, edit))
}
/// `.importsItemProviders(_:onImport:)`
pub fn imports_item_providers(
self,
kinds: &[views::ContentType],
accept: impl Fn(&[views::ItemProvider]) -> bool + 'static,
) -> Self {
Self::new(views::imports_item_providers(&self.handle, kinds, accept))
}
/// `.exportableToServices(_:)` — what the Services menu may take.
pub fn exportable_to_services(self, items: &[&str]) -> Self {
Self::new(views::exportable_to_services(&self.handle, items))
}
/// `.importableFromServices(for:action:)`
pub fn importable_from_services(self, accept: impl Fn(&[String]) -> bool + 'static) -> Self {
Self::new(views::importable_from_services(&self.handle, accept))
}
/// `.onReceive(_:perform:)` — a publisher's values, as `Int`s.
pub fn on_receive(self, complete_immediately: bool, perform: impl Fn(i64) + 'static) -> Self {
Self::new(views::on_receive(&self.handle, complete_immediately, perform))
}
/// `.onScrollGeometryChange(for:of:action:)`
/// `measure` is handed the scroll view's [`views::ScrollGeometry`] and
/// returns the value to watch; `action` is called with the old and the new
/// one. Both used to be blind, which left the modifier able to notice that
/// *something* had scrolled and nothing more.
pub fn on_scroll_geometry_change(
self,
measure: impl Fn(views::ScrollGeometry) -> i64 + 'static,
action: impl Fn(i64, i64) + 'static,
) -> Self {
Self::new(views::on_scroll_geometry_change(&self.handle, measure, action))
}
/// `.onScrollGeometryChange(for: Double.self, …)` — the same, watching a
/// `Double`, which a scroll offset is.
pub fn on_scroll_geometry_change_f64(
self,
measure: impl Fn(views::ScrollGeometry) -> f64 + 'static,
action: impl Fn(f64, f64) + 'static,
) -> Self {
Self::new(views::on_scroll_geometry_change_f64(&self.handle, measure, action))
}
/// `.onScrollTargetVisibilityChange(for:threshold:_:)` — which targets are
/// on screen, which is how a carousel knows what page it is on.
pub fn on_scroll_target_visibility_change(
self,
threshold: f64,
visible: impl Fn(&[i64]) + 'static,
) -> Self {
Self::new(views::on_scroll_target_visibility_change(&self.handle, threshold, visible))
}
/// `.dismissalConfirmationDialog(_:shouldPresent:actions:message:)` — ask
/// before a sheet closes on unsaved work.
pub fn dismissal_confirmation_dialog(
self,
title: &str,
should_present: bool,
actions: View,
message: View,
) -> Self {
Self::new(views::dismissal_confirmation_dialog(
&self.handle,
title,
should_present,
actions.handle(),
message.handle(),
))
}
/// `.presentationPreventsAppTermination(_:)` — `None` restores the default.
pub fn presentation_prevents_app_termination(self, prevents: Option<bool>) -> Self {
Self::new(views::presentation_prevents_app_termination(&self.handle, prevents))
}
/// `.textInputFormattingControlVisibility(_:for:)`
pub fn text_input_formatting_control_visibility(
self,
visibility: views::Visibility,
placements: views::TextInputFormattingControlPlacementSet,
) -> Self {
Self::new(views::text_input_formatting_control_visibility(
&self.handle,
visibility,
placements,
))
}
/// `.handGestureShortcut(_:isEnabled:)` — the pinch that stands in for a
/// tap on a watch.
pub fn hand_gesture_shortcut(
self,
shortcut: views::HandGestureShortcut,
enabled: bool,
) -> Self {
Self::new(views::hand_gesture_shortcut(&self.handle, shortcut, enabled))
}
/// `.assistiveAccessNavigationIcon(_:)`
pub fn assistive_access_navigation_icon(self, name: &str) -> Self {
Self::new(views::assistive_access_navigation_icon(&self.handle, name))
}
/// `.accessibilityRotor(_:textRanges:)` — a custom rotor VoiceOver can spin
/// through.
pub fn a11y_rotor(self, label: &str, text: &str) -> Self {
Self::new(views::accessibility_rotor(&self.handle, label, text))
}
/// `.accessibilityRotorEntry(id:in:)`
pub fn a11y_rotor_entry(self, id: views::HashableValue<'_>) -> Self {
Self::new(views::accessibility_rotor_entry(&self.handle, id))
}
/// `.accessibilityChartDescriptor(_:)`
pub fn a11y_chart_descriptor(self) -> Self {
Self::new(views::accessibility_chart_descriptor(&self.handle))
}
/// `.environmentObject(_:)`
pub fn environment_object(self) -> Self {
Self::new(views::environment_object(&self.handle))
}
/// `.focusedObject(_:)`
pub fn focused_object(self) -> Self {
Self::new(views::focused_object(&self.handle))
}
/// `.defaultAppStorage(_:)`
pub fn default_app_storage_standard(self) -> Self {
Self::new(views::default_app_storage_standard(&self.handle))
}
/// `.textRenderer(_:)`
pub fn text_renderer(self) -> Self {
Self::new(views::text_renderer(&self.handle))
}
/// `.attributedTextFormattingDefinition(_:)`
pub fn attributed_text_formatting_definition(self) -> Self {
Self::new(views::attributed_text_formatting_definition(&self.handle))
}
// ── Environment ──
/// `.environment(\.imageScale, _)`
pub fn environment_image_scale(self, scale: views::ImageScale) -> Self {
Self::new(views::environment_image_scale(&self.handle, scale))
}
/// `.environment(\.symbolVariants, _)`
pub fn environment_symbol_variants(self, value: views::SymbolVariants) -> Self {
Self::new(views::environment_symbol_variants(&self.handle, value))
}
/// `.transformEnvironment(\.imageScale, _)`
pub fn transform_environment_image_scale(
self,
action: impl Fn(views::ImageScale) -> views::ImageScale + 'static,
) -> Self {
Self::new(views::transform_environment_image_scale(&self.handle, action))
}
/// `.focusedValue(_:)`
pub fn focused_value(self, present: bool) -> Self {
Self::new(views::focused_value(&self.handle, present))
}
// ── Preferences and anchors ──
//
// SwiftUI's way of passing a value *up* a view tree: a child writes one, an
// ancestor reads it and can place content with it. The key is fixed to an
// `Int` here — a generic key needs a Swift type per key, which is a
// different piece of work — but the mechanism is the whole of it.
/// `.preference(key:value:)` — write a value for an ancestor to collect.
pub fn preference(self, value: i64) -> Self {
Self::new(views::preference_int(&self.handle, value))
}
/// `.onPreferenceChange(_:perform:)` — observe what descendants wrote.
///
/// The value is read back with [`views::observed_preference`] rather than
/// through a closure, because SwiftUI calls the handler on its own schedule
/// and the last value is what a caller wants.
pub fn on_preference_change(self) -> Self {
Self::new(views::on_preference_change_int(&self.handle))
}
/// `.transformPreference(_:_:)` — rewrite what passes through.
pub fn transform_preference(self) -> Self {
Self::new(views::transform_preference_double(&self.handle))
}
/// `.anchorPreference(key:value:transform:)` — write a preference derived
/// from this view's geometry.
pub fn anchor_preference(self, transform: impl Fn() -> i64 + 'static) -> Self {
Self::new(views::anchor_preference(&self.handle, transform))
}
/// `.transformAnchorPreference(key:value:transform:)`
pub fn transform_anchor_preference(self, transform: impl Fn(i64) -> i64 + 'static) -> Self {
Self::new(views::transform_anchor_preference(&self.handle, transform))
}
/// `.overlayPreferenceValue(_:alignment:_:)` — place content over this view
/// using what a descendant reported, which is how a badge follows the thing
/// it belongs to.
pub fn overlay_preference_value(self, alignment: views::Alignment, content: View) -> Self {
Self::new(views::overlay_preference_value(&self.handle, alignment, content.handle()))
}
/// `.backgroundPreferenceValue(_:alignment:_:)`
pub fn background_preference_value(self, alignment: views::Alignment, content: View) -> Self {
Self::new(views::background_preference_value(&self.handle, alignment, content.handle()))
}
/// `.gridCellAnchor(_:)` — where this cell sits in the space the grid gives
/// it, as a unit point.
pub fn grid_cell_anchor(self, x: f64, y: f64) -> Self {
Self::new(views::grid_cell_anchor(&self.handle, x, y))
}
/// `.popover(isPresented:attachmentAnchor:arrowEdge:content:)` bound to Rust
/// state — the anchored form, where the arrow points at a chosen point
/// rather than the view's middle.
pub fn popover_anchored(
self,
state: &views::BoundState<bool>,
anchor: (f64, f64),
arrow_edge: views::Edge,
content: View,
) -> Self {
Self::new(views::popover_anchored(
&self.handle,
state,
anchor,
arrow_edge,
content.handle(),
))
}
/// `.windowResizeAnchor(_:)` — `None` restores the default.
pub fn window_resize_anchor(self, anchor: Option<(f64, f64)>) -> Self {
Self::new(views::window_resize_anchor(&self.handle, anchor))
}
}