Skip to content

Commit 49143f1

Browse files
committed
Scroll to the current session instead of just scrolling to the top
1 parent bce34ba commit 49143f1

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

trySwift.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
499CCFF21CC2E0F4007A5BBB /* UIViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 499CCFF11CC2E0F4007A5BBB /* UIViewControllerExtension.swift */; };
2828
49F7B2811E8475F900F09768 /* SplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49F7B2801E8475F900F09768 /* SplitViewController.swift */; };
2929
4D498DB1B98D4B496FDBB7AA /* Pods_try__Extension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD2E9D5733A6E1B6E10AFEEF /* Pods_try__Extension.framework */; };
30-
5CDB20792048952A00C3E0D3 /* TwitterFollowDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */; };
3130
5C7F82DB2048B01D009193B4 /* RootTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C7F82DA2048B01D009193B4 /* RootTabBarController.swift */; };
31+
5CDB20792048952A00C3E0D3 /* TwitterFollowDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */; };
3232
7AD1E19C80B78BB08E3DF079 /* Pods_trySwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 620220ABCCCDF47FDAF48B67 /* Pods_trySwift.framework */; };
3333
EAFE1C26E49EFABF83487BDC /* Pods_try__Today.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24718BF11477753FCD47A7A8 /* Pods_try__Today.framework */; };
3434
FA0E2B4F1E63B90400B40814 /* SessionDetailInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA0E2B4E1E63B90400B40814 /* SessionDetailInterfaceController.swift */; };
@@ -195,8 +195,8 @@
195195
499CCFF11CC2E0F4007A5BBB /* UIViewControllerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewControllerExtension.swift; sourceTree = "<group>"; };
196196
49F7B2801E8475F900F09768 /* SplitViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = "<group>"; };
197197
58F81AD508535BD405F98215 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
198-
5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwitterFollowDelegate.swift; sourceTree = "<group>"; };
199198
5C7F82DA2048B01D009193B4 /* RootTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootTabBarController.swift; sourceTree = "<group>"; };
199+
5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwitterFollowDelegate.swift; sourceTree = "<group>"; };
200200
5FA07FBC036240AEF8B7C739 /* Pods-trySwift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-trySwift.release.xcconfig"; path = "Pods/Target Support Files/Pods-trySwift/Pods-trySwift.release.xcconfig"; sourceTree = "<group>"; };
201201
620220ABCCCDF47FDAF48B67 /* Pods_trySwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_trySwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
202202
6C1F9C27BCD8099DCA758F7A /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
@@ -385,20 +385,20 @@
385385
name = Frameworks;
386386
sourceTree = "<group>";
387387
};
388-
5CDB20772048951F00C3E0D3 /* Twitter */ = {
388+
5C7F82D92048B00B009193B4 /* RootTabBar */ = {
389389
isa = PBXGroup;
390390
children = (
391-
5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */,
391+
5C7F82DA2048B01D009193B4 /* RootTabBarController.swift */,
392392
);
393-
path = Twitter;
393+
path = RootTabBar;
394394
sourceTree = "<group>";
395395
};
396-
5C7F82D92048B00B009193B4 /* RootTabBar */ = {
396+
5CDB20772048951F00C3E0D3 /* Twitter */ = {
397397
isa = PBXGroup;
398398
children = (
399-
5C7F82DA2048B01D009193B4 /* RootTabBarController.swift */,
399+
5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */,
400400
);
401-
path = RootTabBar;
401+
path = Twitter;
402402
sourceTree = "<group>";
403403
};
404404
F413680C9BA29129B4319377 /* Pods */ = {

trySwift/RootTabBar/RootTabBarController.swift

+18-11
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,25 @@ class RootTabBarController: UITabBarController, UITabBarControllerDelegate {
1515
}
1616

1717
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
18-
if let splitViewController = viewController as? UISplitViewController {
19-
if let navigationController = splitViewController.viewControllers.last as? UINavigationController {
20-
if navigationController.viewControllers.count > 1 {
21-
navigationController.popViewController(animated: true)
18+
guard
19+
let splitViewController = viewController as? UISplitViewController,
20+
let navigationController = splitViewController.viewControllers.last as? UINavigationController
21+
else {
22+
return
23+
}
24+
25+
// if several view controllers are in the stack, pop to the root
26+
if navigationController.viewControllers.count > 1 {
27+
navigationController.popToRootViewController(animated: true)
28+
} else {
29+
// if there's at least one view controller in the stack (which there always should be)
30+
if let firstController = navigationController.viewControllers.first {
31+
// we either delegate to the controller since it knows better how to scroll to the top
32+
if let scrollableToTop = firstController as? ScrollableToTop {
33+
scrollableToTop.scrollAfterTabTap()
34+
// or we find the topmost scroll view and scroll it to the top
2235
} else {
23-
if let firstController = navigationController.viewControllers.first {
24-
if let scrollableToTop = firstController as? ScrollableToTop {
25-
scrollableToTop.scrollAfterTabTap()
26-
} else {
27-
firstController.view.findScrollSubview()?.setContentOffset(.zero, animated: true)
28-
}
29-
}
36+
firstController.view.findScrollSubview()?.setContentOffset(.zero, animated: true)
3037
}
3138
}
3239
}

trySwift/ScheduleViewController.swift

-18
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class ScheduleViewController: ButtonBarPagerTabStripViewController {
3030
buttonBarView.backgroundColor = .white
3131
settings.style.selectedBarBackgroundColor = .white
3232
buttonBarView.selectedBar.backgroundColor = .trySwiftAccentColor()
33-
34-
tabBarController?.delegate = self
3533
}
3634

3735
override func viewDidAppear(_ animated: Bool) {
@@ -83,19 +81,3 @@ private extension ScheduleViewController {
8381
}
8482
}
8583

86-
extension ScheduleViewController: UITabBarControllerDelegate {
87-
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
88-
guard
89-
tabBarController.selectedViewController === viewController,
90-
navigationController?.viewControllers.last === self
91-
else { return true }
92-
93-
guard
94-
let index = moveToCorrectDate(animated: true),
95-
let controller = viewControllers[index] as? SessionsTableViewController
96-
else { return true }
97-
controller.scrollToCurrentSession(animated: true)
98-
99-
return true
100-
}
101-
}

0 commit comments

Comments
 (0)