From c3b868a87b54506fee3c9fe6d47f9b82eb09ff97 Mon Sep 17 00:00:00 2001 From: taek0622 Date: Fri, 2 Jun 2023 16:35:05 +0900 Subject: [PATCH] Chore:wrench:: #32 Modify searching variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 검색용 변수를 searchQueryString에서 AddressSearcher의 queryString으로 변경 --- Nav/View/MapView.swift | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Nav/View/MapView.swift b/Nav/View/MapView.swift index fef6bde..89e84f4 100644 --- a/Nav/View/MapView.swift +++ b/Nav/View/MapView.swift @@ -7,9 +7,7 @@ import MapKit import SwiftUI struct MapView: View { - private var mockDatas: [MockDatum] = MockDatum.allData - - @State var searchQueryString = "" + @ObservedObject var addressSearcher = AddressSearcher() @State var isEditing = false // 서울 좌표 @@ -18,6 +16,8 @@ struct MapView: View { @State private var isClickedYes: Bool = false @State private var isShowModal: Bool = false + private var mockDatas: [MockDatum] = MockDatum.allData + var body: some View { NavigationView { ZStack { @@ -28,23 +28,36 @@ struct MapView: View { } if isEditing { - List { - Text(searchQueryString) + List(addressSearcher.completions) { completion in + Button { + // 핀 포커싱 기능 추가 + addressSearcher.searchQuery = "" + } label: { + VStack(alignment: .leading) { + Text(completion.title) + if completion.subtitle != "" { + Text(completion.subtitle) + .font(.subheadline) + .foregroundColor(.gray) + } + } + } } } } .navigationTitle("NAV") .searchable( - text: $searchQueryString, + text: $addressSearcher.searchQuery, placement: .navigationBarDrawer, prompt: "검색" ) - .onChange(of: searchQueryString) { newValue in + .onChange(of: addressSearcher.searchQuery) { newValue in isEditing = (newValue != "" ? true : false) } } } } + struct MapView_Previews: PreviewProvider { static var previews: some View { MapView()