@@ -7,65 +7,60 @@ struct TagsScreen: View
77{
88 @ObservedObject var store = TagStore ( )
99
10- /// Used in the extra example that shrinks the collectionView to fit its content
11- var shrinkToSize : Bool = false
12- @State var contentSize : CGSize ? // This state variable is handed to the collectionView to allow it to store the content size
13- ///
14-
1510 var body : some View
1611 {
17- VStack ( alignment: . leading, spacing: 20 )
18- {
19- HStack
12+ ScrollView ( . vertical) {
13+ VStack ( alignment: . leading, spacing: 20 )
2014 {
21- Spacer ( )
22- Text ( " Tap this button to reload new tags " )
15+ Text ( " This screen has an ASCollectionView embedded into a SwiftUI scrollview " )
16+ . multilineTextAlignment ( . center)
17+ . fixedSize ( horizontal: false , vertical: true )
18+ . frame ( maxWidth: . infinity)
2319 . padding ( )
24- . background ( Color ( . secondarySystemBackground) )
25- Spacer ( )
26- }
27- . onTapGesture
28- {
29- withAnimation ( self . shrinkToSize ? nil : . default) {
20+ HStack
21+ {
22+ Spacer ( )
23+ Text ( " Tap this button to reload new tags " )
24+ . padding ( )
25+ . background ( Color ( . secondarySystemBackground) )
26+ Spacer ( )
27+ }
28+ . onTapGesture
29+ {
3030 self . store. refreshStore ( )
3131 }
32- }
33- Text ( " Tags: " )
34- . font ( . title)
35-
36- ASCollectionView (
37- section:
38- ASCollectionViewSection ( id: 0 , data: store. items)
39- { item, _ in
40- Text ( item. displayString)
41- . fixedSize ( horizontal: false , vertical: true )
42- . padding ( 5 )
43- . background ( Color ( . systemGray) )
44- . cornerRadius ( 5 )
45- } . selfSizingConfig { _ in
46- ASSelfSizingConfig ( canExceedCollectionWidth: false )
32+ Text ( " Tags: " )
33+ . font ( . title)
34+
35+ ASCollectionView (
36+ section:
37+ ASCollectionViewSection ( id: 0 , data: store. items)
38+ { item, _ in
39+ Text ( item. displayString)
40+ . fixedSize ( horizontal: false , vertical: true )
41+ . padding ( 5 )
42+ . background ( Color ( . systemGray) )
43+ . cornerRadius ( 5 )
44+ } . selfSizingConfig { _ in
45+ ASSelfSizingConfig ( canExceedCollectionWidth: false )
46+ }
47+ )
48+ . layout
49+ {
50+ let fl = AlignedFlowLayout ( )
51+ fl. estimatedItemSize = UICollectionViewFlowLayout . automaticSize
52+ return fl
4753 }
48- )
49- . layout
50- {
51- let fl = AlignedFlowLayout ( )
52- fl. estimatedItemSize = UICollectionViewFlowLayout . automaticSize
53- return fl
54- }
55- . shrinkToContentSize ( isEnabled: shrinkToSize, dimension: . vertical)
56-
57- if shrinkToSize
58- {
54+ . fitContentSize ( dimension: . vertical)
5955 Text ( " This is another view in the VStack, it shows how the collectionView above fits itself to the content. " )
6056 . padding ( )
61- . frame ( idealWidth : . infinity , maxWidth: . infinity)
57+ . frame ( maxWidth: . infinity)
6258 . foregroundColor ( Color ( . secondaryLabel) )
6359 . fixedSize ( horizontal: false , vertical: true )
6460 . background ( Color ( . secondarySystemBackground) )
65- Spacer ( )
6661 }
62+ . padding ( )
6763 }
68- . padding ( )
6964 . navigationBarTitle ( " Tags " , displayMode: . inline)
7065 }
7166}
0 commit comments