Skip to content

Commit

Permalink
Show selected filter in the Discover navigation bar (#23956)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Jan 7, 2025
2 parents 4b41387 + 5fd1a43 commit f0e5730
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* [*] Update site menu style on iPhone [#23944]
* [*] Integrate zoom transitions in Themes, Reader [#23945, #23947]
* [*] Fix an issue with site icons cropped in share extensions [#23950]
* [*] Show selected filter in the Discover navigation bar [#23956]
* [*] Enable fast deceleration for filters on the Discover tab [#23954]
* [*] Disable universal links support for QR code login. You can only scan the codes using the app now. [#23953]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ class ReaderDiscoverViewController: UIViewController, ReaderDiscoverHeaderViewDe
streamVC.view.pinEdges()
streamVC.didMove(toParent: self)

navigationItem.titleView = streamVC.navigationItem.titleView // important
streamVC.titleView.detailsLabel.text = selectedChannel.localizedTitle
streamVC.titleView.detailsLabel.isHidden = false

navigationItem.titleView = streamVC.titleView // important
}

/// TODO: (tech-debt) the app currently stores the responses from the `/discover`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ import AutomatticTracks
return refreshControl
}()

private let loadMoreThreashold = 4
let titleView = ReaderNavigationCustomTitleView()

private let loadMoreThreashold = 5
private let refreshInterval = 300
private var cleanupAndRefreshAfterScrolling = false
private let recentlyBlockedSitePostObjectIDs = NSMutableArray()
Expand All @@ -77,7 +78,6 @@ import AutomatticTracks
private var indexPathForGapMarker: IndexPath?
private var didSetupView = false
private var didBumpStats = false
@Lazy private var titleView = ReaderNavigationCustomTitleView()
internal let scrollViewTranslationPublisher = PassthroughSubject<Bool, Never>()
private let notificationsButtonViewModel = NotificationsButtonViewModel()
private var notificationsButtonCancellable: AnyCancellable?
Expand Down Expand Up @@ -1660,7 +1660,7 @@ extension ReaderStreamViewController: UITableViewDelegate, JPScrollViewDelegate
func scrollViewDidScroll(_ scrollView: UIScrollView) {
layoutEmptyStateView()
processJetpackBannerVisibility(scrollView)
$titleView.value?.updateAlpha(in: scrollView)
titleView.updateAlpha(in: scrollView)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,36 @@ import WordPressUI
/// A custom replacement for a navigation bar title view.
final class ReaderNavigationCustomTitleView: UIView {
let textLabel = UILabel()
let detailsLabel = UILabel()
private lazy var stackView = UIStackView(axis: .vertical, alignment: .center, [textLabel, detailsLabel])

override init(frame: CGRect) {
super.init(frame: frame)

textLabel.font = WPStyleGuide.navigationBarStandardFont
textLabel.alpha = 0

// The label has to be a subview of the title view because
// navigation bar doesn't seem to allow you to change the alpha
// of `navigationItem.titleView` itself.
addSubview(textLabel)
textLabel.pinEdges()
detailsLabel.font = .preferredFont(forTextStyle: .footnote)
detailsLabel.textColor = .secondaryLabel
detailsLabel.isHidden = true

addSubview(stackView)
stackView.pinEdges()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// The label has to be a subview of the title view because
// navigation bar doesn't seem to allow you to change the alpha
// of `navigationItem.titleView` itself.
func updateAlpha(in scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
if offsetY < 16 {
textLabel.alpha = 0
stackView.alpha = 0
} else {
let alpha = (offsetY - 16) / 24
textLabel.alpha = max(0, min(1, alpha))
stackView.alpha = max(0, min(1, alpha))
}
}
}

0 comments on commit f0e5730

Please sign in to comment.