From cc26fec8c466bd6e5d0c7e76fb6e91cacbb5c570 Mon Sep 17 00:00:00 2001 From: Alex Grebenyuk Date: Thu, 19 Dec 2024 17:48:54 -0500 Subject: [PATCH] Fix crash in Reader stream empty state views (#23908) * Fix crash in Reader empty state views and fix some layout issues * Fix frame conversion --- RELEASE-NOTES.txt | 1 + .../ReaderStreamViewController.swift | 34 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 63410a79a5b0..2a225326cbcd 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -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] diff --git a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift index ce34c4db378f..ae6bca99e855 100644 --- a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift +++ b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift @@ -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() } @@ -352,6 +347,8 @@ import AutomatticTracks if didSetupView { tableView.sizeToFitHeaderView() } + + layoutEmptyStateView() } override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { @@ -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() @@ -1599,6 +1618,7 @@ extension ReaderStreamViewController: UIViewControllerTransitioningDelegate { extension ReaderStreamViewController: UITableViewDelegate, JPScrollViewDelegate { func scrollViewDidScroll(_ scrollView: UIScrollView) { + layoutEmptyStateView() processJetpackBannerVisibility(scrollView) $titleView.value?.updateAlpha(in: scrollView) }