diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineNavigationBarState.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineNavigationBarState.swift index 3ae74a264..11692eaac 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineNavigationBarState.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineNavigationBarState.swift @@ -17,7 +17,6 @@ final class HomeTimelineNavigationBarState { var networkErrorCountSubject = PassthroughSubject() var newTopContent = CurrentValueSubject(false) - var newBottomContent = CurrentValueSubject(false) var hasContentBeforeFetching: Bool = true weak var viewController: HomeTimelineViewController? @@ -36,10 +35,12 @@ final class HomeTimelineNavigationBarState { extension HomeTimelineNavigationBarState { func showOfflineInNavigationBar() { + HomeTimelineNavigationBarView.progressView.removeFromSuperview() viewController?.navigationItem.titleView = HomeTimelineNavigationBarView.offlineView } func showNewPostsInNavigationBar() { + HomeTimelineNavigationBarView.progressView.removeFromSuperview() viewController?.navigationItem.titleView = HomeTimelineNavigationBarView.newPostsView } @@ -84,6 +85,7 @@ extension HomeTimelineNavigationBarState { } func showMastodonLogoInNavigationBar() { + HomeTimelineNavigationBarView.progressView.removeFromSuperview() viewController?.navigationItem.titleView = HomeTimelineNavigationBarView.mastodonLogoTitleView } } @@ -100,30 +102,18 @@ extension HomeTimelineNavigationBarState { newTopContent.value = false showMastodonLogoInNavigationBar() } - let isBottom = contentOffsetY > max(-scrollView.adjustedContentInset.top, scrollView.contentSize.height - scrollView.frame.height + scrollView.adjustedContentInset.bottom) - if isBottom { - newBottomContent.value = false - showMastodonLogoInNavigationBar() - } } func addGesture() { let tapGesture = UITapGestureRecognizer.singleTapGestureRecognizer - tapGesture.addTarget(self, action: #selector(newPostsNewDidPressed)) + tapGesture.addTarget(self, action: #selector(HomeTimelineNavigationBarState.newPostsNewDidPressed(_:))) HomeTimelineNavigationBarView.newPostsView.addGestureRecognizer(tapGesture) } - @objc func newPostsNewDidPressed() { + @objc func newPostsNewDidPressed(_ sender: UITapGestureRecognizer) { if newTopContent.value == true { - scrollToDirection(direction: .top) + viewController?.tableView.scroll(to: .top, animated: true) } - if newBottomContent.value == true { - scrollToDirection(direction: .bottom) - } - } - - func scrollToDirection(direction: UIScrollView.ScrollDirection) { - viewController?.tableView.scroll(to: direction, animated: true) } } @@ -136,21 +126,6 @@ extension HomeTimelineNavigationBarState { if self.hasContentBeforeFetching, newContent { self.showNewPostsInNavigationBar() } - if newContent { - self.newBottomContent.value = false - } - } - .store(in: &disposeBag) - newBottomContent - .receive(on: DispatchQueue.main) - .sink { [weak self] newContent in - guard let self = self else { return } - if newContent { - self.showNewPostsInNavigationBar() - } - if newContent { - self.newTopContent.value = false - } } .store(in: &disposeBag) } diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineNavigationBarView.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineNavigationBarView.swift index d371ffe59..c19d45e47 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineNavigationBarView.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineNavigationBarView.swift @@ -55,18 +55,17 @@ final class HomeTimelineNavigationBarView { label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16), view.trailingAnchor.constraint(equalTo: label.trailingAnchor, constant: 16), label.topAnchor.constraint(equalTo: view.topAnchor, constant: 1), - view.bottomAnchor.constraint(equalTo: label.bottomAnchor, constant: 1) + view.bottomAnchor.constraint(equalTo: label.bottomAnchor, constant: 1), + view.heightAnchor.constraint(equalToConstant: 24), ]) - label.sizeToFit() - view.layoutIfNeeded() - view.layer.cornerRadius = view.frame.height / 2 - view.clipsToBounds = true } static func backgroundViewWithColor(color: UIColor) -> UIView { let view = UIView() view.backgroundColor = color view.translatesAutoresizingMaskIntoConstraints = false + view.layer.cornerRadius = 12 + view.clipsToBounds = true return view }