-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPinEditor.swift
More file actions
52 lines (49 loc) · 1.93 KB
/
PinEditor.swift
File metadata and controls
52 lines (49 loc) · 1.93 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
import SwiftUI
import CoreLocation
struct PinEditor: View {
let coordinate: CLLocationCoordinate2D
var onSave: (_ title: String, _ subtitle: String) -> Void
@Environment(\.presentationMode) private var presentationMode
@State private var title: String = ""
@State private var subtitle: String = ""
var body: some View {
NavigationView {
Form {
Section(header: Text("Coordinates")) {
Text(String(format: "%.6f, %.6f", coordinate.latitude, coordinate.longitude))
.font(.subheadline)
.foregroundColor(.secondary)
}
Section(header: Text("Title")) {
TextField("Enter title", text: $title)
}
Section(header: Text("Description")) {
TextField("Enter description", text: $subtitle)
}
}
.navigationTitle("New Pin")
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Cancel") {
presentationMode.wrappedValue.dismiss()
}
}
ToolbarItem(placement: .confirmationAction) {
Button("Save") {
onSave(title.trimmingCharacters(in: .whitespacesAndNewlines),
subtitle.trimmingCharacters(in: .whitespacesAndNewlines))
presentationMode.wrappedValue.dismiss()
}
.disabled(title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
}
}
}
}
}
struct PinEditor_Previews: PreviewProvider {
static var previews: some View {
PinEditor(coordinate: CLLocationCoordinate2D(latitude: 38.0, longitude: -121.0)) { title, subtitle in
print("Saved: \(title) - \(subtitle)")
}
}
}