Skip to content

Commit

Permalink
Chore:wrench:: #32 Seperate searchedView
Browse files Browse the repository at this point in the history
- MapView에서 검색한 결과만을 다루는 SearchedView 분리
- locationManager의 queryString의 유무가 아닌 isSearching 변수로 검색 중인지 여부 판단
- dismissSearch로 좌표 선택 완료시 자동으로 검색 종료 상태로 전환
  • Loading branch information
taek0622 committed Jun 13, 2023
1 parent 0906d0a commit e5e998e
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions Nav/View/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,7 @@ struct MapView: View {
annotationItems: mockDatas) {
data in MapMarker(coordinate: data.coordinate)
}

if locationManager.searchQuery != "" {
List(locationManager.completions) { completion in
Button {
locationManager.loadAddressCoordinate(completion) { location in
withAnimation {
region = location
}
}
locationManager.searchQuery = ""
} label: {
VStack(alignment: .leading) {
Text(completion.title)
if completion.subtitle != "" {
Text(completion.subtitle)
.font(.subheadline)
.foregroundColor(.gray)
}
}
}
}
}
SearchedView(locationManager: locationManager, region: $region)
}
.navigationTitle("NAV")
.searchable(
Expand All @@ -55,6 +34,37 @@ struct MapView: View {
}
}

private struct SearchedView: View {
let locationManager: LocationManager
@Binding var region: MKCoordinateRegion
@Environment(\.isSearching) private var isSearching
@Environment(\.dismissSearch) private var dismissSearch

var body: some View {
if isSearching {
List(locationManager.completions) { completion in
Button {
locationManager.loadAddressCoordinate(completion) { location in
withAnimation {
region = location
}
}
dismissSearch()
} label: {
VStack(alignment: .leading) {
Text(completion.title)
if completion.subtitle != "" {
Text(completion.subtitle)
.font(.subheadline)
.foregroundColor(.gray)
}
}
}
}
}
}
}

struct MapView_Previews: PreviewProvider {
static var previews: some View {
MapView()
Expand Down

0 comments on commit e5e998e

Please sign in to comment.