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

Fix: App crashes when tapping more and share button in the Reader Details screen #20490

Merged
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 RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [***] [internal] Refactor uploading photos (from the device photo, the Free Photo library, and other sources) to the WordPress Media Library. Affected areas are where you can choose a photo and upload, including the "Media" screen, adding images to a post, updating site icon, etc. [#20322]
* [**] [WordPress-only] Warns user about sites with only individual plugins not supporting core app features and offers the option to switch to the Jetpack app. [#20408]
* [**] Add a "Personalize Home Tab" button to the bottom of the Home tab that allows changing cards visibility. [#20369]
* [*] [Reader] Fix an issue that was causing the app to crash when tapping the More or Share buttons in Reader Detail screen. [#20490]
Copy link
Contributor

Choose a reason for hiding this comment

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

Notice that since this landed in the release branch after code freeze, the App Store release notes won't include it.

* [*] Block editor: Avoid empty Gallery block error [https://github.com/WordPress/gutenberg/pull/49557]

22.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import UIKit

extension UIPopoverPresentationController {

enum PopoverAnchor {
case view(UIView)
case barButtonItem(UIBarButtonItem)
}
}
25 changes: 23 additions & 2 deletions WordPress/Classes/ViewRelated/Post/PostSharingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ import SVProgressHUD
}

@objc func sharePost(_ title: String, summary: String, link: String?, fromView anchorView: UIView, inViewController viewController: UIViewController) {
sharePost(title, summary: summary, link: link, fromAnchor: .view(anchorView), inViewController: viewController)
}

private func sharePost(_ title: String, summary: String, link: String?, fromAnchor anchor: PopoverAnchor, inViewController viewController: UIViewController) {
let controller = shareController(
title,
summary: summary,
Expand All @@ -59,8 +63,13 @@ import SVProgressHUD
viewController.present(controller, animated: true)
if let presentationController = controller.popoverPresentationController {
presentationController.permittedArrowDirections = .any
presentationController.sourceView = anchorView
presentationController.sourceRect = anchorView.bounds
switch anchor {
case .barButtonItem(let item):
presentationController.barButtonItem = item
case .view(let anchorView):
presentationController.sourceView = anchorView
presentationController.sourceRect = anchorView.bounds
}
}
}

Expand All @@ -84,6 +93,16 @@ import SVProgressHUD
inViewController: viewController)
}

func shareReaderPost(_ post: ReaderPost, fromAnchor anchor: PopoverAnchor, inViewController viewController: UIViewController) {

sharePost(
post.titleForDisplay(),
summary: post.contentPreviewForDisplay(),
link: post.permaLink,
fromAnchor: anchor,
inViewController: viewController)
}

@objc func shareReaderPost(_ post: ReaderPost, fromView anchorView: UIView, inViewController viewController: UIViewController) {

sharePost(
Expand Down Expand Up @@ -114,4 +133,6 @@ import SVProgressHUD
}

}

typealias PopoverAnchor = UIPopoverPresentationController.PopoverAnchor
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,17 @@ class ReaderDetailCoordinator {
/// Share the current post
///
func share(fromView anchorView: UIView) {
self.share(fromAnchor: .view(anchorView))
}

/// Share the current post
///
func share(fromAnchor anchor: UIPopoverPresentationController.PopoverAnchor) {
guard let post = post, let view = viewController else {
return
}

sharingController.shareReaderPost(post, fromView: anchorView, inViewController: view)
sharingController.shareReaderPost(post, fromAnchor: anchor, inViewController: view)

WPAnalytics.trackReader(.readerSharedItem)
}
Expand Down Expand Up @@ -400,7 +406,7 @@ class ReaderDetailCoordinator {

/// Show a menu with options for the current post's site
///
private func showMenu(_ anchorView: UIView) {
private func showMenu(_ anchor: UIPopoverPresentationController.PopoverAnchor) {
guard let post = post,
let context = post.managedObjectContext,
let viewController = viewController,
Expand All @@ -414,7 +420,7 @@ class ReaderDetailCoordinator {
post: post,
context: context,
readerTopic: readerTopic,
anchor: anchorView,
anchor: anchor,
vc: viewController,
source: ReaderPostMenuSource.details,
followCommentsService: followCommentsService
Expand Down Expand Up @@ -680,8 +686,12 @@ extension ReaderDetailCoordinator: ReaderDetailHeaderViewDelegate {
previewSite()
}

func didTapMenuButton(_ sender: UIBarButtonItem) {
showMenu(.barButtonItem(sender))
}

func didTapMenuButton(_ sender: UIView) {
showMenu(sender)
showMenu(.view(sender))
}

func didTapTagButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,15 +704,15 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {

/// Ask the coordinator to present the share sheet
///
@objc func didTapShareButton(_ sender: UIButton) {
coordinator?.share(fromView: sender)
@objc func didTapShareButton(_ sender: UIBarButtonItem) {
coordinator?.share(fromAnchor: .barButtonItem(sender))
}

@objc func didTapMenuButton(_ sender: UIButton) {
@objc func didTapMenuButton(_ sender: UIBarButtonItem) {
coordinator?.didTapMenuButton(sender)
}

@objc func didTapBrowserButton(_ sender: UIButton) {
@objc func didTapBrowserButton(_ sender: UIBarButtonItem) {
coordinator?.openInBrowser()
}

Expand Down
11 changes: 11 additions & 0 deletions WordPress/Classes/ViewRelated/Reader/ReaderMenuAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ final class ReaderMenuAction {
vc: UIViewController,
source: ReaderPostMenuSource,
followCommentsService: FollowCommentsService
) {
self.execute(post: post, context: context, anchor: .view(anchor), vc: vc, source: source, followCommentsService: followCommentsService)
}

func execute(post: ReaderPost,
context: NSManagedObjectContext,
readerTopic: ReaderAbstractTopic? = nil,
anchor: ReaderShowMenuAction.PopoverAnchor,
vc: UIViewController,
source: ReaderPostMenuSource,
followCommentsService: FollowCommentsService
) {
let siteTopic: ReaderSiteTopic? = post.isFollowing ? (try? ReaderSiteTopic.lookup(withSiteID: post.siteID, in: context)) : nil

Expand Down
6 changes: 5 additions & 1 deletion WordPress/Classes/ViewRelated/Reader/ReaderShareAction.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/// Encapsulates a command share a post
final class ReaderShareAction {
func execute(with post: ReaderPost, context: NSManagedObjectContext, anchor: UIView, vc: UIViewController) {
self.execute(with: post, context: context, anchor: .view(anchor), vc: vc)
}

func execute(with post: ReaderPost, context: NSManagedObjectContext, anchor: UIPopoverPresentationController.PopoverAnchor, vc: UIViewController) {
let postID = post.objectID
if let post: ReaderPost = ReaderActionHelpers.existingObject(for: postID, in: context) {
let sharingController = PostSharingController()

sharingController.shareReaderPost(post, fromView: anchor, inViewController: vc)
sharingController.shareReaderPost(post, fromAnchor: anchor, inViewController: vc)
WPAnalytics.trackReader(.itemSharedReader, properties: ["blogId": post.siteID as Any])
}
}
Expand Down
15 changes: 12 additions & 3 deletions WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class ReaderShowMenuAction {
context: NSManagedObjectContext,
siteTopic: ReaderSiteTopic? = nil,
readerTopic: ReaderAbstractTopic? = nil,
anchor: UIView,
anchor: PopoverAnchor,
vc: UIViewController,
source: ReaderPostMenuSource,
followCommentsService: FollowCommentsService
Expand Down Expand Up @@ -194,8 +194,13 @@ final class ReaderShowMenuAction {
vc.present(alertController, animated: true)
if let presentationController = alertController.popoverPresentationController {
presentationController.permittedArrowDirections = .any
presentationController.sourceView = anchor
presentationController.sourceRect = anchor.bounds
switch anchor {
case .barButtonItem(let item):
presentationController.barButtonItem = item
case .view(let anchor):
presentationController.sourceView = anchor
presentationController.sourceRect = anchor.bounds
}
}
} else {
vc.present(alertController, animated: true)
Expand Down Expand Up @@ -283,4 +288,8 @@ final class ReaderShowMenuAction {
let userInfo: [String: Any] = [ReaderNotificationKeys.post: post, ReaderNotificationKeys.result: result]
center.post(name: .ReaderUserBlockingDidEnd, object: nil, userInfo: userInfo)
}

// MARK: - Types

typealias PopoverAnchor = UIPopoverPresentationController.PopoverAnchor
}
6 changes: 6 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3584,6 +3584,8 @@
F49B9A08293A21F4000CEFCE /* MigrationEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49B9A07293A21F4000CEFCE /* MigrationEvent.swift */; };
F49B9A09293A3243000CEFCE /* MigrationEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49B9A07293A21F4000CEFCE /* MigrationEvent.swift */; };
F49B9A0A293A3249000CEFCE /* MigrationAnalyticsTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49B9A05293A21BF000CEFCE /* MigrationAnalyticsTracker.swift */; };
F49D7BEB29DF329500CB93A5 /* UIPopoverPresentationController+PopoverAnchor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49D7BEA29DF329500CB93A5 /* UIPopoverPresentationController+PopoverAnchor.swift */; };
F49D7BEC29DF329500CB93A5 /* UIPopoverPresentationController+PopoverAnchor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49D7BEA29DF329500CB93A5 /* UIPopoverPresentationController+PopoverAnchor.swift */; };
F4BECD1B288EE5220078391A /* SuggestionsViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4BECD1A288EE5220078391A /* SuggestionsViewModelType.swift */; };
F4BECD1C288EE5220078391A /* SuggestionsViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4BECD1A288EE5220078391A /* SuggestionsViewModelType.swift */; };
F4CBE3D429258AE1004FFBB6 /* MeHeaderViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FB0ACC292587D500F651F9 /* MeHeaderViewConfiguration.swift */; };
Expand Down Expand Up @@ -8907,6 +8909,7 @@
F49B99FE2937C9B4000CEFCE /* MigrationEmailService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationEmailService.swift; sourceTree = "<group>"; };
F49B9A05293A21BF000CEFCE /* MigrationAnalyticsTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationAnalyticsTracker.swift; sourceTree = "<group>"; };
F49B9A07293A21F4000CEFCE /* MigrationEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationEvent.swift; sourceTree = "<group>"; };
F49D7BEA29DF329500CB93A5 /* UIPopoverPresentationController+PopoverAnchor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIPopoverPresentationController+PopoverAnchor.swift"; sourceTree = "<group>"; };
F4BECD1A288EE5220078391A /* SuggestionsViewModelType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SuggestionsViewModelType.swift; sourceTree = "<group>"; };
F4CBE3D329258AD6004FFBB6 /* MeHeaderView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MeHeaderView.h; sourceTree = "<group>"; };
F4CBE3D5292597E3004FFBB6 /* SupportTableViewControllerConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportTableViewControllerConfiguration.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -14989,6 +14992,7 @@
FA20751327A86B73001A644D /* UIScrollView+Helpers.swift */,
C7AFF873283C0ADC000E01DF /* UIApplication+Helpers.swift */,
C3AB4878292F114A001F7AF8 /* UIApplication+AppAvailability.swift */,
F49D7BEA29DF329500CB93A5 /* UIPopoverPresentationController+PopoverAnchor.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -21745,6 +21749,7 @@
BE87E1A01BD4054F0075D45B /* WP3DTouchShortcutCreator.swift in Sources */,
742B7F3A209CB2B6002E3CC9 /* GIFPlaybackStrategy.swift in Sources */,
8B6214E327B1B2F3001DF7B6 /* BlogDashboardService.swift in Sources */,
F49D7BEB29DF329500CB93A5 /* UIPopoverPresentationController+PopoverAnchor.swift in Sources */,
F1D8C6E926BA94DF002E3323 /* WordPressBackgroundTaskEventHandler.swift in Sources */,
D8212CC520AA83F9008E8AE8 /* ReaderCommentAction.swift in Sources */,
FAD954B825B7A99900F011B5 /* JetpackBackupStatusFailedViewController.swift in Sources */,
Expand Down Expand Up @@ -23923,6 +23928,7 @@
FABB22512602FC2C00C8785C /* TabbedTotalsCell.swift in Sources */,
B084E61F27E3B79F007BF7A8 /* SiteIntentStep.swift in Sources */,
FABB22522602FC2C00C8785C /* ActivityTableViewCell.swift in Sources */,
F49D7BEC29DF329500CB93A5 /* UIPopoverPresentationController+PopoverAnchor.swift in Sources */,
FABB22532602FC2C00C8785C /* BlogDetailsViewController+FancyAlerts.swift in Sources */,
FABB22542602FC2C00C8785C /* StoriesIntroDataSource.swift in Sources */,
FABB22552602FC2C00C8785C /* StoreContainer.swift in Sources */,
Expand Down