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

Reader: Add context menus #23808

Merged
merged 1 commit into from
Nov 15, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -53,6 +53,7 @@

- (nullable UISwipeActionsConfiguration *)tableView:(nonnull UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath;
- (nullable UISwipeActionsConfiguration *)tableView:(nonnull UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath;
- (nullable UIContextMenuConfiguration *)tableView:(nonnull UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath point:(CGPoint)point;

#pragma mark - Tracking the removal of views

Expand Down
7 changes: 7 additions & 0 deletions WordPress/Classes/Utility/WPTableViewHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[self.delegate tableView:tableView didSelectRowAtIndexPath:indexPath];
}

- (UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point {
if ([self.delegate respondsToSelector:@selector(tableView:contextMenuConfigurationForRowAtIndexPath:point:)]) {
return [self.delegate tableView:tableView contextMenuConfigurationForRowAtIndexPath:indexPath point:point];
}
return nil;
}


#pragma mark - Optional Delegate Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ private class ReaderDiscoverStreamViewController: ReaderStreamViewController {
super.syncIfAppropriate(forceSync: true)
tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.fade)
}

override func getPost(at indexPath: IndexPath) -> ReaderPost? {
guard let card: ReaderCard = content.object(at: indexPath) else {
return nil
}
return card.post
}
}

// MARK: - ReaderRecommendedSitesCellDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,10 @@ import AutomatticTracks
completion?(false)
})
}

func getPost(at indexPath: IndexPath) -> ReaderPost? {
content.object(at: indexPath)
}
}

// MARK: - ReaderStreamHeaderDelegate
Expand Down Expand Up @@ -1447,6 +1451,20 @@ extension ReaderStreamViewController: WPTableViewHandlerDelegate {
// Do nothing
}

func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
guard let post = getPost(at: indexPath) else {
return nil
}
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ in
guard let self else { return nil }
return UIMenu(children: ReaderPostMenu(
post: post,
topic: readerTopic,
anchor: self.tableView.cellForRow(at: indexPath) ?? self.view,
viewController: self
).makeMenu())
}
}
}

// MARK: - SearchableActivity Conformance
Expand Down