-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentView.cs
More file actions
525 lines (458 loc) · 28 KB
/
Copy pathContentView.cs
File metadata and controls
525 lines (458 loc) · 28 KB
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
using SwiftDotNet;
namespace SwiftDotNet.Sample;
/// <summary>
/// A tour of the framework, organized MAUI-Shell-style: a flyout menu (a grouped <see cref="Form"/> inside a
/// <see cref="NavigationStack"/>) whose rows push detail pages. Each menu row is an icon + title
/// (<see cref="Label"/>); each <see cref="Section"/> is a flyout group. All C#, all rendered as real SwiftUI.
///
/// All state lives here on the root view (per-view child-instance state is a separate milestone), and pages
/// are built by methods so they share these State fields across renders and across push/pop.
/// </summary>
public sealed class ContentView : View
{
// Inputs
readonly State<string> _name = State("");
readonly State<string> _password = State("");
readonly State<double> _volume = State(0.4);
readonly State<int> _quantity = State(1);
readonly State<int> _size = State(1);
readonly State<DateTime> _date = State(new DateTime(2026, 7, 17));
readonly State<string> _color = State("#FF3B30");
readonly State<bool> _notify = State(true);
readonly State<int> _rating = State(3);
readonly State<string> _gesture = State("Try the gestures below");
readonly State<bool> _panel = State(false);
// Lists
readonly State<bool> _expanded = State(false);
readonly State<string?> _selectedFruit = new(null);
// Carousel
readonly State<int> _carouselPage = State(0);
// Nav
readonly State<bool> _sheet = State(false);
readonly State<bool> _alert = State(false);
readonly State<bool> _confirm = State(false);
readonly State<bool> _actionSheet = State(false);
readonly State<string> _lastChoice = State("(nothing yet)");
// Animation / gestures (transforms + continuous drag/pinch)
readonly State<bool> _transformed = State(false);
readonly State<bool> _pulsing = State(false);
readonly State<double> _dragX = State(0.0);
readonly State<double> _dragY = State(0.0);
readonly State<double> _dragBaseX = State(0.0);
readonly State<double> _dragBaseY = State(0.0);
readonly State<double> _zoom = State(1.0);
// Maps (renders as MapLibre on Web / MapKit on Apple; graceful ⚠️ placeholder where no renderer is registered)
readonly State<MapCamera> _mapCamera = State(new MapCamera(new MapCoordinate(51.5074, -0.1278), 12));
readonly State<List<MapCoordinate>> _route = State(new List<MapCoordinate>());
static readonly string[] Sizes = { "Small", "Medium", "Large" };
static readonly string[] Fruits = { "🍎 Apple", "🍌 Banana", "🍒 Cherry", "🥝 Kiwi", "🍑 Peach" };
// The flyout: a grouped menu that pushes detail pages. Sections are the flyout groups; each row carries an
// SF-Symbol icon and pushes onto the stack. This replaces the old bottom TabView tour.
public override View Body =>
new NavigationStack(
new Form(
new Section("Controls",
Row("Text & Input", "textformat", TextInputPage()),
Row("Values & Steppers", "slider.horizontal.3", ValuesPage()),
Row("Rating", "star", RatingPage())),
new Section("Interaction",
Row("Gestures", "hand.tap", GesturesPage()),
Row("Animation", "wand.and.stars", AnimationPage())),
new Section("Layout",
Row("Shapes & Grid", "square.grid.2x2", ShapesPage()),
Row("Stacks & Alignment", "rectangle.3.offgrid", AlignmentPage()),
Row("Cards & Borders", "rectangle.portrait", CardsPage())),
new Section("Media",
Row("Carousel", "rectangle.stack", CarouselPage()),
Row("Indicators", "gauge", IndicatorsPage()),
Row("WebView", "globe", WebPage()),
Row("Maps", "map", MapsPage())),
new Section("Data",
Row("Lists & Selection", "list.bullet", ListsPage()),
Row("Disclosure & Menus", "chevron.down.circle", DisclosurePage())),
new Section("Styling",
Row("Global Styles", "paintbrush", StylesPage())),
new Section("Shiny Controls",
Row("Status & Progress", "gauge", new StatusSample()),
Row("Inputs & Pickers", "slider.horizontal.3", new InputsSample()),
Row("Overlays & Media", "square.stack", new OverlaysSample()),
Row("Collections", "list.bullet", new CollectionsSample()),
Row("Scheduler", "calendar", new SchedulerSample()),
Row("Chat", "bubble.left.and.bubble.right", new ChatSample()),
Row("Camera", "camera", new CameraSample())),
new Section("Navigation",
Row("Sheets & Alerts", "arrow.forward.circle", NavPage()))
).NavigationTitle("SwiftDotNet")
);
// A single flyout menu row: SF-Symbol icon + title that pushes a page.
static NavigationLink Row(string title, string symbol, View destination) =>
new NavigationLink(new Label(title, symbol), destination);
// ── Controls ────────────────────────────────────────────────────────────
View TextInputPage() =>
new ScrollView(
new Text("Text & Input").Font(Font.LargeTitle),
new Text(_name.Value.Length == 0 ? "Hello, stranger!" : $"Hello, {_name.Value}!")
.Font(Font.Headline).ForegroundColor(Color.Blue),
new TextField("Name", _name),
new SecureField("Password", _password),
new Toggle("Enable notifications", _notify),
new Text(_notify.Value ? "🔔 On" : "🔕 Off").Font(Font.Caption).ForegroundColor(Color.Secondary),
// .Disabled() dims + blocks interaction on any control; here it's bound live to the toggle.
new Button("Configure…", () => _sheet.Value = true).Disabled(!_notify.Value)
).Padding(20).NavigationTitle("Text & Input");
View ValuesPage() =>
new ScrollView(
new Text("Values & Steppers").Font(Font.LargeTitle),
new Text($"Volume: {_volume.Value:F2}").Font(Font.Caption),
new Slider(_volume),
new Stepper("Quantity:", _quantity, 0, 10),
new Picker("Size", _size, Sizes),
new DatePicker("Date", _date),
new ColorPicker("Accent color", _color)
).Padding(20).NavigationTitle("Values & Steppers");
View RatingPage() =>
new ScrollView(
new Text("Rating").Font(Font.LargeTitle),
// .ScaleEffect() applies a native transform to any view — grows the star with the rating.
new Text("★").Font(Font.Title).ForegroundColor(Color.Accent).ScaleEffect(1 + _rating.Value * 0.15),
// A user-authored composite custom control (see Rating.cs) — works on every backend.
new Text($"Rating: {_rating.Value}/5").Font(Font.Caption),
new Rating(_rating)
).Padding(20).NavigationTitle("Rating");
// ── Interaction ─────────────────────────────────────────────────────────
View GesturesPage() =>
new ScrollView(
new Text("Gestures").Font(Font.LargeTitle),
new Text(_gesture.Value).Font(Font.Headline),
new Text("One-shot").Font(Font.Headline),
new Text("👆 Double-tap me")
.Padding(12).Background(Color.Hex("#EEF0FF")).CornerRadius(10)
.OnTapGesture(() => _gesture.Value = "Double-tapped 👆", count: 2),
new Text("👇 Long-press me")
.Padding(12).Background(Color.Hex("#EAF7EE")).CornerRadius(10)
.OnLongPress(() => _gesture.Value = "Long-pressed 👇"),
new Text("👈 Swipe me left")
.Padding(12).Background(Color.Hex("#FDECEC")).CornerRadius(10)
.OnSwipe(SwipeDirection.Left, () => _gesture.Value = "Swiped left 👈"),
new Divider(),
// Continuous drag (F1) — began/changed/ended with cumulative translation.
new Text("Continuous drag & pinch").Font(Font.Headline),
new ZStack(
new ZStack(new Text("✋").Font(Font.Title))
.Frame(70, 70).Background(Color.Hex("#FFE0B2")).CornerRadius(14)
.Offset(_dragX.Value, _dragY.Value)
.OnDrag(info =>
{
_dragX.Value = _dragBaseX.Value + info.TranslationX;
_dragY.Value = _dragBaseY.Value + info.TranslationY;
if (info.Phase == GesturePhase.Ended) { _dragBaseX.Value = _dragX.Value; _dragBaseY.Value = _dragY.Value; }
_gesture.Value = $"Drag: ({info.TranslationX:0}, {info.TranslationY:0})";
})
).Frame(height: 180).Alignment(Alignment.Center),
// Continuous pinch (F1) — cumulative scale factor.
new ZStack(new Text("🔍 Pinch me").Font(Font.Headline).ForegroundColor(Color.Hex("#FFFFFF")))
.Frame(220, 90).Background(Color.Blue).CornerRadius(14)
.ScaleEffect(_zoom.Value)
.OnMagnify(scale => { _zoom.Value = Math.Clamp(scale, 0.5, 3); _gesture.Value = $"Zoom: {scale:0.0}×"; })
).Padding(20).NavigationTitle("Gestures");
View AnimationPage() =>
new ScrollView(
new Text("Animation").Font(Font.LargeTitle),
// 1) Implicit height + opacity spring.
new Text("Height & opacity").Font(Font.Headline),
new Button(_panel.Value ? "Collapse panel" : "Expand panel", () => _panel.Value = !_panel.Value),
new VStack(
new Text(".Animation(Anim.Spring(), on: _panel) — a real native spring on iOS/Compose/WinUI, a cubic-bezier on Web.")
.Font(Font.Caption).ForegroundColor(Color.Secondary).Padding(12)
).Frame(height: _panel.Value ? 110 : 0)
.Opacity(_panel.Value ? 1 : 0)
.Background(Color.Hex("#EEF0FF")).CornerRadius(10)
.Animation(Anim.Spring(), on: _panel.Value),
new Divider(),
// 2) Transform modifiers (F4): offset + rotation + scale, animated together on toggle.
new Text("Transforms — offset · rotation · scale").Font(Font.Headline),
new Button(_transformed.Value ? "Reset" : "Transform", () => _transformed.Value = !_transformed.Value),
new ZStack(
new ZStack(new Text("↗︎").Font(Font.LargeTitle).ForegroundColor(Color.Hex("#FFFFFF")))
.Frame(80, 80)
.Background(new LinearGradient(45, new GradientStop(Color.Hex("#7C4DFF"), 0), new GradientStop(Color.Hex("#00BCD4"), 1)))
.CornerRadius(16)
.Offset(_transformed.Value ? 90 : 0, 0)
.Rotation(_transformed.Value ? 25 : 0)
.ScaleEffect(_transformed.Value ? 1.3 : 1.0)
.Animation(Anim.Spring(), on: _transformed.Value)
).Frame(height: 120).Alignment(Alignment.Leading),
new Divider(),
// 3) Looping animation (F4): a self-reversing repeat drives a pulsing scale forever.
new Text("Looping pulse").Font(Font.Headline),
new Button(_pulsing.Value ? "Stop" : "Start pulsing", () => _pulsing.Value = !_pulsing.Value),
new ZStack(
new Circle().Frame(60, 60).ForegroundColor(Color.Red)
.ScaleEffect(_pulsing.Value ? 1.4 : 1.0)
.Opacity(_pulsing.Value ? 0.6 : 1.0)
.Animation(Anim.EaseInOut(0.7).Repeating(autoreverse: true), on: _pulsing.Value)
).Frame(height: 100),
new Divider(),
// 4) Keyframe timeline: independent per-property tracks on one clock. The scale track
// overshoots on a spring while opacity dips on an ease-out — a shape `.Animation` can't
// express, since it only knows the two endpoints.
new Text("Keyframes — independent tracks").Font(Font.Headline),
new Text("Opacity dips and recovers while scale overshoots; one clock, two curves.")
.Font(Font.Caption).ForegroundColor(Color.Secondary),
new ZStack(
new RoundedRectangle(18).Frame(80, 80).ForegroundColor(Color.Accent)
.Keyframes(k => k
.Track(Prop.Opacity, t => t
.At(0.0, 1.0)
.At(0.5, 0.3, Anim.EaseOut())
.At(1.0, 1.0))
.Track(Prop.Scale, t => t
.At(0.0, 1.0)
.At(0.6, 1.25, Anim.Spring())
.At(1.0, 1.0))
.Track(Prop.Rotation, t => t
.At(0.0, 0)
.At(1.0, 360, Anim.Linear()))
.Duration(2.0)
.Repeating())
).Frame(height: 120)
).Padding(20).NavigationTitle("Animation");
// ── Layout ──────────────────────────────────────────────────────────────
View ShapesPage() =>
new ScrollView(
new Text("Shapes & Grid").Font(Font.LargeTitle),
new Grid(3,
new Circle().Frame(70, 70).ForegroundColor(Color.Red),
new Rectangle().Frame(70, 70).ForegroundColor(Color.Green),
new Capsule().Frame(70, 44).ForegroundColor(Color.Blue),
new RoundedRectangle(14).Frame(70, 70).ForegroundColor(Color.Accent),
new Circle().Frame(70, 70).ForegroundColor(Color.Secondary),
new Rectangle().Frame(70, 70).ForegroundColor(Color.Red).Opacity(0.4)
).Spacing(12),
new Divider(),
new ZStack(
new RoundedRectangle(20).Frame(200, 100).ForegroundColor(Color.Blue),
new Text("ZStack").Font(Font.Title).ForegroundColor(Color.Primary)
),
new Divider(),
// Sized tracks + spans: a fixed gutter, a greedy middle, and a content-sized tail.
new Text("Grid tracks & spans").Font(Font.Headline),
new Grid(
new Rectangle().Frame(height: 24).ForegroundColor(Color.Accent).GridSpan(columns: 3),
new Text("Fixed 60"),
new Rectangle().Frame(height: 24).ForegroundColor(Color.Blue),
new Text("Auto"),
new Text("Tall").GridSpan(rows: 2),
new Rectangle().Frame(height: 24).ForegroundColor(Color.Green),
new Text("→"),
new Rectangle().Frame(height: 24).ForegroundColor(Color.Red),
new Text("↓"))
.Columns(GridTrack.Fixed(60), GridTrack.Star(), GridTrack.Auto)
.ColumnSpacing(10)
.RowSpacing(6)
.Alignment(Alignment.Leading),
new Divider(),
// AbsoluteLayout: a proportional backdrop with two children pinned to opposite corners.
new Text("AbsoluteLayout").Font(Font.Headline),
new AbsoluteLayout(
new RoundedRectangle(12).ForegroundColor(Color.Secondary).Opacity(0.25)
.LayoutBounds(0, 0, 1, 1, LayoutFlags.SizeProportional),
new Text("top-left").LayoutBounds(12, 12),
new Capsule().Frame(60, 24).ForegroundColor(Color.Accent)
.LayoutBounds(1, 1, 60, 24, LayoutFlags.PositionProportional))
.Frame(height: 120)
).Padding(20).NavigationTitle("Shapes & Grid");
View AlignmentPage() =>
new ScrollView(
new Text("Stacks & Alignment").Font(Font.LargeTitle),
new HStack(
Image.System("star.fill").ForegroundColor(Color.Accent),
new Label("Starred", "star"),
new Spacer(),
Image.System("heart.fill").ForegroundColor(Color.Red)
).Padding(),
new Divider(),
new Text("← leading").Align(Alignment.Leading).Border(Color.Secondary),
new Text("centered").Align(Alignment.Center).Border(Color.Secondary),
new Text("trailing →").Align(Alignment.Trailing).Border(Color.Secondary)
).Padding(20).NavigationTitle("Stacks & Alignment");
View CardsPage() =>
new ScrollView(
new Text("Cards & Borders").Font(Font.LargeTitle),
// A solid card: per-edge padding + background + corner radius + border + shadow
new VStack(
new Text("Solid card").Font(Font.Headline),
new Text("padding · background · corner radius · border · shadow")
.Font(Font.Caption).ForegroundColor(Color.Secondary)
).Alignment(HorizontalAlignment.Leading)
.Spacing(4).Padding(16)
.Background(Color.Hex("#EEF0FF")).CornerRadius(14)
.Border(Color.Blue, 2, cornerRadius: 14).Shadow(10, Color.Blue, y: 4),
// A linear-gradient card (F5) — a real gradient shader/CSS/SwiftUI LinearGradient.
new VStack(
new Text("Linear gradient").Font(Font.Headline).ForegroundColor(Color.Hex("#FFFFFF")),
new Text(".Background(new LinearGradient(45, …))").Font(Font.Caption).ForegroundColor(Color.Hex("#F0F0FF"))
).Alignment(HorizontalAlignment.Leading).Spacing(4).Padding(16)
.Background(new LinearGradient(45,
new GradientStop(Color.Hex("#7C4DFF"), 0), new GradientStop(Color.Hex("#00BCD4"), 1)))
.CornerRadius(14).Shadow(8, y: 4),
// A radial-gradient card (F5).
new VStack(
new Text("Radial gradient").Font(Font.Headline).ForegroundColor(Color.Hex("#FFFFFF"))
).Alignment(HorizontalAlignment.Leading).Padding(16)
.Background(new RadialGradient(Color.Hex("#FF5252"), Color.Hex("#7B1FA2")))
.CornerRadius(14),
// A frosted-glass material card (F6) over a gradient backdrop — real backdrop blur on Web/SwiftUI.
new ZStack(
new RoundedRectangle(16).Frame(300, 120).ForegroundColor(Color.Hex("#FF9500")),
new VStack(
new Text("Material").Font(Font.Headline),
new Text(".Material(MaterialStyle.Thin)").Font(Font.Caption)
).Spacing(4).Padding(16).Material(MaterialStyle.Thin).CornerRadius(12)
),
// Shadow & corner variations.
new HStack(
new RoundedRectangle(4).Frame(80, 80).ForegroundColor(Color.Hex("#EEF0FF")).Shadow(2, y: 1),
new RoundedRectangle(16).Frame(80, 80).ForegroundColor(Color.Hex("#EEF0FF")).Shadow(8, y: 4),
new RoundedRectangle(40).Frame(80, 80).ForegroundColor(Color.Hex("#EEF0FF")).Shadow(16, Color.Blue, y: 8)
).Spacing(12)
).Padding(20).NavigationTitle("Cards & Borders");
// ── Media ───────────────────────────────────────────────────────────────
static readonly string[] CardLabels = { "① Swipe me", "② Real SwiftUI", "③ Paged TabView", "④ From C#" };
View CarouselPage() =>
new VStack(
new Text($"Page {_carouselPage.Value + 1} of {CardLabels.Length}")
.Font(Font.Headline),
new TabView(
Card(CardLabels[0], Color.Red),
Card(CardLabels[1], Color.Green),
Card(CardLabels[2], Color.Blue),
Card(CardLabels[3], Color.Accent)
).Paged().SelectedIndex(_carouselPage),
new HStack(
new Button("◀ Prev", () => _carouselPage.Value = Math.Max(0, _carouselPage.Value - 1)),
new Button("Next ▶", () => _carouselPage.Value = Math.Min(CardLabels.Length - 1, _carouselPage.Value + 1))
).Spacing(24)
).Spacing(12).Padding(16).NavigationTitle("Carousel");
static View Card(string title, SwiftColor color) =>
new ZStack(
new RoundedRectangle(24).ForegroundColor(color).Opacity(0.85).Padding(30),
new Text(title).Font(Font.LargeTitle).ForegroundColor(Color.Primary)
);
View IndicatorsPage() =>
new ScrollView(
new Text("Indicators").Font(Font.LargeTitle),
new ProgressView(0.6, "Downloading"),
new Gauge(0.7, 0, 1, "Speed")
).Padding(20).NavigationTitle("Indicators");
View WebPage() =>
new ScrollView(
new Text("WebView").Font(Font.LargeTitle),
// Embedded web content — WKWebView (Apple), WebView2 (Windows), android.webkit.WebView,
// and an <iframe> on the Web backend. HTML string renders with no network round-trip.
WebView.FromHtml(
"<div style='font-family:sans-serif;padding:16px;text-align:center'>" +
"<h2>Hello from HTML 👋</h2><p>Rendered by the native web engine.</p></div>")
.Frame(height: 160),
new WebView("https://example.com").Frame(height: 220)
).Padding(20).NavigationTitle("WebView");
View MapsPage() =>
new VStack(
new Text("Maps").Font(Font.LargeTitle),
new Text("Tap the map to drop a pin and extend the route.")
.Font(Font.Caption).ForegroundColor(Color.Secondary),
new Map(_mapCamera)
.Pins(_route.Value.Select((c, i) => new MapPin(c, $"Stop {i + 1}", Color.Red, Id: i.ToString())))
.Polylines(new[] { new MapPolyline(_route.Value, Color.Blue, 4) })
.OnTap(c => _route.Value = new List<MapCoordinate>(_route.Value) { c })
.OnCameraChanged(cam => _mapCamera.Value = cam)
.Frame(height: 420),
new Button("Clear route", () => _route.Value = new())
).Spacing(8).Padding(16).NavigationTitle("Maps");
// ── Data ────────────────────────────────────────────────────────────────
View ListsPage() =>
new Form(
new Section($"Fruits — selected: {_selectedFruit.Value ?? "none"}",
List.ForEach(Fruits, f => f, f => new Text(f)).Selection(_selectedFruit))
).NavigationTitle("Lists & Selection");
View DisclosurePage() =>
new Form(
new Section("Disclosure",
new DisclosureGroup("Show details", _expanded,
new Text("Hidden row 1"),
new Text("Hidden row 2"),
new Text($"Notifications: {(_notify.Value ? "on" : "off")}"))),
new Section("Menu",
new Menu("Actions",
new Button("Increment quantity", () => _quantity.Value++),
new Button("Reset", () => _quantity.Value = 0)))
).NavigationTitle("Disclosure & Menus");
// ── Styling ─────────────────────────────────────────────────────────────
// Global styles, SwiftUI-style but resolved in C#: values set on a container cascade to descendants
// that don't set their own. Everything below is wrapped once in a Theme + a default ButtonStyle; the
// inner VStack adds an ambient font/color. None of the leaf Texts or Buttons style themselves.
View StylesPage() =>
new ScrollView(
new VStack(
new Text("Global styles").Font(Font.LargeTitle),
new Text("Set a font, color, control style, or theme once — descendants inherit it.")
.Font(Font.Caption).ForegroundColor(Color.Secondary),
// B — cascade: these three Texts declare no font/color; they inherit the ambient environment.
new VStack(
new Text("Inherited heading"),
new Text("Inherited line one"),
new Text("Inherited line two")
).Spacing(6).Align(Alignment.Leading)
.Environment(e => e.Font(Font.Headline).ForegroundColor(Color.Accent)),
// A — reusable bundle: a themed card look, its padding/surface/radius read from the Theme.
new VStack(
new Text("Reusable bundle").Font(Font.Headline),
new Text(".CardStyle() pulls padding, surface, radius and shadow from the Theme.")
.Font(Font.Caption)
).Spacing(4).Align(Alignment.Leading).CardStyle(),
// C — control style: neither button sets a style; both adopt the ambient FilledButtonStyle.
new Text("Ambient button style").Font(Font.Headline).Align(Alignment.Leading),
new HStack(
new Button("Primary", () => _quantity.Value++),
new Button("Secondary", () => _quantity.Value = 0)
).Spacing(12)
).Spacing(16).Padding(20)
).ButtonStyle(new FilledButtonStyle())
.Theme(new Theme { Accent = Color.Hex("#7C4DFF"), Surface = Color.Hex("#F0EEFF"), CornerRadius = 16 })
.NavigationTitle("Global Styles");
// ── Navigation ──────────────────────────────────────────────────────────
// Sheets, alerts and action sheets. This page already lives inside the flyout's NavigationStack, so it
// presents a nested Form of push/sheet/alert/link demos directly — no second NavigationStack needed.
//
// The three dialogs stack as fluent modifiers rather than nested constructors, which is what the
// .Alert / .ConfirmationDialog / .Sheet presentation modifiers are for.
View NavPage() =>
new Form(
new NavigationLink("Go to details ›",
new VStack(
new Text("Details").Font(Font.LargeTitle),
new Text("Pushed onto the navigation stack.").ForegroundColor(Color.Secondary)
).Padding().NavigationTitle("Details")),
new Button("Present a sheet", () => _sheet.Value = true),
new Button("Show an alert (one button)", () => _alert.Value = true),
new Button("Confirm a delete (two buttons)", () => _confirm.Value = true),
new Button("Show an action sheet", () => _actionSheet.Value = true),
new Text($"Last choice: {_lastChoice.Value}").Font(Font.Caption).ForegroundColor(Color.Secondary),
new Link("Visit apple.com", "https://apple.com")
).NavigationTitle("Sheets & Alerts")
.Sheet(_sheet,
new VStack(
new Text("Sheet content").Font(Font.Title),
new Text("Rendered from C#, presented by SwiftUI.").ForegroundColor(Color.Secondary),
new Button("Close", () => _sheet.Value = false)
).Padding(24))
.Alert(_alert, "Hello 👋", "This alert came from C# state.")
.Alert(_confirm, "Delete draft?", "This cannot be undone.",
AlertButton.Destructive("Delete", () => _lastChoice.Value = "Deleted"),
AlertButton.Cancel("Keep", () => _lastChoice.Value = "Kept"))
.ConfirmationDialog(_actionSheet, "Share this draft", "Pick a destination.",
new AlertButton("Copy link", () => _lastChoice.Value = "Copied link"),
new AlertButton("Email", () => _lastChoice.Value = "Emailed"),
AlertButton.Destructive("Discard", () => _lastChoice.Value = "Discarded"),
AlertButton.Cancel());
}