File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
Shared/Supporting Files/Views Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -24,13 +24,17 @@ 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+ @AppStorage ( . favoriteSampleNames) private var favoriteNamesString = " "
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+ let shouldShowFavorites = Array ( jsonString: favoriteNamesString) . isEmpty
36+ return ( shouldShowFavorites ? [ " All " ] : [ " All " , " Favorites " ] ) + sampleCategories
37+ }
3438
3539 var body : some View {
3640 ScrollView {
@@ -54,6 +58,7 @@ struct CategoriesView: View {
5458 )
5559 )
5660 }
61+ . animation ( . default, value: categories)
5762 }
5863 . padding ( )
5964 }
You can’t perform that action at this time.
0 commit comments