@@ -30,6 +30,8 @@ class ScheduleViewController: ButtonBarPagerTabStripViewController {
3030 buttonBarView. backgroundColor = . white
3131 settings. style. selectedBarBackgroundColor = . white
3232 buttonBarView. selectedBar. backgroundColor = . trySwiftAccentColor( )
33+
34+ tabBarController? . delegate = self
3335 }
3436
3537 override func viewDidAppear( _ animated: Bool ) {
@@ -59,14 +61,35 @@ class ScheduleViewController: ButtonBarPagerTabStripViewController {
5961
6062private extension ScheduleViewController {
6163
62- func moveToCorrectDate( ) {
63- if days. count > 1 {
64- let calendar = NSCalendar . current
65- if let todaysIndex = days. enumerated ( )
66- . first ( where: { calendar. isDateInToday ( $0. element. date) } )
67- . map ( { $0. offset} ) {
68- moveToViewController ( at: todaysIndex, animated: false )
69- }
64+ @discardableResult
65+ func moveToCorrectDate( animated: Bool = false ) -> Int ? {
66+ if days. count > 1 {
67+ let calendar = Calendar . current
68+ if let todaysIndex = days. enumerated ( )
69+ . first ( where: { calendar. isDateInToday ( $0. element. date) } )
70+ . map ( { $0. offset} ) {
71+ moveToViewController ( at: todaysIndex, animated: animated)
72+ return todaysIndex
73+ }
74+ }
75+
76+ return . none
77+ }
78+ }
79+
80+ extension ScheduleViewController : UITabBarControllerDelegate {
81+ func tabBarController( _ tabBarController: UITabBarController , shouldSelect viewController: UIViewController ) -> Bool {
82+ guard
83+ tabBarController. selectedViewController === viewController,
84+ navigationController? . viewControllers. last === self
85+ else { return true }
86+
87+ guard
88+ let index = moveToCorrectDate ( animated: true ) ,
89+ let controller = viewControllers [ index] as? SessionsTableViewController
90+ else { return true }
91+ controller. scrollToCurrentSession ( animated: true )
92+
93+ return true
7094 }
71- }
7295}
0 commit comments