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

Improve post sharing in Reader #23692

Merged
merged 1 commit into from
Oct 24, 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
2 changes: 1 addition & 1 deletion WordPress/Classes/Utility/Sharing/SafariActivity.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ @implementation SafariActivity {

- (UIImage *)activityImage
{
return [UIImage imageNamed:@"Safari"];
return [UIImage systemImageNamed:@"safari"];
}

- (NSString *)activityTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ final class NotificationTableViewCell: HostingTableViewCell<NotificationsTableVi
let sharingController = PostSharingController()
sharingController.sharePost(
content.title,
summary: nil,
link: content.url,
fromView: self,
inViewController: parent
Expand Down
94 changes: 13 additions & 81 deletions WordPress/Classes/ViewRelated/Post/PostSharingController.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import Foundation
import UIKit
import SVProgressHUD

@objc class PostSharingController: NSObject {

@objc func shareController(_ title: String?, summary: String?, link: String?) -> UIActivityViewController {
@objc func shareController(_ title: String?, link: String?) -> UIActivityViewController {
let url = link.flatMap(URL.init(string:))
let allItems: [Any?] = [title, summary, url]
let allItems: [Any?] = [url]
let nonNilActivityItems = allItems.compactMap({ $0 })

var activities: [UIActivity] = [CopyLinkActivity()]
activities.append(contentsOf: WPActivityDefaults.defaultActivities() as! [UIActivity])
let activities = WPActivityDefaults.defaultActivities() as! [UIActivity]
let controller = UIActivityViewController(activityItems: nonNilActivityItems, applicationActivities: activities)

if let str = title {
controller.setValue(str, forKey: "subject")
if let title {
controller.setValue(title, forKey: "subject")
}
controller.completionWithItemsHandler = { (activityType, completed, returnedItems, error) in
if completed {
Expand All @@ -24,11 +24,8 @@ import SVProgressHUD
return controller
}

@objc func sharePost(_ title: String, summary: String, link: String?, fromBarButtonItem anchorBarButtonItem: UIBarButtonItem, inViewController viewController: UIViewController) {
let controller = shareController(
title,
summary: summary,
link: link)
@objc func sharePost(_ title: String, link: String?, fromBarButtonItem anchorBarButtonItem: UIBarButtonItem, inViewController viewController: UIViewController) {
let controller = shareController(title, link: link)

if !UIDevice.isPad() {
viewController.present(controller, animated: true)
Expand All @@ -44,16 +41,12 @@ 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)
@objc func sharePost(_ title: String?, link: String?, fromView anchorView: UIView, inViewController viewController: UIViewController) {
sharePost(title, 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,
link: link)

private func sharePost(_ title: String?, link: String?, fromAnchor anchor: PopoverAnchor, inViewController viewController: UIViewController) {
let controller = shareController(title, link: link)
if !UIDevice.isPad() {
viewController.present(controller, animated: true)
return
Expand All @@ -75,57 +68,47 @@ import SVProgressHUD
}

@objc func sharePage(_ page: Page, fromView anchorView: UIView, inViewController viewController: UIViewController) {

sharePost(
page.titleForDisplay(),
summary: page.contentPreviewForDisplay(),
link: page.permaLink,
fromView: anchorView,
inViewController: viewController)
}

@objc func sharePost(_ post: Post, fromBarButtonItem anchorBarButtonItem: UIBarButtonItem, inViewController viewController: UIViewController) {

sharePost(
post.titleForDisplay(),
summary: post.contentPreviewForDisplay(),
link: post.permaLink,
fromBarButtonItem: anchorBarButtonItem,
inViewController: viewController)
}

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

sharePost(
post.titleForDisplay(),
summary: post.contentPreviewForDisplay(),
link: post.permaLink,
fromView: anchorView,
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(
post.titleForDisplay(),
summary: post.contentPreviewForDisplay(),
link: post.permaLink,
fromView: anchorView,
inViewController: viewController)
}

@objc func shareURL(url: NSURL, fromRect rect: CGRect, inView view: UIView, inViewController viewController: UIViewController) {
let controller = shareController("", summary: "", link: url.absoluteString)
let controller = shareController("", link: url.absoluteString)

if !UIDevice.isPad() {
viewController.present(controller, animated: true)
Expand All @@ -147,54 +130,3 @@ import SVProgressHUD

typealias PopoverAnchor = UIPopoverPresentationController.PopoverAnchor
}

private class CopyLinkActivity: UIActivity {
var activityItems = [Any]()
private var url = URL(string: "")

override var activityTitle: String? {
return NSLocalizedString(
"share.sheet.copy.link.title",
value: "Copy Link",
comment: "Title for the \"Copy Link\" action in Share Sheet."
)
}

override var activityImage: UIImage? {
return UIImage(systemName: "link")
}

override var activityType: UIActivity.ActivityType? {
return UIActivity.ActivityType(rawValue: "copy.link.activity")
}

override class var activityCategory: UIActivity.Category {
return .action
}

override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
for activityItem in activityItems {
if let _ = activityItem as? URL {
return true
}
}
return false
}

override func prepare(withActivityItems activityItems: [Any]) {
for activityItem in activityItems {
if let url = activityItem as? URL {
self.url = url
}
}
self.activityItems = activityItems
}

override func perform() {
guard let url else {
return
}
UIPasteboard.general.string = url.absoluteString
activityDidFinish(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ struct ReaderDetailNewHeaderView: View {
.font(Font(viewModel.displaySetting.font(with: .title1, weight: .bold)))
.foregroundStyle(Color(primaryTextColor))
.lineLimit(nil)
.textSelection(.enabled)
.fixedSize(horizontal: false, vertical: true) // prevents the title from being truncated.
}
if viewModel.likeCountString != nil || viewModel.commentCountString != nil {
Expand Down

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class PostSharingControllerTests: XCTestCase {

let sharingController = PostSharingController()

var controller = sharingController.shareController("test", summary: "test", link: "test")
var controller = sharingController.shareController("test", link: "test")
XCTAssertNotNil(controller, "Controller should not be nil")

controller = sharingController.shareController("", summary: "", link: "")
controller = sharingController.shareController("", link: "")
XCTAssertNotNil(controller, "Controller should not be nil")

controller = sharingController.shareController(nil, summary: nil, link: nil)
controller = sharingController.shareController(nil, link: nil)
XCTAssertNotNil(controller, "Controller should not be nil")
}

Expand Down