@@ -10,6 +10,7 @@ import UIKit
1010import XLPagerTabStrip
1111import TrySwiftData
1212
13+
1314class SessionsTableViewController : UITableViewController {
1415 private lazy var needsToScrollToCurrentSession = Calendar . current. isDateInToday ( conferenceDay. date)
1516
@@ -33,15 +34,15 @@ class SessionsTableViewController: UITableViewController {
3334 super. viewDidLoad ( )
3435
3536 configureTableView ( )
36-
37+
3738 if traitCollection. forceTouchCapability == . available {
3839 registerForPreviewing ( with: self , sourceView: tableView)
3940 }
4041 }
41-
42+
4243 override func viewDidAppear( _ animated: Bool ) {
4344 super. viewDidAppear ( animated)
44-
45+
4546 if needsToScrollToCurrentSession {
4647 needsToScrollToCurrentSession = false
4748 scrollToCurrentSession ( animated: false )
@@ -55,32 +56,32 @@ class SessionsTableViewController: UITableViewController {
5556 let isCollapsed = splitViewController? . isCollapsed,
5657 !isCollapsed,
5758 !didShowDetail else { return }
58-
59+
5960 didShowDetail = true
6061 scheduleViewController? . performSegue ( withIdentifier: sessionDetailsSegue, sender: firstSelectableSessionVC)
6162 }
6263}
6364
6465// MARK: - Table view data source
6566extension SessionsTableViewController {
66-
67+
6768 override func numberOfSections( in tableView: UITableView ) -> Int {
6869 return conferenceDay. sessionBlocks. count
6970 }
70-
71+
7172 override func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
7273 return conferenceDay. sessionBlocks [ section] . sessions. count
7374 }
74-
75+
7576 override func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
7677 let cell = tableView. dequeueReusableCell ( forIndexPath: indexPath) as SessionTableViewCell
77-
78+
7879 let session = conferenceDay. sessionBlocks [ indexPath. section] . sessions [ indexPath. row]
7980 cell. configure ( withSession: session)
80-
81+
8182 return cell
8283 }
83-
84+
8485 override func tableView( _ tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
8586 let session = conferenceDay. sessionBlocks [ section]
8687 let sessionDateFormatter = DateFormatter . sessionDateFormatter
@@ -108,33 +109,33 @@ extension SessionsTableViewController: IndicatorInfoProvider {
108109}
109110
110111extension SessionsTableViewController : UIViewControllerPreviewingDelegate {
111-
112+
112113 func previewingContext( _ previewingContext: UIViewControllerPreviewing , viewControllerForLocation location: CGPoint ) -> UIViewController ? {
113114 guard let indexPath = tableView. indexPathForRow ( at: location) else { return nil }
114115 // This will show the cell clearly and blur the rest of the screen for our peek.
115116 previewingContext. sourceRect = tableView. rectForRow ( at: indexPath)
116117 let session = conferenceDay. sessionBlocks [ indexPath. section] . sessions [ indexPath. row]
117118 return viewController ( for: session)
118119 }
119-
120+
120121 func previewingContext( _ previewingContext: UIViewControllerPreviewing , commit viewControllerToCommit: UIViewController ) {
121122 scheduleViewController? . performSegue ( withIdentifier: sessionDetailsSegue, sender: viewControllerToCommit)
122123 }
123124}
124125
125126extension SessionsTableViewController {
126-
127+
127128 func configureTableView( ) {
128-
129+
129130 tableView. register ( SessionTableViewCell . self)
130-
131+
131132 tableView. estimatedRowHeight = 160
132133 tableView. rowHeight = UITableViewAutomaticDimension
133134 }
134135}
135136
136137private extension SessionsTableViewController {
137-
138+
138139 func viewController( for session: Session ) -> UIViewController ? {
139140 switch session. type {
140141 case . talk, . lightningTalk:
@@ -174,39 +175,39 @@ private extension SessionsTableViewController {
174175 default :
175176 return nil
176177 }
177-
178+
178179 return nil
179180 }
180-
181+
181182 func sessionDetails( _ presentation: Presentation , session: Session ) -> UIViewController {
182183 let storyboard = UIStoryboard ( name: " Main " , bundle: nil )
183184 let sessionDetailsVC = storyboard. instantiateViewController ( withIdentifier: String ( describing: SessionDetailsViewController . self) ) as! SessionDetailsViewController
184185 sessionDetailsVC. session = session
185186 sessionDetailsVC. presentation = presentation
186187 return sessionDetailsVC
187188 }
188-
189+
189190 func officeHourDetails( _ speaker: Speaker , session: Session ) -> UIViewController {
190191 let officeHoursVC = OfficeHoursDetailViewController ( )
191192 officeHoursVC. speaker = speaker
192193 officeHoursVC. session = session
193194 return officeHoursVC
194195 }
195-
196+
196197 func webDisplay( _ event: Event ) -> UIViewController {
197198 let webViewController = WebDisplayViewController ( )
198199 webViewController. url = URL ( string: event. website!)
199200 webViewController. displayTitle = event. title
200201 return webViewController
201202 }
202-
203+
203204 func webDisplay( _ sponsor: Sponsor ) -> UIViewController {
204205 let webViewController = WebDisplayViewController ( )
205206 webViewController. url = URL ( string: sponsor. url!)
206207 webViewController. displayTitle = sponsor. name
207208 return webViewController
208209 }
209-
210+
210211 func venueDetails( _ venue: Venue ) -> UIViewController {
211212 let venueDetailsVC = VenueTableViewController ( venue: venue)
212213 venueDetailsVC. tableView. contentInset = UIEdgeInsets ( top: 80 , left: 0 , bottom: 0 , right: 0 )
@@ -224,15 +225,21 @@ private extension SessionsTableViewController {
224225}
225226
226227extension SessionsTableViewController {
227-
228+
228229 func scrollToCurrentSession( animated: Bool ) {
229230 let secondsFromGMT = TimeZone . current. secondsFromGMT ( )
230231 guard
231232 let date = Date ( ) . changed ( second: secondsFromGMT) ,
232233 let section = conferenceDay. sessionBlocks. index ( where: { date < $0. endTime } ) ,
233234 !conferenceDay. sessionBlocks [ section] . sessions. isEmpty
234235 else { return }
235-
236+
236237 tableView. scrollToRow ( at: IndexPath ( row: 0 , section: section) , at: . top, animated: animated)
237238 }
238239}
240+
241+ extension SessionsTableViewController : ScrollableToTop {
242+ func scrollAfterTabTap( ) {
243+ scrollToCurrentSession ( animated: true )
244+ }
245+ }
0 commit comments