From 8b9eed4cfd78491f09ee67535cb91e1a6cafff1f Mon Sep 17 00:00:00 2001 From: Caleb Rasmussen Date: Wed, 13 Nov 2024 13:27:13 -0800 Subject: [PATCH 1/3] Disable search autocorrect. --- Shared/Samples/Geocode offline/GeocodeOfflineView.swift | 1 + Shared/Samples/Query feature table/QueryFeatureTableView.swift | 3 ++- Shared/Samples/Search for web map/SearchForWebMapView.swift | 1 + Shared/Supporting Files/Views/CategoriesView.swift | 1 + Shared/Supporting Files/Views/FavoritesView.swift | 1 + 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Shared/Samples/Geocode offline/GeocodeOfflineView.swift b/Shared/Samples/Geocode offline/GeocodeOfflineView.swift index 3e8265e7e..2d75b294c 100644 --- a/Shared/Samples/Geocode offline/GeocodeOfflineView.swift +++ b/Shared/Samples/Geocode offline/GeocodeOfflineView.swift @@ -46,6 +46,7 @@ struct GeocodeOfflineView: View { var body: some View { GeocodeMapView(model: model, viewpoint: $viewpoint) .searchable(text: $searchText, prompt: "Type in an address") + .autocorrectionDisabled() .onSubmit(of: .search) { submittedSearchText = searchText } diff --git a/Shared/Samples/Query feature table/QueryFeatureTableView.swift b/Shared/Samples/Query feature table/QueryFeatureTableView.swift index 7d8019456..175d1d5ba 100644 --- a/Shared/Samples/Query feature table/QueryFeatureTableView.swift +++ b/Shared/Samples/Query feature table/QueryFeatureTableView.swift @@ -29,7 +29,8 @@ struct QueryFeatureTableView: View { MapView(map: model.map) .errorAlert(presentingError: $error) // Makes the search bar. - .searchable(text: $searchBarText, prompt: Text("Search state names")) + .searchable(text: $searchBarText, prompt: "Search state names") + .autocorrectionDisabled() .onSubmit(of: .search) { model.currentQuery = searchBarText } diff --git a/Shared/Samples/Search for web map/SearchForWebMapView.swift b/Shared/Samples/Search for web map/SearchForWebMapView.swift index acb0d7c4a..bc5fd5b94 100644 --- a/Shared/Samples/Search for web map/SearchForWebMapView.swift +++ b/Shared/Samples/Search for web map/SearchForWebMapView.swift @@ -74,6 +74,7 @@ struct SearchForWebMapView: View { placement: .navigationBarDrawer(displayMode: .always), prompt: "Web Maps" ) + .autocorrectionDisabled() .task(id: query) { // Load new results when the query changes. resultsAreLoading = true diff --git a/Shared/Supporting Files/Views/CategoriesView.swift b/Shared/Supporting Files/Views/CategoriesView.swift index 2558ffb65..9774ea118 100644 --- a/Shared/Supporting Files/Views/CategoriesView.swift +++ b/Shared/Supporting Files/Views/CategoriesView.swift @@ -140,6 +140,7 @@ private extension CategoriesView { } } .searchable(text: $query, placement: .navigationBarDrawer(displayMode: .always)) + .autocorrectionDisabled() .scrollDismissesKeyboard(.immediately) } } diff --git a/Shared/Supporting Files/Views/FavoritesView.swift b/Shared/Supporting Files/Views/FavoritesView.swift index 7ffe9a75c..db5da9bce 100644 --- a/Shared/Supporting Files/Views/FavoritesView.swift +++ b/Shared/Supporting Files/Views/FavoritesView.swift @@ -132,6 +132,7 @@ private extension FavoritesView { } } .searchable(text: $query, placement: .navigationBarDrawer(displayMode: .always)) + .autocorrectionDisabled() } } } From 1a13ea07864ca90e39fb4ae74496e8002809030a Mon Sep 17 00:00:00 2001 From: Caleb Rasmussen Date: Wed, 13 Nov 2024 16:44:50 -0800 Subject: [PATCH 2/3] Fix bolded name bug. --- Shared/Supporting Files/Views/SampleLink.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Shared/Supporting Files/Views/SampleLink.swift b/Shared/Supporting Files/Views/SampleLink.swift index ad4dcf664..673fa7a05 100644 --- a/Shared/Supporting Files/Views/SampleLink.swift +++ b/Shared/Supporting Files/Views/SampleLink.swift @@ -131,11 +131,18 @@ private extension String { /// - Parameter substring: The substring to bold. /// - Returns: The attributed string with the bolded substring. func boldingFirstOccurrence(of substring: String) -> AttributedString { - if let range = localizedStandardRange(of: substring.trimmingCharacters(in: .whitespacesAndNewlines)), - let boldedString = try? AttributedString(markdown: replacingCharacters(in: range, with: "**\(self[range])**")) { - return boldedString - } else { - return AttributedString(self) + var attributedString = AttributedString(self) + + let trimmedSubstring = substring.trimmingCharacters(in: .whitespacesAndNewlines) + if let range = localizedStandardRange(of: trimmedSubstring) { + let substring = self[range] + + if let boldedSubstring = try? AttributedString(markdown: "**\(substring)**"), + let attributedRange = attributedString.range(of: substring) { + attributedString.replaceSubrange(attributedRange, with: boldedSubstring) + } } + + return attributedString } } From 49e992dc225bd6079ec900cce31245cb96405a78 Mon Sep 17 00:00:00 2001 From: Caleb Rasmussen Date: Thu, 14 Nov 2024 17:19:01 -0800 Subject: [PATCH 3/3] Apply suggestions from code review. https://github.com/Esri/arcgis-maps-sdk-swift-samples/pull/548#discussion_r1843057605 https://github.com/Esri/arcgis-maps-sdk-swift-samples/pull/548#discussion_r1843058696 --- Shared/Supporting Files/Views/SampleLink.swift | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Shared/Supporting Files/Views/SampleLink.swift b/Shared/Supporting Files/Views/SampleLink.swift index 673fa7a05..85ad276e7 100644 --- a/Shared/Supporting Files/Views/SampleLink.swift +++ b/Shared/Supporting Files/Views/SampleLink.swift @@ -134,13 +134,10 @@ private extension String { var attributedString = AttributedString(self) let trimmedSubstring = substring.trimmingCharacters(in: .whitespacesAndNewlines) - if let range = localizedStandardRange(of: trimmedSubstring) { - let substring = self[range] - - if let boldedSubstring = try? AttributedString(markdown: "**\(substring)**"), - let attributedRange = attributedString.range(of: substring) { - attributedString.replaceSubrange(attributedRange, with: boldedSubstring) - } + if let range = localizedStandardRange(of: trimmedSubstring), + let boldedSubstring = try? AttributedString(markdown: "**\(self[range])**"), + let attributedRange = attributedString.range(of: self[range]) { + attributedString.replaceSubrange(attributedRange, with: boldedSubstring) } return attributedString