Skip to content

Commit cc26fec

Browse files
authored
Fix crash in Reader stream empty state views (#23908)
* Fix crash in Reader empty state views and fix some layout issues * Fix frame conversion
1 parent d634ed4 commit cc26fec

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* [*] Reader: Fix an issue with posts shown embedded in the notifications popover on iPad [#23889]
1919
* [*] 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]
2020
* [*] Reader: Move the "Reading Preferences" button to the "More" menu [#23897]
21+
* [*] Reader: Fix an issue with empty state views being non-scrollable in streams [#23908]
2122
* [*] Reader: Hide post toolbar when reading an article and fix like button animations [#23909]
2223
* [*] Reader: Fix off-by-one error in post details like counter when post is liked by you [#23912]
2324

WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,8 @@ import AutomatticTracks
197197
didSet {
198198
oldValue?.removeFromSuperview()
199199
if let emptyStateView {
200-
view.addSubview(emptyStateView)
201-
emptyStateView.pinEdges(.horizontal, to: view.safeAreaLayoutGuide)
202-
NSLayoutConstraint.activate([
203-
emptyStateView.topAnchor.constraint(equalTo: tableView.tableHeaderView?.bottomAnchor ?? view.safeAreaLayoutGuide.topAnchor),
204-
emptyStateView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
205-
])
206-
200+
tableView.addSubview(emptyStateView)
201+
layoutEmptyStateView()
207202
footerView.isHidden = true
208203
hideGhost()
209204
}
@@ -352,6 +347,8 @@ import AutomatticTracks
352347
if didSetupView {
353348
tableView.sizeToFitHeaderView()
354349
}
350+
351+
layoutEmptyStateView()
355352
}
356353

357354
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
@@ -361,6 +358,28 @@ import AutomatticTracks
361358
setupNotificationsBarButtonItem()
362359
}
363360

361+
private func layoutEmptyStateView() {
362+
guard let emptyStateView else { return }
363+
364+
// Calculate visible part of the table view in `self.view` coordinates
365+
let y: CGFloat = {
366+
if let headerView = tableView.tableHeaderView {
367+
return tableView.convert(headerView.frame, to: view).maxY
368+
} else {
369+
return view.safeAreaInsets.top
370+
}
371+
}()
372+
373+
// And convert it to the `tableView` coordinate space since that's where
374+
// `emptyStateView` belongs.
375+
emptyStateView.frame = tableView.convert(CGRect(
376+
x: 0,
377+
y: y,
378+
width: view.bounds.width,
379+
height: view.bounds.height - y - view.safeAreaInsets.bottom
380+
), from: view)
381+
}
382+
364383
private func didChangeIsCompact(_ isCompact: Bool) {
365384
(tableView.tableHeaderView as? ReaderBaseHeaderView)?.isCompact = isCompact
366385
tableView.reloadData()
@@ -1599,6 +1618,7 @@ extension ReaderStreamViewController: UIViewControllerTransitioningDelegate {
15991618

16001619
extension ReaderStreamViewController: UITableViewDelegate, JPScrollViewDelegate {
16011620
func scrollViewDidScroll(_ scrollView: UIScrollView) {
1621+
layoutEmptyStateView()
16021622
processJetpackBannerVisibility(scrollView)
16031623
$titleView.value?.updateAlpha(in: scrollView)
16041624
}

0 commit comments

Comments
 (0)