Skip to content

Commit

Permalink
Fix crash in Reader stream empty state views (#23908)
Browse files Browse the repository at this point in the history
* Fix crash in Reader empty state views and fix some layout issues

* Fix frame conversion
  • Loading branch information
kean authored Dec 19, 2024
1 parent d634ed4 commit cc26fec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [*] Reader: Fix an issue with posts shown embedded in the notifications popover on iPad [#23889]
* [*] Reader: The post cover now uses the standard aspect ratio for covers, so there is no jumping. There are also a few minor improvements to the layout and animations of the cover and the header [#23897, #23909]
* [*] Reader: Move the "Reading Preferences" button to the "More" menu [#23897]
* [*] Reader: Fix an issue with empty state views being non-scrollable in streams [#23908]
* [*] Reader: Hide post toolbar when reading an article and fix like button animations [#23909]
* [*] Reader: Fix off-by-one error in post details like counter when post is liked by you [#23912]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,8 @@ import AutomatticTracks
didSet {
oldValue?.removeFromSuperview()
if let emptyStateView {
view.addSubview(emptyStateView)
emptyStateView.pinEdges(.horizontal, to: view.safeAreaLayoutGuide)
NSLayoutConstraint.activate([
emptyStateView.topAnchor.constraint(equalTo: tableView.tableHeaderView?.bottomAnchor ?? view.safeAreaLayoutGuide.topAnchor),
emptyStateView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
])

tableView.addSubview(emptyStateView)
layoutEmptyStateView()
footerView.isHidden = true
hideGhost()
}
Expand Down Expand Up @@ -352,6 +347,8 @@ import AutomatticTracks
if didSetupView {
tableView.sizeToFitHeaderView()
}

layoutEmptyStateView()
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
Expand All @@ -361,6 +358,28 @@ import AutomatticTracks
setupNotificationsBarButtonItem()
}

private func layoutEmptyStateView() {
guard let emptyStateView else { return }

// Calculate visible part of the table view in `self.view` coordinates
let y: CGFloat = {
if let headerView = tableView.tableHeaderView {
return tableView.convert(headerView.frame, to: view).maxY
} else {
return view.safeAreaInsets.top
}
}()

// And convert it to the `tableView` coordinate space since that's where
// `emptyStateView` belongs.
emptyStateView.frame = tableView.convert(CGRect(
x: 0,
y: y,
width: view.bounds.width,
height: view.bounds.height - y - view.safeAreaInsets.bottom
), from: view)
}

private func didChangeIsCompact(_ isCompact: Bool) {
(tableView.tableHeaderView as? ReaderBaseHeaderView)?.isCompact = isCompact
tableView.reloadData()
Expand Down Expand Up @@ -1599,6 +1618,7 @@ extension ReaderStreamViewController: UIViewControllerTransitioningDelegate {

extension ReaderStreamViewController: UITableViewDelegate, JPScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
layoutEmptyStateView()
processJetpackBannerVisibility(scrollView)
$titleView.value?.updateAlpha(in: scrollView)
}
Expand Down

0 comments on commit cc26fec

Please sign in to comment.