Skip to content

Commit 8cd4769

Browse files
authored
Improve post sharing in Reader (#23692)
2 parents 52bd1f3 + 39373ec commit 8cd4769

File tree

10 files changed

+18
-118
lines changed

10 files changed

+18
-118
lines changed

WordPress/Classes/Utility/Sharing/SafariActivity.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ @implementation SafariActivity {
66

77
- (UIImage *)activityImage
88
{
9-
return [UIImage imageNamed:@"Safari"];
9+
return [UIImage systemImageNamed:@"safari"];
1010
}
1111

1212
- (NSString *)activityTitle

WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController/NotificationTableViewCell.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ final class NotificationTableViewCell: HostingTableViewCell<NotificationsTableVi
5959
let sharingController = PostSharingController()
6060
sharingController.sharePost(
6161
content.title,
62-
summary: nil,
6362
link: content.url,
6463
fromView: self,
6564
inViewController: parent
Lines changed: 13 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import Foundation
2+
import UIKit
23
import SVProgressHUD
34

45
@objc class PostSharingController: NSObject {
56

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

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

15-
if let str = title {
16-
controller.setValue(str, forKey: "subject")
15+
if let title {
16+
controller.setValue(title, forKey: "subject")
1717
}
1818
controller.completionWithItemsHandler = { (activityType, completed, returnedItems, error) in
1919
if completed {
@@ -24,11 +24,8 @@ import SVProgressHUD
2424
return controller
2525
}
2626

27-
@objc func sharePost(_ title: String, summary: String, link: String?, fromBarButtonItem anchorBarButtonItem: UIBarButtonItem, inViewController viewController: UIViewController) {
28-
let controller = shareController(
29-
title,
30-
summary: summary,
31-
link: link)
27+
@objc func sharePost(_ title: String, link: String?, fromBarButtonItem anchorBarButtonItem: UIBarButtonItem, inViewController viewController: UIViewController) {
28+
let controller = shareController(title, link: link)
3229

3330
if !UIDevice.isPad() {
3431
viewController.present(controller, animated: true)
@@ -44,16 +41,12 @@ import SVProgressHUD
4441
}
4542
}
4643

47-
@objc func sharePost(_ title: String?, summary: String?, link: String?, fromView anchorView: UIView, inViewController viewController: UIViewController) {
48-
sharePost(title, summary: summary, link: link, fromAnchor: .view(anchorView), inViewController: viewController)
44+
@objc func sharePost(_ title: String?, link: String?, fromView anchorView: UIView, inViewController viewController: UIViewController) {
45+
sharePost(title, link: link, fromAnchor: .view(anchorView), inViewController: viewController)
4946
}
5047

51-
private func sharePost(_ title: String?, summary: String?, link: String?, fromAnchor anchor: PopoverAnchor, inViewController viewController: UIViewController) {
52-
let controller = shareController(
53-
title,
54-
summary: summary,
55-
link: link)
56-
48+
private func sharePost(_ title: String?, link: String?, fromAnchor anchor: PopoverAnchor, inViewController viewController: UIViewController) {
49+
let controller = shareController(title, link: link)
5750
if !UIDevice.isPad() {
5851
viewController.present(controller, animated: true)
5952
return
@@ -75,57 +68,47 @@ import SVProgressHUD
7568
}
7669

7770
@objc func sharePage(_ page: Page, fromView anchorView: UIView, inViewController viewController: UIViewController) {
78-
7971
sharePost(
8072
page.titleForDisplay(),
81-
summary: page.contentPreviewForDisplay(),
8273
link: page.permaLink,
8374
fromView: anchorView,
8475
inViewController: viewController)
8576
}
8677

8778
@objc func sharePost(_ post: Post, fromBarButtonItem anchorBarButtonItem: UIBarButtonItem, inViewController viewController: UIViewController) {
88-
8979
sharePost(
9080
post.titleForDisplay(),
91-
summary: post.contentPreviewForDisplay(),
9281
link: post.permaLink,
9382
fromBarButtonItem: anchorBarButtonItem,
9483
inViewController: viewController)
9584
}
9685

9786
@objc func sharePost(_ post: Post, fromView anchorView: UIView, inViewController viewController: UIViewController) {
98-
9987
sharePost(
10088
post.titleForDisplay(),
101-
summary: post.contentPreviewForDisplay(),
10289
link: post.permaLink,
10390
fromView: anchorView,
10491
inViewController: viewController)
10592
}
10693

10794
func shareReaderPost(_ post: ReaderPost, fromAnchor anchor: PopoverAnchor, inViewController viewController: UIViewController) {
108-
10995
sharePost(
11096
post.titleForDisplay(),
111-
summary: post.contentPreviewForDisplay(),
11297
link: post.permaLink,
11398
fromAnchor: anchor,
11499
inViewController: viewController)
115100
}
116101

117102
@objc func shareReaderPost(_ post: ReaderPost, fromView anchorView: UIView, inViewController viewController: UIViewController) {
118-
119103
sharePost(
120104
post.titleForDisplay(),
121-
summary: post.contentPreviewForDisplay(),
122105
link: post.permaLink,
123106
fromView: anchorView,
124107
inViewController: viewController)
125108
}
126109

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

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

148131
typealias PopoverAnchor = UIPopoverPresentationController.PopoverAnchor
149132
}
150-
151-
private class CopyLinkActivity: UIActivity {
152-
var activityItems = [Any]()
153-
private var url = URL(string: "")
154-
155-
override var activityTitle: String? {
156-
return NSLocalizedString(
157-
"share.sheet.copy.link.title",
158-
value: "Copy Link",
159-
comment: "Title for the \"Copy Link\" action in Share Sheet."
160-
)
161-
}
162-
163-
override var activityImage: UIImage? {
164-
return UIImage(systemName: "link")
165-
}
166-
167-
override var activityType: UIActivity.ActivityType? {
168-
return UIActivity.ActivityType(rawValue: "copy.link.activity")
169-
}
170-
171-
override class var activityCategory: UIActivity.Category {
172-
return .action
173-
}
174-
175-
override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
176-
for activityItem in activityItems {
177-
if let _ = activityItem as? URL {
178-
return true
179-
}
180-
}
181-
return false
182-
}
183-
184-
override func prepare(withActivityItems activityItems: [Any]) {
185-
for activityItem in activityItems {
186-
if let url = activityItem as? URL {
187-
self.url = url
188-
}
189-
}
190-
self.activityItems = activityItems
191-
}
192-
193-
override func perform() {
194-
guard let url else {
195-
return
196-
}
197-
UIPasteboard.general.string = url.absoluteString
198-
activityDidFinish(true)
199-
}
200-
}

WordPress/Classes/ViewRelated/Reader/Detail/Views/ReaderDetailNewHeaderView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ struct ReaderDetailNewHeaderView: View {
260260
.font(Font(viewModel.displaySetting.font(with: .title1, weight: .bold)))
261261
.foregroundStyle(Color(primaryTextColor))
262262
.lineLimit(nil)
263+
.textSelection(.enabled)
263264
.fixedSize(horizontal: false, vertical: true) // prevents the title from being truncated.
264265
}
265266
if viewModel.likeCountString != nil || viewModel.commentCountString != nil {

WordPress/Resources/AppImages.xcassets/Safari.imageset/Contents.json

Lines changed: 0 additions & 32 deletions
This file was deleted.
-648 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

WordPress/WordPressTest/Posts/PostSharingControllerTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class PostSharingControllerTests: XCTestCase {
99

1010
let sharingController = PostSharingController()
1111

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

15-
controller = sharingController.shareController("", summary: "", link: "")
15+
controller = sharingController.shareController("", link: "")
1616
XCTAssertNotNil(controller, "Controller should not be nil")
1717

18-
controller = sharingController.shareController(nil, summary: nil, link: nil)
18+
controller = sharingController.shareController(nil, link: nil)
1919
XCTAssertNotNil(controller, "Controller should not be nil")
2020
}
2121

0 commit comments

Comments
 (0)