Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show selected filter in the Discover navigation bar #23956

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]


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