-
Notifications
You must be signed in to change notification settings - Fork 0
/
FloatingButton.swift
50 lines (43 loc) · 1.36 KB
/
FloatingButton.swift
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
//
// FloatingButton.swift
// BucketList
//
// Created by Waveline Media on 12/30/20.
//
import SwiftUI
import MapKit
struct FloatingButton: View {
@Binding var centerCoordinate: CLLocationCoordinate2D
@Binding var locations: [CodableMKPointAnnotation]
var body: some View {
VStack {
Spacer()
HStack {
Spacer()
Button(action: addNewPin, label: {
Image(systemName: "plus")
})
.padding()
.background(Color.black.opacity(0.75))
.foregroundColor(.white)
.font(.title)
.clipShape(Circle())
.padding([.trailing, .bottom])
}
}
}
func addNewPin() {
let newLocation = CodableMKPointAnnotation()
newLocation.coordinate = self.centerCoordinate
newLocation.title = "Example location"
let filteredLocations = locations.first(where: { $0 == newLocation })
if filteredLocations == nil {
self.locations.append(newLocation)
}
}
}
struct FloatingButton_Previews: PreviewProvider {
static var previews: some View {
FloatingButton(centerCoordinate: .constant(MKPointAnnotation.example.coordinate), locations: .constant([MKPointAnnotation.example]))
}
}