-
Notifications
You must be signed in to change notification settings - Fork 8
BER-80: Converting MapMarkerDetailView into SwiftUI #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6293188
72e7aec
dff7222
a6500af
7afef88
0bdc698
77356ee
504bff5
83d72c1
bb79a60
7d1e11c
d273278
b93720b
d48348f
152c754
1d6da83
5bc47fc
102796f
c5d7da4
af98076
329c5e5
a2ae856
3f048bb
8b8707a
0d61a4d
ac7752b
2a39354
6efe6d4
12c0663
ffd7cb5
b25e4c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"originHash" : "7ed1966e3e00f1cc30964015f9aca1372b03fa405ea9aca1300a7bf1d858ba6a", | ||
"pins" : [ | ||
{ | ||
"identity" : "swiftsoup", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/scinfu/SwiftSoup.git", | ||
"state" : { | ||
"revision" : "0837db354faf9c9deb710dc597046edaadf5360f", | ||
"version" : "2.7.6" | ||
} | ||
} | ||
], | ||
"version" : 3 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
// | ||
// MapMakerDetailSwiftView.swift | ||
// berkeley-mobile | ||
// | ||
// Created by Dylan Chhum on 3/11/25. | ||
// Copyright © 2025 ASUC OCTO. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MapKit | ||
import SwiftUI | ||
|
||
// MARK: - MapMarkerDetailSwiftView | ||
|
||
struct MapMarkerDetailSwiftView: View { | ||
var marker: MapMarker? | ||
var onClose: (() -> Void)? | ||
var body: some View { | ||
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add newline between |
||
ZStack { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this |
||
HStack { | ||
colorAccentBar | ||
|
||
VStack(alignment: .leading, spacing: 4) { | ||
headerView | ||
Spacer() | ||
descriptionView | ||
Spacer() | ||
infoRowView | ||
} | ||
.padding(.vertical, 8) | ||
Spacer() | ||
} | ||
.background(Color(.systemBackground)) | ||
Chhumbucket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.clipShape(RoundedRectangle(cornerRadius: 12)) | ||
.frame(maxWidth: .infinity) | ||
.frame(minWidth: 200, maxHeight: 140) | ||
.shadow(color: .black.opacity(0.2), radius: 5, x: 0, y: 2) | ||
.padding(.horizontal, 20) | ||
} | ||
} | ||
|
||
|
||
Chhumbucket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// MARK: - Private Views | ||
|
||
private var colorAccentBar: some View { | ||
let markerColor: Color = { | ||
guard let marker else { | ||
return .purple | ||
} | ||
|
||
switch marker.type { | ||
case .known(let type): | ||
return Color(type.color()) | ||
case .unknown: | ||
return Color(BMColor.MapMarker.other) | ||
} | ||
}() | ||
Comment on lines
+46
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make this is a private helper function? |
||
|
||
return Rectangle() | ||
.fill(markerColor) | ||
.frame(width: 12) | ||
} | ||
|
||
private var headerView: some View { | ||
HStack(alignment: .top) { | ||
Text((marker?.title ?? "Unknown").capitalized) | ||
.font(Font(BMFont.bold(21))) | ||
.foregroundColor(.primary) | ||
.fixedSize(horizontal: false, vertical: true) | ||
Spacer() | ||
|
||
Button { | ||
onClose?() | ||
} label: { | ||
Image(systemName: "xmark") | ||
.font(.system(size: 16)) | ||
.foregroundStyle(Color.secondary) | ||
.padding(.trailing, 4) | ||
} | ||
Comment on lines
+72
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use trailing closure syntax: Button(action: {
}) {
...
} |
||
} | ||
} | ||
|
||
private var descriptionView: some View { | ||
Text(marker?.subtitle ?? "No description") | ||
.font(Font(BMFont.regular(10))) | ||
.fixedSize(horizontal: false, vertical: true) | ||
.padding(.trailing, 8) | ||
} | ||
|
||
private var infoRowView: some View { | ||
HStack { | ||
HStack(spacing: 8) { | ||
Image(systemName: "clock") | ||
.font(.system(size: 12)) | ||
.foregroundColor(.secondary) | ||
.rotationEffect(.init(degrees: 90)) | ||
openStatusButton | ||
} | ||
|
||
Spacer() | ||
|
||
locationInfoView | ||
|
||
Spacer() | ||
|
||
categoryView | ||
} | ||
Comment on lines
+91
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the outer |
||
} | ||
|
||
private var openStatusButton: some View { | ||
Capsule() | ||
.fill(marker?.isOpen ?? false ? Color.blue : Color(red: 0.4, green: 0.5, blue: 0.9)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.frame(width: 48, height: 18) | ||
.overlay { | ||
Text(marker?.isOpen ?? false ? "Open" : "Closed") | ||
.font(Font(BMFont.medium(9))) | ||
.foregroundStyle(.white) | ||
} | ||
} | ||
|
||
private var locationInfoView: some View { | ||
HStack(spacing: 8) { | ||
Image(systemName: "mappin.and.ellipse") | ||
.font(.system(size: 12)) | ||
.foregroundColor(.secondary) | ||
Text(marker?.address ?? "No Address") | ||
.font(Font(BMFont.regular(12))) | ||
.foregroundColor(.primary) | ||
.lineLimit(1) | ||
.truncationMode(.tail) | ||
} | ||
} | ||
|
||
private var categoryView: some View { | ||
HStack(spacing: 8){ | ||
Image(systemName: getCategoryIcon()) | ||
.font(.system(size: 12)) | ||
.foregroundColor(.secondary) | ||
|
||
Group { | ||
if let marker, case .known(let type) = marker.type, type == .cafe, let mealPrice = marker.mealPrice { | ||
Text(mealPrice) | ||
.font(Font(BMFont.regular(12))) | ||
.foregroundColor(.primary) | ||
} else { | ||
Text("<10") | ||
.font(Font(BMFont.regular(12))) | ||
.foregroundColor(.primary) | ||
} | ||
} | ||
Comment on lines
+140
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bring |
||
} | ||
} | ||
|
||
private func getCategoryIcon() -> String { | ||
guard let marker else { | ||
return "questionmark.circle" | ||
} | ||
|
||
switch marker.type { | ||
case .known(let type): | ||
switch type { | ||
case .cafe: | ||
return "fork.knife" | ||
case .store: | ||
return "bag" | ||
case .mentalHealth: | ||
return "brain" | ||
case .genderInclusiveRestrooms: | ||
return "toilet" | ||
case .menstrualProductDispensers: | ||
return "drop" | ||
case .garden: | ||
return "leaf" | ||
case .bikes: | ||
return "bicycle" | ||
case .lactation: | ||
return "heart" | ||
case .rest: | ||
return "bed.double" | ||
case .microwave: | ||
return "bolt" | ||
case .printer: | ||
return "printer" | ||
case .water: | ||
return "drop.fill" | ||
case .waste: | ||
return "trash" | ||
case .none: | ||
return "mappin" | ||
} | ||
case .unknown: | ||
return "mappin" | ||
} | ||
} | ||
Comment on lines
+154
to
+194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have a |
||
} | ||
|
||
|
||
// MARK: - Preview | ||
Chhumbucket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#Preview { | ||
MapMarkerDetailSwiftView( | ||
marker: MapMarker( | ||
type: "Cafe", | ||
location: CLLocationCoordinate2D(latitude: 37.871684, longitude: -122.259934), | ||
name: "Babette South Hall Coffee Bar", | ||
description: "A retail Cal Dining location featuring a Peet Coffee & tea store, made- to-go order deli and bagels bar, smoothies, and grab-and-go items.", | ||
address: "Lower Sproul Plaza", | ||
onCampus: true, | ||
phone: "510-123-4567", | ||
email: "[email protected]", | ||
weeklyHours: nil, | ||
appointment: false, | ||
mealPrice: "$5-10", | ||
cal1Card: true, | ||
eatWell: true, | ||
mpdRooms: nil, | ||
accessibleGIRs: nil, | ||
nonAccesibleGIRs: nil | ||
), | ||
onClose: {} | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove MARK