@@ -100,11 +100,13 @@ func actionButtonTapped()
100100 return refreshingStatus
101101 } ( )
102102
103- private lazy var tableView : UITableView = {
104- let tableView = UITableView ( frame: . zero, style: . grouped)
105- tableView. estimatedRowHeight = 52
106- tableView. rowHeight = UITableView . automaticDimension
107- return tableView
103+ private lazy var collectionView : UICollectionView = {
104+ var configuration = UICollectionLayoutListConfiguration ( appearance: . grouped)
105+ configuration. headerMode = . supplementary
106+ configuration. footerMode = . supplementary
107+
108+ let collectionView = UICollectionView ( frame: . zero, collectionViewLayout: UICollectionViewCompositionalLayout . list ( using: configuration) )
109+ return collectionView
108110 } ( )
109111
110112 let allEventsController = Event . caseInsensitiveSortFetchAll ( sortTerm: " name " , ascending: true , predicate: NSPredicate ( format: " TRUEPREDICATE " ) , groupBy: nil , context: NSManagedObjectContext . mr_default ( ) )
@@ -119,7 +121,7 @@ func actionButtonTapped()
119121 self . modalPresentationStyle = . fullScreen
120122 self . scheme = scheme
121123 self . delegate = delegate
122- self . eventDataSource = EventTableDataSource ( tableView : tableView , eventSelectionDelegate: self , scheme: scheme)
124+ self . eventDataSource = EventTableDataSource ( eventSelectionDelegate: self , scheme: scheme)
123125 self . allEventsController? . delegate = self
124126
125127 do {
@@ -140,17 +142,17 @@ func actionButtonTapped()
140142 title = " Welcome To MAGE "
141143 navigationItem. hidesBackButton = true
142144
143- tableView . dataSource = eventDataSource
144- tableView . delegate = eventDataSource
145- tableView . register ( UINib ( nibName : " EventCell " , bundle : nil ) , forCellReuseIdentifier : " eventCell " )
146- tableView . isAccessibilityElement = true
147- tableView . accessibilityLabel = " Event Table "
148- tableView . accessibilityIdentifier = " Event Table "
145+ collectionView . dataSource = eventDataSource
146+ collectionView . delegate = eventDataSource
147+
148+ collectionView . isAccessibilityElement = true
149+ collectionView . accessibilityLabel = " Event Table "
150+ collectionView . accessibilityIdentifier = " Event Table "
149151
150152 searchController. searchResultsUpdater = self
151153 applyTheme ( withContainerScheme: scheme)
152154
153- emptyState = EmptyState ( frame: CGRect ( x: 0 , y: 0 , width: self . tableView . bounds. size. width, height: self . tableView . bounds. size. height) )
155+ emptyState = EmptyState ( frame: CGRect ( x: 0 , y: 0 , width: self . collectionView . bounds. size. width, height: self . collectionView . bounds. size. height) )
154156 }
155157
156158 override func viewWillAppear( _ animated: Bool ) {
@@ -159,7 +161,7 @@ func actionButtonTapped()
159161 if !eventsFetched && !eventsInitialized && eventDataSource? . otherFetchedResultsController? . fetchedObjects? . count == 0 && eventDataSource? . recentFetchedResultsController? . fetchedObjects? . count == 0 {
160162 emptyState? . configure ( image: UIImage ( systemName: " calendar " ) , title: " Loading Events " , showActivityIndicator: true , scheme: self . scheme)
161163 emptyState? . toggleVisible ( true )
162- tableView . backgroundView = emptyState
164+ collectionView . backgroundView = emptyState
163165 }
164166 }
165167
@@ -173,7 +175,7 @@ func actionButtonTapped()
173175 eventInstructions. textColor = scheme? . colorScheme. onPrimaryColor
174176 eventInstructions. font = scheme? . typographyScheme. caption
175177 // actionbutton
176- tableView . backgroundColor = scheme? . colorScheme. surfaceColor
178+ collectionView . backgroundColor = scheme? . colorScheme. surfaceColor
177179 refreshingButton. applySecondaryTheme ( withScheme: containerScheme)
178180 searchController. searchBar. barTintColor = scheme? . colorScheme. onPrimaryColor;
179181 searchController. searchBar. tintColor = scheme? . colorScheme. onPrimaryColor;
@@ -203,7 +205,7 @@ func actionButtonTapped()
203205 searchContainer. addSubview ( searchBar)
204206 }
205207 view. addSubview ( searchContainer)
206- view. addSubview ( tableView )
208+ view. addSubview ( collectionView )
207209 view. addSubview ( refreshingButton)
208210 view. addSubview ( refreshingView)
209211 searchContainerHeightConstraint = searchContainer. autoSetDimension ( . height, toSize: 56 )
@@ -218,19 +220,20 @@ func actionButtonTapped()
218220 searchContainer. autoPinEdge ( . top, to: . bottom, of: stackView)
219221
220222 NSLayoutConstraint . autoSetPriority ( . defaultHigh) {
221- tableView . autoPinEdgesToSuperviewEdges ( with: . zero, excludingEdge: . top)
222- tableView . autoPinEdge ( . top, to: . bottom, of: searchContainer)
223+ collectionView . autoPinEdgesToSuperviewEdges ( with: . zero, excludingEdge: . top)
224+ collectionView . autoPinEdge ( . top, to: . bottom, of: searchContainer)
223225 }
224226
225227 NSLayoutConstraint . autoSetPriority ( . defaultLow) {
226- tableView . autoPinEdgesToSuperviewEdges ( with: . zero, excludingEdge: . top)
227- tableView . autoPinEdge ( . top, to: . bottom, of: stackView)
228+ collectionView . autoPinEdgesToSuperviewEdges ( with: . zero, excludingEdge: . top)
229+ collectionView . autoPinEdge ( . top, to: . bottom, of: stackView)
228230 }
229231
230232 eventInstructions. autoSetDimension ( . height, toSize: 32 )
231233
232234 refreshingButton. autoAlignAxis ( toSuperviewAxis: . vertical)
233- refreshingButton. autoPinEdge ( . top, to: . top, of: tableView, withOffset: 8 )
235+
236+ refreshingButton. autoPinEdge ( . top, to: . top, of: collectionView, withOffset: 8 )
234237
235238 refreshingStatus. autoPinEdgesToSuperviewSafeArea ( with: UIEdgeInsets ( top: 16 , left: 8 , bottom: 0 , right: 8 ) )
236239 refreshingView. autoPinEdgesToSuperviewEdges ( with: . zero, excludingEdge: . top)
@@ -278,7 +281,7 @@ func actionButtonTapped()
278281 } else {
279282 UserDefaults . standard. showEventChooserOnce = false
280283 }
281- tableView . reloadData ( )
284+ collectionView . reloadData ( )
282285 }
283286
284287 let timer = Timer ( timeInterval: 10 , repeats: true ) { [ weak self] timer in
@@ -319,7 +322,7 @@ func actionButtonTapped()
319322 // will update the event table and if there is only one event follow the autoSelectEvent flag
320323 func updateEventTable( autoSelectEvent: Bool = true ) {
321324 eventDataSource? . refreshEventData ( )
322- tableView . reloadData ( )
325+ collectionView . reloadData ( )
323326 refreshingButton. isHidden = true
324327
325328 if eventDataSource? . otherFetchedResultsController? . fetchedObjects? . count == 0 && eventDataSource? . recentFetchedResultsController? . fetchedObjects? . count == 0 {
@@ -335,7 +338,7 @@ func actionButtonTapped()
335338 attributedString. addAttribute ( . paragraphStyle, value: paragraph, range: NSRange ( location: 0 , length: attributedString. length) )
336339
337340 emptyState? . configure ( image: UIImage ( systemName: " calendar " ) , title: " No Events " , attributedDescription: attributedString, buttonText: " Return to Login " , tapHandler: self , selector: #selector( actionButtonTapped) , scheme: scheme)
338- self . tableView . backgroundView = emptyState
341+ self . collectionView . backgroundView = emptyState
339342 emptyState? . toggleVisible ( true )
340343 eventInstructions. isHidden = true
341344 searchContainerHeightConstraint? . constant = 0.0
@@ -411,6 +414,6 @@ extension EventChooserController : UISearchResultsUpdating {
411414 } else {
412415 eventDataSource? . setEventFilter ( filter: nil , delegate: nil )
413416 }
414- tableView . reloadData ( )
417+ collectionView . reloadData ( )
415418 }
416419}
0 commit comments