Skip to content

BER-80: Converting MapMarkerDetailView into SwiftUI [WIP]#341

Open
Chhumbucket wants to merge 42 commits into
masterfrom
dylchhum/ber-80
Open

BER-80: Converting MapMarkerDetailView into SwiftUI [WIP]#341
Chhumbucket wants to merge 42 commits into
masterfrom
dylchhum/ber-80

Conversation

@Chhumbucket

Copy link
Copy Markdown
Collaborator
Screenshot 2025-03-12 at 5 33 06 PM

Converted the MapMarkerDetailView into SwiftUI.

Currently placed templates for the buttons and used static data just to represent the view.

Future updates,

I want to connect the title of the place and the description in the same place to make sure that the padding is aligned. I feel that there is redundancy in the code, I want some feedback if there is.

@Chhumbucket Chhumbucket changed the title Dylchhum/ber 80 Ber-80: Converting MapMarkerDetailView into SwiftUI Mar 13, 2025
@Chhumbucket Chhumbucket self-assigned this Mar 13, 2025
@Chhumbucket Chhumbucket changed the title Ber-80: Converting MapMarkerDetailView into SwiftUI BER-80: Converting MapMarkerDetailView into SwiftUI Mar 13, 2025
@justinwongeecs
justinwongeecs self-requested a review March 14, 2025 08:11
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
@baeuke
baeuke self-requested a review March 20, 2025 22:37
baeuke
baeuke previously requested changes Mar 25, 2025
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMakerDetailSwiftView.swift Outdated
@Chhumbucket

Copy link
Copy Markdown
Collaborator Author
Screen.Recording.2025-03-28.at.11.04.52.PM.mov

@justinwongeecs justinwongeecs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve merge conflicts and for the past comments in the conversation, please resolve them if they have been implemented.

@Chhumbucket
Chhumbucket dismissed stale reviews from justinwongeecs and baeuke March 31, 2025 20:40

Fixed the conflicts

Comment thread berkeley-mobile.xcodeproj/project.pbxproj
@baeuke

baeuke commented May 3, 2025

Copy link
Copy Markdown
Collaborator

Search is breaking in your branch:

description

searchResultsView = UIHostingController(rootView: SearchResultsView().environmentObject(searchViewModel)).view
let resultsView = SearchResultsView().environmentObject(searchViewModel)
searchResultsHostingController = UIHostingController(rootView: AnyView(resultsView))
searchResultsView = searchResultsHostingController.view

@baeuke baeuke May 3, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chhumbucket You didn't resolve this one. I think we had a consistent way with the hostingController;
you better make markerDetail work same way too than changing how search components are made (don't change search).
Justin did in the same way with mapUserLocationButton.

private var searchBar: UIView!
private var searchResultsView: UIView!
private var searchResultsHostingController: UIHostingController<AnyView>!
private var searchViewModel: SearchViewModel!

@baeuke baeuke May 3, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to store UIHostingController variables. The reason previously we added searchBarViewController (which is a hosting controller) is because we needed to add it as a child to mapViewController to share environment and focus state (which was specific to how search works and the whole setup here). in this case there is no need for that.

private var mapMarkers: [[MapMarker]] = []
private var markerDetail: MapMarkerDetailView!
private var markerDetail: UIHostingController<MapMarkerDetailSwiftView>!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. You don't need markerDetail: UIHostingController<MapMarkerDetailSwiftView>!
just make markerDetail: UIView, and follow same setup process as for mapUserLocationBtn, mapMarkersDropdown, and Search components

baeuke
baeuke previously requested changes May 3, 2025

self.view.addSubViews([mapView, mapUserLocationButton, mapMarkersDropdownButton, markerDetail, searchResultsView, searchBar])
self.view.addSubViews([mapView, mapUserLocationButton, mapMarkersDropdownButton, markerDetail.view, searchResultsView, searchBar])
setupSubviews()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when consistent, here you add just markerDetail, not markerDetail.view

import MapKit
import SwiftUI

// MARK: - MapMarkerDetailSwiftView

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove MARK

Comment on lines +17 to +18
var onClose: (() -> Void)?
var body: some View {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline between onClose and body

var marker: MapMarker?
var onClose: (() -> Void)?
var body: some View {
ZStack {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ZStack necessary?

Comment on lines +46 to +57
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)
}
}()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this is a private helper function?

Comment on lines +72 to +79
Button {
onClose?()
} label: {
Image(systemName: "xmark")
.font(.system(size: 16))
.foregroundStyle(Color.secondary)
.padding(.trailing, 4)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use trailing closure syntax:

Button(action: {
}) {
...
}

Comment on lines +91 to +107
HStack {
HStack(spacing: 8) {
Image(systemName: "clock")
.font(.system(size: 12))
.foregroundColor(.secondary)
.rotationEffect(.init(degrees: 90))
openStatusButton
}

Spacer()

locationInfoView

Spacer()

categoryView
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the outer HStack necessary? Could we put lines 100-106 within the nested HStack?


private var openStatusButton: some View {
Capsule()
.fill(marker?.isOpen ?? false ? Color.blue : Color(red: 0.4, green: 0.5, blue: 0.9))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Color.blue.blue?

Comment on lines +140 to +150
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)
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bring .font(Font(BMFont.regular(12))) and .foregroundColor(.primary) out and apply it to Group?

Comment on lines +154 to +194
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"
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a icon() method on a MapMarker that returns a UIImage? maybe use that?

@Chhumbucket Chhumbucket changed the title BER-80: Converting MapMarkerDetailView into SwiftUI BER-80: Converting MapMarkerDetailView into SwiftUI [WIP] May 25, 2025
@Chhumbucket
Chhumbucket requested a review from baeuke May 30, 2025 22:27
@Chhumbucket

Chhumbucket commented May 30, 2025

Copy link
Copy Markdown
Collaborator Author

Let me know how you like the UI

Screen.Recording.2025-05-30.at.3.23.57.PM.mov

Comment thread berkeley-mobile/Map/MapMarkerDetailSwiftView.swift Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-06-07.at.22.20.03.mp4

The MapMarkerDetailSwiftView is centered not aligned at the bottom.

Comment thread berkeley-mobile/Map/MapMarkerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMarkerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMarkerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMarkerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMarkerDetailSwiftView.swift
Comment thread berkeley-mobile/Map/MapMarkerDetailSwiftView.swift Outdated
Comment thread berkeley-mobile/Map/MapMarkerDetailSwiftView.swift Outdated
Comment on lines +143 to +150
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)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need a Group. Apply view modifiers directly on the Text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants