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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader: Update when the results controller is reset for tags feed #23179

Merged
merged 1 commit into from
May 10, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions WordPress/Classes/Utility/WPTableViewHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
- (void)clearCachedRowHeights;
- (void)refreshCachedRowHeightsForWidth:(CGFloat)width;
- (void)invalidateCachedRowHeightAtIndexPath:(nonnull NSIndexPath *)indexPath;
- (void)resetResultsController;

/**
A convenience method for clearing cached row heights and reloading the table view.
Expand Down
9 changes: 5 additions & 4 deletions WordPress/Classes/Utility/WPTableViewHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ - (void)invalidateCachedRowHeightAtIndexPath:(NSIndexPath *)indexPath
[self clearCachedRowHeightAtIndexPath:indexPath];
}

- (void)resetResultsController
{
_resultsController = nil;
}


#pragma mark - Required Delegate Methods

Expand Down Expand Up @@ -598,10 +603,6 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi

- (NSFetchedResultsController *)resultsController
{
if (_resultsController != nil && ![_resultsController.fetchRequest.entityName isEqualToString:[self fetchRequest].entityName]) {
_resultsController = nil;
}

if (_resultsController != nil) {
return _resultsController;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,7 @@ extension ReaderStreamViewController: ReaderContentViewController {
isContentFiltered = content.topicType == .tag || content.topicType == .site
readerTopic = content.topicType == .discover ? nil : content.topic
contentType = content.type
self.content.resetResultsController()

guard !shouldDisplayNoTopicController else {
return
Expand Down
11 changes: 11 additions & 0 deletions WordPress/Classes/ViewRelated/Reader/ReaderTableContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ final class ReaderTableContent {
tableViewHandler?.delegate = delegate
}

func resetResultsController() {
tableViewHandler?.resetResultsController()
tableViewHandler?.tableView.reloadData()
tableViewHandler?.tableView.layoutIfNeeded()

if !isEmpty {
tableViewHandler?.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to use scrollToRow here because using setContentOffset would scroll too high sometimes above the first card. I believe this was due to the pull-to-refresh.

}
}

/// The fetch request can need a different predicate depending on how the content
/// being displayed has changed (blocking sites for instance). Call this method to
/// update the fetch request predicate and then perform a new fetch.
///
func updateAndPerformFetchRequest(predicate: NSPredicate) {
assert(Thread.isMainThread, "Reader Error: updating fetch request on a background thread.")

tableViewHandler?.resetResultsController()
tableViewHandler?.resultsController?.fetchRequest.predicate = predicate
do {
try tableViewHandler?.resultsController?.performFetch()
Expand Down