@@ -12,11 +12,13 @@ struct TodoListView: View {
12
12
@State private var newTodo : NewTodo ?
13
13
@State private var editing : Bool = false
14
14
15
+ #if os(iOS)
15
16
// Called when a photo has been captured. Individual widgets should register the listener
16
17
@State private var onMediaSelect : ( ( _: Data ) async throws -> Void ) ?
17
18
@State private var pickMediaType : UIImagePickerController . SourceType = . camera
18
19
@State private var showMediaPicker = false
19
20
@State private var isCameraAvailable : Bool = false
21
+ #endif
20
22
21
23
var body : some View {
22
24
List {
@@ -33,6 +35,7 @@ struct TodoListView: View {
33
35
}
34
36
35
37
ForEach ( todos) { todo in
38
+ #if os(iOS)
36
39
TodoListRow (
37
40
todo: todo,
38
41
isCameraAvailable: isCameraAvailable,
@@ -68,6 +71,20 @@ struct TodoListView: View {
68
71
pickMediaType = . photoLibrary
69
72
showMediaPicker = true
70
73
}
74
+ #else
75
+ TodoListRow (
76
+ todo: todo,
77
+ isCameraAvailable: false ,
78
+ completeTapped: {
79
+ Task {
80
+ await toggleCompletion ( of: todo)
81
+ }
82
+ } ,
83
+ deletePhotoTapped: { } ,
84
+ capturePhotoTapped: { } ,
85
+ selectPhotoTapped: { } ,
86
+ )
87
+ #endif
71
88
}
72
89
. onDelete { indexSet in
73
90
Task {
@@ -80,12 +97,14 @@ struct TodoListView: View {
80
97
}
81
98
}
82
99
}
100
+ #if os(iOS)
83
101
. sheet( isPresented: $showMediaPicker) {
84
102
CameraView (
85
103
onMediaSelect: $onMediaSelect,
86
104
mediaType: $pickMediaType
87
105
)
88
106
}
107
+ #endif
89
108
. animation( . default, value: todos)
90
109
. navigationTitle ( " Todos " )
91
110
. toolbar {
@@ -111,9 +130,11 @@ struct TodoListView: View {
111
130
}
112
131
}
113
132
}
133
+ #if os(iOS)
114
134
. onAppear {
115
135
checkCameraAvailability ( )
116
136
}
137
+ #endif
117
138
. task {
118
139
await system. watchTodos ( listId) { tds in
119
140
withAnimation {
@@ -144,6 +165,7 @@ struct TodoListView: View {
144
165
}
145
166
}
146
167
168
+ #if os(iOS)
147
169
/// Registers a callback which saves a photo for the specified Todo item if media is sucessfully loaded.
148
170
func registerMediaCallback( todo: Todo ) {
149
171
// Register a callback for successful image capture
@@ -181,6 +203,7 @@ struct TodoListView: View {
181
203
isCameraAvailable = UIImagePickerController . isSourceTypeAvailable ( . camera)
182
204
#endif
183
205
}
206
+ #endif
184
207
}
185
208
186
209
#Preview {
@@ -191,6 +214,7 @@ struct TodoListView: View {
191
214
}
192
215
}
193
216
217
+ #if os(iOS)
194
218
struct CameraView : UIViewControllerRepresentable {
195
219
@Binding var onMediaSelect : ( ( _: Data ) async throws -> Void ) ?
196
220
@Binding var mediaType : UIImagePickerController . SourceType
@@ -244,3 +268,4 @@ struct CameraView: UIViewControllerRepresentable {
244
268
}
245
269
}
246
270
}
271
+ #endif
0 commit comments