Skip to content

Commit 8c34d17

Browse files
authored
Merge pull request #549 from Esri/Caleb/Update-FavoriteCategory
[Update] Conditionally hide favorites category
2 parents f0f112c + 07add72 commit 8c34d17

File tree

6 files changed

+32
-59
lines changed

6 files changed

+32
-59
lines changed

Samples.xcodeproj/project.pbxproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
D72C43F32AEB066D00B6157B /* GeocodeOfflineView.Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72C43F22AEB066D00B6157B /* GeocodeOfflineView.Model.swift */; };
280280
D72F272E2ADA1E4400F906DA /* AugmentRealityToShowTabletopSceneView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72F272B2ADA1E4400F906DA /* AugmentRealityToShowTabletopSceneView.swift */; };
281281
D72F27302ADA1E9900F906DA /* AugmentRealityToShowTabletopSceneView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D72F272B2ADA1E4400F906DA /* AugmentRealityToShowTabletopSceneView.swift */; };
282+
D72FE7032CE6D05600BBC0FE /* AppFavorites.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72FE7022CE6D05600BBC0FE /* AppFavorites.swift */; };
282283
D731F3C12AD0D2AC00A8431E /* IdentifyGraphicsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D731F3C02AD0D2AC00A8431E /* IdentifyGraphicsView.swift */; };
283284
D731F3C22AD0D2BB00A8431E /* IdentifyGraphicsView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D731F3C02AD0D2AC00A8431E /* IdentifyGraphicsView.swift */; };
284285
D7337C5A2ABCFDB100A5D865 /* StyleSymbolsFromMobileStyleFileView.SymbolOptionsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7337C592ABCFDB100A5D865 /* StyleSymbolsFromMobileStyleFileView.SymbolOptionsListView.swift */; };
@@ -435,8 +436,6 @@
435436
D7BA38922BFBC4F0009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7BA38902BFBC476009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift */; };
436437
D7BA38972BFBFC0F009954F5 /* QueryRelatedFeaturesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7BA38932BFBFC0F009954F5 /* QueryRelatedFeaturesView.swift */; };
437438
D7BA389A2BFBFC2E009954F5 /* QueryRelatedFeaturesView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7BA38932BFBFC0F009954F5 /* QueryRelatedFeaturesView.swift */; };
438-
D7BA8C442B2A4DAA00018633 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7BA8C432B2A4DAA00018633 /* Array.swift */; };
439-
D7BA8C462B2A8ACA00018633 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7BA8C452B2A8ACA00018633 /* String.swift */; };
440439
D7BB3DD22C5D781800FFCD56 /* SaveTheBay.geodatabase in Resources */ = {isa = PBXBuildFile; fileRef = D7BB3DD02C5D781800FFCD56 /* SaveTheBay.geodatabase */; settings = {ASSET_TAGS = (EditGeodatabaseWithTransactions, ); }; };
441440
D7BE7E6F2CC19CC3006DDB0C /* AddTiledLayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7BE7E6B2CC19CC3006DDB0C /* AddTiledLayerView.swift */; };
442441
D7BE7E722CC19CE5006DDB0C /* AddTiledLayerView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7BE7E6B2CC19CC3006DDB0C /* AddTiledLayerView.swift */; };
@@ -967,6 +966,7 @@
967966
D7232EE02AC1E5AA0079ABFF /* PlayKMLTourView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayKMLTourView.swift; sourceTree = "<group>"; };
968967
D72C43F22AEB066D00B6157B /* GeocodeOfflineView.Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeocodeOfflineView.Model.swift; sourceTree = "<group>"; };
969968
D72F272B2ADA1E4400F906DA /* AugmentRealityToShowTabletopSceneView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AugmentRealityToShowTabletopSceneView.swift; sourceTree = "<group>"; };
969+
D72FE7022CE6D05600BBC0FE /* AppFavorites.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppFavorites.swift; sourceTree = "<group>"; };
970970
D731F3C02AD0D2AC00A8431E /* IdentifyGraphicsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdentifyGraphicsView.swift; sourceTree = "<group>"; };
971971
D7337C592ABCFDB100A5D865 /* StyleSymbolsFromMobileStyleFileView.SymbolOptionsListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyleSymbolsFromMobileStyleFileView.SymbolOptionsListView.swift; sourceTree = "<group>"; };
972972
D7337C5F2ABD142D00A5D865 /* ShowMobileMapPackageExpirationDateView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowMobileMapPackageExpirationDateView.swift; sourceTree = "<group>"; };
@@ -1050,8 +1050,6 @@
10501050
D7B759B22B1FFBE300017FDD /* FavoritesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesView.swift; sourceTree = "<group>"; };
10511051
D7BA38902BFBC476009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditFeaturesWithFeatureLinkedAnnotationView.Model.swift; sourceTree = "<group>"; };
10521052
D7BA38932BFBFC0F009954F5 /* QueryRelatedFeaturesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryRelatedFeaturesView.swift; sourceTree = "<group>"; };
1053-
D7BA8C432B2A4DAA00018633 /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = "<group>"; };
1054-
D7BA8C452B2A8ACA00018633 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
10551053
D7BB3DD02C5D781800FFCD56 /* SaveTheBay.geodatabase */ = {isa = PBXFileReference; lastKnownFileType = file; path = SaveTheBay.geodatabase; sourceTree = "<group>"; };
10561054
D7BE7E6B2CC19CC3006DDB0C /* AddTiledLayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddTiledLayerView.swift; sourceTree = "<group>"; };
10571055
D7BEBA9E2CBD9CCA00F882E7 /* MontereyElevation.dt2 */ = {isa = PBXFileReference; lastKnownFileType = text; path = MontereyElevation.dt2; sourceTree = "<group>"; };
@@ -1166,8 +1164,6 @@
11661164
00181B442846AD3900654571 /* Extensions */ = {
11671165
isa = PBXGroup;
11681166
children = (
1169-
D7BA8C432B2A4DAA00018633 /* Array.swift */,
1170-
D7BA8C452B2A8ACA00018633 /* String.swift */,
11711167
00181B452846AD7100654571 /* View+ErrorAlert.swift */,
11721168
);
11731169
path = Extensions;
@@ -1416,6 +1412,7 @@
14161412
0074ABC028174F430037244A /* Models */ = {
14171413
isa = PBXGroup;
14181414
children = (
1415+
D72FE7022CE6D05600BBC0FE /* AppFavorites.swift */,
14191416
00CCB8A4285BAF8700BBAB70 /* OnDemandResource.swift */,
14201417
0074ABC128174F430037244A /* Sample.swift */,
14211418
);
@@ -3455,7 +3452,6 @@
34553452
D75E5EF12CC049D500252595 /* EditFeaturesUsingFeatureFormsView.swift in Sources */,
34563453
D7352F8E2BD992C40013FFEF /* MonitorChangesToDrawStatusView.swift in Sources */,
34573454
F111CCC1288B5D5600205358 /* DisplayMapFromMobileMapPackageView.swift in Sources */,
3458-
D7BA8C462B2A8ACA00018633 /* String.swift in Sources */,
34593455
D76495212B74687E0042699E /* ValidateUtilityNetworkTopologyView.Model.swift in Sources */,
34603456
D7D9FCF62BF2CC8600F972A2 /* FilterByDefinitionExpressionOrDisplayFilterView.swift in Sources */,
34613457
D7337C5A2ABCFDB100A5D865 /* StyleSymbolsFromMobileStyleFileView.SymbolOptionsListView.swift in Sources */,
@@ -3522,7 +3518,6 @@
35223518
D77570C02A2942F800F490CD /* AnimateImagesWithImageOverlayView.swift in Sources */,
35233519
D7848EFE2CBD986400F6F546 /* AddElevationSourceFromRasterView.swift in Sources */,
35243520
D7054AE92ACCCB6C007235BA /* Animate3DGraphicView.SettingsView.swift in Sources */,
3525-
D7BA8C442B2A4DAA00018633 /* Array.swift in Sources */,
35263521
D78FA4942C3C88880079313E /* CreateDynamicBasemapGalleryView.Views.swift in Sources */,
35273522
E0EA0B772866390E00C9621D /* ProjectGeometryView.swift in Sources */,
35283523
D74C8BFE2ABA5605007C76B8 /* StyleSymbolsFromMobileStyleFileView.swift in Sources */,
@@ -3554,6 +3549,7 @@
35543549
D7781D4B2B7ECCB700E53C51 /* NavigateRouteWithReroutingView.Model.swift in Sources */,
35553550
4D2ADC6929C50C4C003B367F /* AddDynamicEntityLayerView.SettingsView.swift in Sources */,
35563551
1C42E04729D2396B004FC4BE /* ShowPopupView.swift in Sources */,
3552+
D72FE7032CE6D05600BBC0FE /* AppFavorites.swift in Sources */,
35573553
79302F872A1ED71B0002336A /* CreateAndSaveKMLView.Views.swift in Sources */,
35583554
D73FC0FD2AD4A18D0067A19B /* CreateMobileGeodatabaseView.swift in Sources */,
35593555
D7F2A02F2CD00F1C0008D981 /* ApplyDictionaryRendererToFeatureLayerView.swift in Sources */,

Shared/Supporting Files/Extensions/String.swift

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

Shared/Supporting Files/Extensions/Array.swift renamed to Shared/Supporting Files/Models/AppFavorites.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import Foundation
15+
import SwiftUI
16+
17+
/// A property wrapper for accessing and setting the names of the favorite samples.
18+
@propertyWrapper
19+
struct AppFavorites: DynamicProperty {
20+
/// The favorite sample names JSON string loaded from user defaults.
21+
@AppStorage("favoriteSampleNames") private var favoriteNamesJSON = ""
22+
23+
var wrappedValue: [String] {
24+
get { .init(jsonString: favoriteNamesJSON) }
25+
nonmutating set { favoriteNamesJSON = newValue.jsonString }
26+
}
27+
}
1628

1729
/// An extension allowing an array to be used with the app storage property wrapper.
18-
extension Array<String> {
30+
private extension Array<String> {
1931
/// Creates a new array from a given raw value.
2032
/// - Parameter jsonString: The JSON representation of the array to create.
2133
init(jsonString: String) {

Shared/Supporting Files/Views/CategoriesView.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ struct CategoriesView: View {
2424
/// A Boolean value indicating whether the navigation destination is showing.
2525
@State private var destinationIsPresented = false
2626

27-
/// The list of categories.
28-
private let categories: [String] = {
29-
var categories = ["All", "Favorites"]
30-
let sampleCategories = Set(SamplesApp.samples.map(\.category))
31-
categories.append(contentsOf: sampleCategories.sorted())
32-
return categories
33-
}()
27+
/// The names of the favorite samples loaded from user defaults.
28+
@AppFavorites private var favoriteNames
29+
30+
/// The list of categories generated from the samples.
31+
private let sampleCategories = Set(SamplesApp.samples.map(\.category)).sorted()
32+
33+
/// The full list of categories to show.
34+
private var categories: [String] {
35+
return (favoriteNames.isEmpty ? ["All"] : ["All", "Favorites"]) + sampleCategories
36+
}
3437

3538
var body: some View {
3639
ScrollView {
@@ -54,6 +57,7 @@ struct CategoriesView: View {
5457
)
5558
)
5659
}
60+
.animation(.default, value: categories)
5761
}
5862
.padding()
5963
}

Shared/Supporting Files/Views/FavoritesView.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ struct FavoritesView: View {
2222
@State private var addFavoriteSheetIsShowing = false
2323

2424
/// The names of the favorite samples loaded from user defaults.
25-
@AppStorage(.favoriteSampleNames) private var favoriteNamesString = ""
26-
27-
/// A helper property to decode the app storage string to an array of
28-
/// sample names.
29-
private var favoriteNames: [String] {
30-
get { .init(jsonString: favoriteNamesString) }
31-
nonmutating set { favoriteNamesString = newValue.jsonString }
32-
}
25+
@AppFavorites private var favoriteNames
3326

3427
/// A list of the favorite samples.
3528
private var favoriteSamples: [Sample] {
@@ -77,14 +70,7 @@ private extension FavoritesView {
7770
@Environment(\.dismiss) private var dismiss: DismissAction
7871

7972
/// The names of the favorite samples loaded from user defaults.
80-
@AppStorage(.favoriteSampleNames) private var favoriteNamesString = ""
81-
82-
/// A helper property to decode the app storage string to an array of
83-
/// sample names.
84-
private var favoriteNames: [String] {
85-
get { .init(jsonString: favoriteNamesString) }
86-
nonmutating set { favoriteNamesString = newValue.jsonString }
87-
}
73+
@AppFavorites private var favoriteNames
8874

8975
/// The search query in the search bar.
9076
@State private var query = ""

Shared/Supporting Files/Views/SampleLink.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,7 @@ private extension SampleLink {
6161
@State private var isShowingDescription = false
6262

6363
/// The names of the favorite samples loaded from user defaults.
64-
@AppStorage(.favoriteSampleNames) private var favoriteNamesString = ""
65-
66-
/// A helper property to decode the app storage string to an array of
67-
/// sample names.
68-
private var favoriteNames: [String] {
69-
get { .init(jsonString: favoriteNamesString) }
70-
nonmutating set { favoriteNamesString = newValue.jsonString }
71-
}
64+
@AppFavorites private var favoriteNames
7265

7366
/// A Boolean value indicating whether the sample is a favorite.
7467
private var sampleIsFavorite: Bool {

0 commit comments

Comments
 (0)