-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainTabView.swift
More file actions
71 lines (65 loc) · 2.15 KB
/
MainTabView.swift
File metadata and controls
71 lines (65 loc) · 2.15 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
//
// MainTabView.swift
// DavisFriends
//
// Created by Jerry Au on 4/21/25.
//
import SwiftUI
import MapKit
struct MainTabView: View {
@StateObject private var store = EventStore()
@State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 38.54237287621318,
longitude: -121.74955185519764),
span: MKCoordinateSpan(latitudeDelta: 0.05,
longitudeDelta: 0.05)
)
@State private var showEditor = false
@State private var newCoord: CLLocationCoordinate2D?
var body: some View {
TabView {
NavigationView {
MapView(
region: $region,
pins: store.pins.map(\.mkAnnotation),
onTap: { coord in
newCoord = coord
showEditor = true
}
)
.navigationTitle("Map")
}
.tabItem {
Label("Map", systemImage: "map")
}
NavigationView {
Text("Placeholder for your second tab")
.navigationTitle("Details")
}
.tabItem {
Label("Details", systemImage: "list.bullet")
}
}
.toolbarBackground(.blue, for: .tabBar)
.toolbarBackground(.visible, for: .tabBar)
.toolbarColorScheme(.dark, for: .tabBar)
// sheet for adding a new pin
.sheet(item: $newCoord, onDismiss: {newCoord = nil}) { coord in
PinEditor(coordinate: coord) { title, subtitle in
let pin = Pin(id: nil,
lat: coord.latitude,
long: coord.longitude,
locationName: title,
description: subtitle)
store.append(pin)
// dismiss by setting newCoord back to nil
newCoord = nil
}
}
}
}
struct MainPage_Preview: PreviewProvider {
static var previews: some View {
MainTabView()
}
}