Skip to content

Commit 452c08e

Browse files
authored
Merge pull request #228 from Esri/Caleb/Update-SampleViewerSearchBar
[Update] Improve Sample Viewer search
2 parents ae2dc52 + 62e0b96 commit 452c08e

File tree

10 files changed

+277
-128
lines changed

10 files changed

+277
-128
lines changed

Samples.xcodeproj/project.pbxproj

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
0005580A2817C51E00224BC6 /* SampleDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 000558092817C51E00224BC6 /* SampleDetailView.swift */; };
1111
00181B462846AD7100654571 /* View+Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00181B452846AD7100654571 /* View+Alert.swift */; };
1212
001C6DE127FE8A9400D472C2 /* AppSecrets.swift.masque in Sources */ = {isa = PBXBuildFile; fileRef = 001C6DD827FE585A00D472C2 /* AppSecrets.swift.masque */; };
13+
00273CF42A82AB5900A7A77D /* SamplesSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00273CF32A82AB5900A7A77D /* SamplesSearchView.swift */; };
14+
00273CF62A82AB8700A7A77D /* SampleRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00273CF52A82AB8700A7A77D /* SampleRow.swift */; };
1315
0039A4E92885C50300592C86 /* AddSceneLayerFromServiceView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = E066DD3F28610F55004D3D5B /* AddSceneLayerFromServiceView.swift */; };
1416
0039A4EA2885C50300592C86 /* ClipGeometryView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = E000E75F2869E33D005D87C5 /* ClipGeometryView.swift */; };
1517
0039A4EB2885C50300592C86 /* CreatePlanarAndGeodeticBuffersView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = E004A6EC2849556E002A1FE6 /* CreatePlanarAndGeodeticBuffersView.swift */; };
@@ -51,6 +53,7 @@
5153
00B042E8282EDC690072E1B4 /* SetBasemapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B042E5282EDC690072E1B4 /* SetBasemapView.swift */; };
5254
00B04FB5283EEBA80026C882 /* DisplayOverviewMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B04FB4283EEBA80026C882 /* DisplayOverviewMapView.swift */; };
5355
00C43AED2947DC350099AE34 /* ArcGISToolkit in Frameworks */ = {isa = PBXBuildFile; productRef = 00C43AEC2947DC350099AE34 /* ArcGISToolkit */; };
56+
00C7993B2A845AAF00AFE342 /* Sidebar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C7993A2A845AAF00AFE342 /* Sidebar.swift */; };
5457
00C94A0D28B53DE1004E42D9 /* raster-file in Resources */ = {isa = PBXBuildFile; fileRef = 00C94A0C28B53DE1004E42D9 /* raster-file */; settings = {ASSET_TAGS = (AddRasterFromFile, ); }; };
5558
00CB9138284814A4005C2C5D /* SearchWithGeocodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00CB9137284814A4005C2C5D /* SearchWithGeocodeView.swift */; };
5659
00CCB8A5285BAF8700BBAB70 /* OnDemandResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00CCB8A4285BAF8700BBAB70 /* OnDemandResource.swift */; };
@@ -134,10 +137,7 @@
134137
88F93CC129C3D59D0006B28E /* SketchOnMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88F93CC029C3D59C0006B28E /* SketchOnMapView.swift */; };
135138
88F93CC229C4D3480006B28E /* SketchOnMapView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 88F93CC029C3D59C0006B28E /* SketchOnMapView.swift */; };
136139
D701D72C2A37C7F7006FF0C8 /* bradley_low_3ds in Resources */ = {isa = PBXBuildFile; fileRef = D701D72B2A37C7F7006FF0C8 /* bradley_low_3ds */; settings = {ASSET_TAGS = (ShowViewshedFromGeoelementInScene, ); }; };
137-
D70BE5792A5624A80022CA02 /* CategoryGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE5782A5624A80022CA02 /* CategoryGridView.swift */; };
138-
D70BE57F2A5753B70022CA02 /* SampleListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE57E2A5753B70022CA02 /* SampleListView.swift */; };
139-
D70BE5832A5766CA0022CA02 /* CategoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE5822A5766C90022CA02 /* CategoryView.swift */; };
140-
D70BE5882A5787530022CA02 /* CategoryView+Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE5872A5787530022CA02 /* CategoryView+Search.swift */; };
140+
D70BE5792A5624A80022CA02 /* CategoriesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70BE5782A5624A80022CA02 /* CategoriesView.swift */; };
141141
D710996D2A27D9210065A1C1 /* DensifyAndGeneralizeGeometryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D710996C2A27D9210065A1C1 /* DensifyAndGeneralizeGeometryView.swift */; };
142142
D710996E2A27D9B30065A1C1 /* DensifyAndGeneralizeGeometryView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D710996C2A27D9210065A1C1 /* DensifyAndGeneralizeGeometryView.swift */; };
143143
D71099702A2802FA0065A1C1 /* DensifyAndGeneralizeGeometryView.SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D710996F2A2802FA0065A1C1 /* DensifyAndGeneralizeGeometryView.SettingsView.swift */; };
@@ -380,6 +380,8 @@
380380
000558092817C51E00224BC6 /* SampleDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleDetailView.swift; sourceTree = "<group>"; };
381381
00181B452846AD7100654571 /* View+Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Alert.swift"; sourceTree = "<group>"; };
382382
001C6DD827FE585A00D472C2 /* AppSecrets.swift.masque */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AppSecrets.swift.masque; sourceTree = "<group>"; };
383+
00273CF32A82AB5900A7A77D /* SamplesSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SamplesSearchView.swift; sourceTree = "<group>"; };
384+
00273CF52A82AB8700A7A77D /* SampleRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleRow.swift; sourceTree = "<group>"; };
383385
003D7C342821EBCC009DDFD2 /* masquerade */ = {isa = PBXFileReference; lastKnownFileType = text; path = masquerade; sourceTree = "<group>"; };
384386
003D7C352821EBCC009DDFD2 /* GenerateSampleViewSourceCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateSampleViewSourceCode.swift; sourceTree = "<group>"; };
385387
0042E24228E4BF8F001F33D6 /* ShowViewshedFromPointInSceneView.Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowViewshedFromPointInSceneView.Model.swift; sourceTree = "<group>"; };
@@ -397,6 +399,7 @@
397399
00B04272282EC59E0072E1B4 /* AboutView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
398400
00B042E5282EDC690072E1B4 /* SetBasemapView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetBasemapView.swift; sourceTree = "<group>"; };
399401
00B04FB4283EEBA80026C882 /* DisplayOverviewMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayOverviewMapView.swift; sourceTree = "<group>"; };
402+
00C7993A2A845AAF00AFE342 /* Sidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar.swift; sourceTree = "<group>"; };
400403
00C94A0C28B53DE1004E42D9 /* raster-file */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "raster-file"; sourceTree = "<group>"; };
401404
00CB9137284814A4005C2C5D /* SearchWithGeocodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchWithGeocodeView.swift; sourceTree = "<group>"; };
402405
00CCB8A2285AAD7D00BBAB70 /* DowloadPortalItemData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DowloadPortalItemData.swift; sourceTree = "<group>"; };
@@ -445,10 +448,7 @@
445448
883C121429C9136600062FF9 /* DownloadPreplannedMapAreaView.MapPicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadPreplannedMapAreaView.MapPicker.swift; sourceTree = "<group>"; };
446449
88F93CC029C3D59C0006B28E /* SketchOnMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SketchOnMapView.swift; sourceTree = "<group>"; };
447450
D701D72B2A37C7F7006FF0C8 /* bradley_low_3ds */ = {isa = PBXFileReference; lastKnownFileType = folder; path = bradley_low_3ds; sourceTree = "<group>"; };
448-
D70BE5782A5624A80022CA02 /* CategoryGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryGridView.swift; sourceTree = "<group>"; };
449-
D70BE57E2A5753B70022CA02 /* SampleListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleListView.swift; sourceTree = "<group>"; };
450-
D70BE5822A5766C90022CA02 /* CategoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryView.swift; sourceTree = "<group>"; };
451-
D70BE5872A5787530022CA02 /* CategoryView+Search.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CategoryView+Search.swift"; sourceTree = "<group>"; };
451+
D70BE5782A5624A80022CA02 /* CategoriesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoriesView.swift; sourceTree = "<group>"; };
452452
D710996C2A27D9210065A1C1 /* DensifyAndGeneralizeGeometryView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DensifyAndGeneralizeGeometryView.swift; sourceTree = "<group>"; };
453453
D710996F2A2802FA0065A1C1 /* DensifyAndGeneralizeGeometryView.SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DensifyAndGeneralizeGeometryView.SettingsView.swift; sourceTree = "<group>"; };
454454
D722BD212A420DAD002C2087 /* ShowExtrudedFeaturesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowExtrudedFeaturesView.swift; sourceTree = "<group>"; };
@@ -523,12 +523,13 @@
523523
isa = PBXGroup;
524524
children = (
525525
00B04272282EC59E0072E1B4 /* AboutView.swift */,
526-
D70BE5782A5624A80022CA02 /* CategoryGridView.swift */,
527-
D70BE5822A5766C90022CA02 /* CategoryView.swift */,
526+
D70BE5782A5624A80022CA02 /* CategoriesView.swift */,
528527
00E5400D27F3CCA100CF66D5 /* ContentView.swift */,
529528
000558092817C51E00224BC6 /* SampleDetailView.swift */,
530529
E041ABD6287DB04D0056009B /* SampleInfoView.swift */,
531-
D70BE57E2A5753B70022CA02 /* SampleListView.swift */,
530+
00273CF52A82AB8700A7A77D /* SampleRow.swift */,
531+
00273CF32A82AB5900A7A77D /* SamplesSearchView.swift */,
532+
00C7993A2A845AAF00AFE342 /* Sidebar.swift */,
532533
E041ABBF287CA9F00056009B /* WebView.swift */,
533534
);
534535
path = Views;
@@ -537,7 +538,6 @@
537538
00181B442846AD3900654571 /* Extensions */ = {
538539
isa = PBXGroup;
539540
children = (
540-
D70BE5872A5787530022CA02 /* CategoryView+Search.swift */,
541541
E08953F02891899600E077CF /* EnvironmentValues+SampleInfoVisibility.swift */,
542542
00181B452846AD7100654571 /* View+Alert.swift */,
543543
E0082216287755AC002AD138 /* View+Sheet.swift */,
@@ -1590,11 +1590,10 @@
15901590
D752D9462A3A6F80003EB25E /* MonitorChangesToMapLoadStatusView.swift in Sources */,
15911591
E0082217287755AC002AD138 /* View+Sheet.swift in Sources */,
15921592
00181B462846AD7100654571 /* View+Alert.swift in Sources */,
1593+
00273CF62A82AB8700A7A77D /* SampleRow.swift in Sources */,
15931594
D7ABA2FF2A32881C0021822B /* ShowViewshedFromGeoelementInSceneView.swift in Sources */,
15941595
E0FE32E728747778002C6ACA /* BrowseBuildingFloorsView.swift in Sources */,
1595-
D70BE5882A5787530022CA02 /* CategoryView+Search.swift in Sources */,
15961596
D752D95F2A3BCE06003EB25E /* DisplayMapFromPortalItemView.swift in Sources */,
1597-
D70BE5832A5766CA0022CA02 /* CategoryView.swift in Sources */,
15981597
1CAB8D4B2A3CEAB0002AA649 /* RunValveIsolationTraceView.Model.swift in Sources */,
15991598
E070A0A3286F3B6000F2B606 /* DownloadPreplannedMapAreaView.swift in Sources */,
16001599
D77570C02A2942F800F490CD /* AnimateImagesWithImageOverlayView.swift in Sources */,
@@ -1623,6 +1622,7 @@
16231622
E041ABC0287CA9F00056009B /* WebView.swift in Sources */,
16241623
E088E1572862579D00413100 /* SetSurfacePlacementModeView.swift in Sources */,
16251624
1CAF831F2A20305F000E1E60 /* ShowUtilityAssociationsView.swift in Sources */,
1625+
00C7993B2A845AAF00AFE342 /* Sidebar.swift in Sources */,
16261626
E004A6C128414332002A1FE6 /* SetViewpointRotationView.swift in Sources */,
16271627
883C121529C9136600062FF9 /* DownloadPreplannedMapAreaView.MapPicker.swift in Sources */,
16281628
1C9B74C929DB43580038B06F /* ShowRealisticLightAndShadowsView.swift in Sources */,
@@ -1633,7 +1633,7 @@
16331633
108EC04129D25B2C000F35D0 /* QueryFeatureTableView.swift in Sources */,
16341634
00B04FB5283EEBA80026C882 /* DisplayOverviewMapView.swift in Sources */,
16351635
D7CC33FF2A31475C00198EDF /* ShowLineOfSightBetweenPointsView.swift in Sources */,
1636-
D70BE5792A5624A80022CA02 /* CategoryGridView.swift in Sources */,
1636+
D70BE5792A5624A80022CA02 /* CategoriesView.swift in Sources */,
16371637
4D2ADC5D29C4F612003B367F /* ChangeMapViewBackgroundView.SettingsView.swift in Sources */,
16381638
75DD739529D38B1B0010229D /* NavigateRouteView.swift in Sources */,
16391639
D75362D22A1E886700D83028 /* ApplyUniqueValueRendererView.swift in Sources */,
@@ -1657,7 +1657,6 @@
16571657
00B042E8282EDC690072E1B4 /* SetBasemapView.swift in Sources */,
16581658
E004A6E62846A61F002A1FE6 /* StyleGraphicsWithSymbolsView.swift in Sources */,
16591659
E088E1742863B5F800413100 /* GenerateOfflineMapView.swift in Sources */,
1660-
D70BE57F2A5753B70022CA02 /* SampleListView.swift in Sources */,
16611660
0074ABC428174F430037244A /* Sample.swift in Sources */,
16621661
00A7A14A2A2FC5B700F035F7 /* DisplayContentOfUtilityNetworkContainerView.Model.swift in Sources */,
16631662
E004A6F0284E4B9B002A1FE6 /* DownloadVectorTilesToLocalCacheView.swift in Sources */,
@@ -1667,6 +1666,7 @@
16671666
1C19B4F52A578E46001D2506 /* CreateLoadReportView.Model.swift in Sources */,
16681667
0042E24528E4F82C001F33D6 /* ShowViewshedFromPointInSceneView.ViewshedSettingsView.swift in Sources */,
16691668
1C9B74D929DB54560038B06F /* ChangeCameraControllerView.swift in Sources */,
1669+
00273CF42A82AB5900A7A77D /* SamplesSearchView.swift in Sources */,
16701670
D78666AD2A2161F100C60110 /* FindNearestVertexView.swift in Sources */,
16711671
D744FD172A2112D90084A66C /* CreateConvexHullAroundPointsView.swift in Sources */,
16721672
00CB9138284814A4005C2C5D /* SearchWithGeocodeView.swift in Sources */,

Scripts/GenerateSampleViewSourceCode.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ private struct SampleMetadata: Decodable {
4141
let offlineData: [String]?
4242
/// The tags and relevant APIs of the sample.
4343
let keywords: [String]
44+
/// The relevant APIs of the sample.
45+
let relevantApis: [String]
4446
}
4547

4648
extension SampleMetadata {
@@ -57,6 +59,16 @@ extension SampleMetadata {
5759
// E.g., DisplayMapView -> DisplayMap
5860
viewName.dropLast(4)
5961
}
62+
63+
/// The tags of a sample.
64+
/// - Note: See common-samples/wiki/README.metadata.json#keywords.
65+
/// The keywords in the sample metadata combines Tags and Relevant APIs
66+
/// from the README. This is done in Scripts/CI/common.py by appending the
67+
/// relevant APIs to the tags. Therefore, dropping the relevant APIs will
68+
/// give the tags.
69+
var tags: Array<String>.SubSequence {
70+
keywords.dropLast(relevantApis.count)
71+
}
6072
}
6173

6274
// MARK: Script Entry
@@ -116,7 +128,7 @@ private let sampleStructs = sampleMetadata
116128
var category: String { \"\(sample.category)\" }
117129
var description: String { \"\(sample.description)\" }
118130
var snippets: [String] { \(sample.snippets) }
119-
var tags: Set<String> { \(sample.keywords) }
131+
var tags: Set<String> { \(sample.tags) }
120132
\(portalItemIDs.isEmpty ? "" : "var hasDependencies: Bool { true }\n")
121133
func makeBody() -> AnyView { .init(\(sample.viewName)()) }
122134
}

Shared/Supporting Files/Extensions/CategoryView+Search.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

Shared/Supporting Files/Models/Sample.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protocol Sample {
2828
/// The relative paths to the code snippets.
2929
var snippets: [String] { get }
3030

31-
/// The tags and relevant APIs of the sample.
31+
/// The tags of the sample.
3232
var tags: Set<String> { get }
3333

3434
/// A Boolean value that indicates whether a sample has offline data dependencies.

Shared/Supporting Files/Views/CategoryGridView.swift renamed to Shared/Supporting Files/Views/CategoriesView.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import SwiftUI
1616

17-
struct CategoryGridView: View {
17+
struct CategoriesView: View {
1818
/// All samples that will be shown in the categories.
1919
private let samples: [Sample]
2020

@@ -38,7 +38,7 @@ struct CategoryGridView: View {
3838
LazyVGrid(columns: columns) {
3939
ForEach(categories, id: \.self) { category in
4040
NavigationLink {
41-
SampleListView(samples: samples.filter { $0.category == category })
41+
CategoryList(samples: samples.filter { $0.category == category })
4242
.navigationTitle(category)
4343
} label: {
4444
CategoryTitleView(category: category)
@@ -49,12 +49,29 @@ struct CategoryGridView: View {
4949
.buttonStyle(.plain)
5050
}
5151
}
52-
.padding(8)
52+
.padding()
5353
}
5454
}
5555
}
5656

57-
private extension CategoryGridView {
57+
private extension CategoriesView {
58+
struct CategoryList: View {
59+
/// The samples in a category.
60+
let samples: [Sample]
61+
62+
var body: some View {
63+
List(samples, id: \.name) { sample in
64+
NavigationLink {
65+
SampleDetailView(sample: sample)
66+
.id(sample.name)
67+
} label: {
68+
SampleRow(name: AttributedString(sample.name), description: AttributedString(sample.description))
69+
}
70+
}
71+
.listStyle(.sidebar)
72+
}
73+
}
74+
5875
struct CategoryTitleView: View {
5976
/// The category name used to load the images from assets.
6077
let category: String

Shared/Supporting Files/Views/ContentView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct ContentView: View {
3939
}
4040

4141
var sidebar: some View {
42-
CategoryView(samples: samples, query: $query)
43-
.searchable(text: $query, prompt: "Search By Sample Name")
42+
Sidebar(samples: samples, query: query)
43+
.searchable(text: $query)
4444
}
4545

4646
var detail: some View {

0 commit comments

Comments
 (0)