Commit d71867cc by Demid Merzlyakov

Forecast: fix (hopefully) infinite recursion in `scrollViewDidScroll`.

parent 30bfb68a
......@@ -23,6 +23,8 @@ class ForecastViewController: UIViewController {
return TimePeriod(rawValue: timePeriodControl.selectedSegmentIndex) ?? .daily
}
private var navigationBarStateBeingChanged = false
init(viewModel: ForecastViewModel, coordinator: ForecastCoordinator) {
self.viewModel = viewModel
self.coordinator = coordinator
......@@ -188,6 +190,7 @@ private extension ForecastViewController {
extension ForecastViewController: UITableViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard
!navigationBarStateBeingChanged,
let navVC = self.navigationController,
viewModel.location?.daily.isEmpty == false,
self.timePeriod == .daily
......@@ -200,18 +203,27 @@ extension ForecastViewController: UITableViewDelegate {
}
let startPointY = timePeriodCellFrame.origin.y + timePeriodCellFrame.height - self.daysControlView.frame.height
let animationDuration = TimeInterval(UINavigationController.hideShowBarDuration)
if scrollView.contentOffset.y >= startPointY {
if !navVC.isNavigationBarHidden {
self.navigationBarStateBeingChanged = true
DispatchQueue.main.asyncAfter(deadline: .now() + animationDuration) {
self.navigationBarStateBeingChanged = false
}
navVC.setNavigationBarHidden(true, animated: true)
self.daysControlView.update(offset: self.viewModel.offsetHolder.currentOffset)
UIView.animate(withDuration: 0.35) {
UIView.animate(withDuration: animationDuration) {
self.daysControlView.alpha = 1
}
}
}
else {
if navVC.isNavigationBarHidden {
self.navigationBarStateBeingChanged = true
DispatchQueue.main.asyncAfter(deadline: .now() + animationDuration) {
self.navigationBarStateBeingChanged = false
}
navVC.setNavigationBarHidden(false, animated: true)
UIView.animate(withDuration: 0.35) {
self.daysControlView.alpha = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment