Merge pull request #701 from kylebshr/kb/scroll-to-top
Fix scroll to top when tab is tapped
This commit is contained in:
commit
a790199ee4
|
@ -569,25 +569,24 @@ extension MainTabBarController: UITabBarControllerDelegate {
|
||||||
composeButtonDidPressed(tabBarController)
|
composeButtonDidPressed(tabBarController)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assert index is as same as the tab rawValue. This check needs to be done `shouldSelect`
|
||||||
|
// because the nav controller has already popped in `didSelect`.
|
||||||
|
if currentTab.rawValue == tabBarController.selectedIndex,
|
||||||
|
let navigationController = viewController as? UINavigationController,
|
||||||
|
navigationController.viewControllers.count == 1,
|
||||||
|
let scrollViewContainer = navigationController.topViewController as? ScrollViewContainer {
|
||||||
|
scrollViewContainer.scrollToTop(animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
|
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
|
||||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: select %s", ((#file as NSString).lastPathComponent), #line, #function, viewController.debugDescription)
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: select %s", ((#file as NSString).lastPathComponent), #line, #function, viewController.debugDescription)
|
||||||
defer {
|
if let tab = Tab(rawValue: viewController.tabBarItem.tag) {
|
||||||
if let tab = Tab(rawValue: viewController.tabBarItem.tag) {
|
currentTab = tab
|
||||||
currentTab = tab
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// assert index is as same as the tab rawValue
|
|
||||||
guard currentTab.rawValue == tabBarController.selectedIndex,
|
|
||||||
let navigationController = viewController as? UINavigationController,
|
|
||||||
navigationController.viewControllers.count == 1,
|
|
||||||
let scrollViewContainer = navigationController.topViewController as? ScrollViewContainer else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
scrollViewContainer.scrollToTop(animated: true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue