Skip to content

Commit 8258119

Browse files
committed
Wire NavigationView/NavigationLink and flexible List into demo
1 parent a5f4f5d commit 8258119

1 file changed

Lines changed: 52 additions & 33 deletions

File tree

Demo/App.swiftpm/Sources/ContentView.swift

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#if canImport(AndroidSwiftUI)
22
import AndroidSwiftUI
3-
typealias List = AndroidListView
43
#else
54
import SwiftUI
65
#endif
@@ -23,50 +22,70 @@ struct ContentView: View {
2322
}
2423

2524
var body: some View {
26-
VStack {
27-
HStack {
28-
VStack(spacing: 20) {
29-
Image("globe")
30-
Text("Hello World")
31-
Text(verbatim: date.formatted(date: .numeric, time: .complete))
32-
if counter > 0 {
33-
HStack {
34-
Text("Counter:")
35-
Text(verbatim: counter.description)
25+
NavigationView {
26+
VStack {
27+
HStack {
28+
VStack(spacing: 20) {
29+
Image("globe")
30+
Text("Hello World")
31+
Text(verbatim: date.formatted(date: .numeric, time: .complete))
32+
if counter > 0 {
33+
HStack {
34+
Text("Counter:")
35+
Text(verbatim: counter.description)
36+
}
3637
}
37-
}
38-
Button("Increment") {
39-
counter += 1
40-
if counter > 20 {
41-
counter = 0
38+
Button("Increment") {
39+
counter += 1
40+
if counter > 20 {
41+
counter = 0
42+
}
4243
}
4344
}
44-
}
45-
.onAppear {
46-
task = Task {
47-
while true {
48-
do {
49-
try await Task.sleep(for: .seconds(1))
50-
date = Date()
51-
}
52-
catch {
53-
return
45+
.onAppear {
46+
task = Task {
47+
while true {
48+
do {
49+
try await Task.sleep(for: .seconds(1))
50+
date = Date()
51+
}
52+
catch {
53+
return
54+
}
5455
}
5556
}
5657
}
58+
.onDisappear {
59+
task?.cancel()
60+
task = nil
61+
}
5762
}
58-
.onDisappear {
59-
task?.cancel()
60-
task = nil
61-
}
62-
}
63-
List(items) { item in
64-
Text(verbatim: item.title)
63+
NavigationLink("Show Items", destination: ItemsView(items: items))
6564
}
6665
}
6766
}
6867
}
6968

69+
struct ItemsView: View {
70+
71+
let items: [Item]
72+
73+
var body: some View {
74+
List(items) { item in
75+
NavigationLink(item.title, destination: DetailView(item: item))
76+
}
77+
}
78+
}
79+
80+
struct DetailView: View {
81+
82+
let item: Item
83+
84+
var body: some View {
85+
Text(verbatim: "Detail for \(item.title)")
86+
}
87+
}
88+
7089
struct Item: Identifiable {
7190
let id: Int
7291
var title: String {

0 commit comments

Comments
 (0)