chore: remove newBottomContent logic

This commit is contained in:
sunxiaojian 2021-03-16 15:05:01 +08:00
parent 1abe550745
commit 27307ed4dd
2 changed files with 10 additions and 36 deletions

View File

@ -17,7 +17,6 @@ final class HomeTimelineNavigationBarState {
var networkErrorCountSubject = PassthroughSubject<Bool, Never>()
var newTopContent = CurrentValueSubject<Bool, Never>(false)
var newBottomContent = CurrentValueSubject<Bool, Never>(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)
}

View File

@ -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
}