Skip to content

Commit 4f416c1

Browse files
authored
Show message in a separate section (#24953)
1 parent 73c3f0c commit 4f416c1

2 files changed

Lines changed: 107 additions & 62 deletions

File tree

WordPress/Classes/ViewRelated/Post/Publishing/Views/PrepublishingSocialAccountsViewController.swift

Lines changed: 73 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import UIKit
2+
import SwiftUI
13
import WordPressData
24
import WordPressShared
35
import WordPressUI
@@ -37,7 +39,7 @@ class PrepublishingSocialAccountsViewController: UITableViewController {
3739

3840
private var shareMessage: String {
3941
didSet {
40-
messageCell.detailTextLabel?.text = shareMessage
42+
tableView.reloadData()
4143
}
4244
}
4345

@@ -61,22 +63,6 @@ class PrepublishingSocialAccountsViewController: UITableViewController {
6163
/// instead of having it abruptly stopped due to the table view reload.
6264
private var lastToggledRow: Int = -1
6365

64-
private lazy var messageCell: UITableViewCell = {
65-
let cell = UITableViewCell(style: .value1, reuseIdentifier: Constants.messageCellIdentifier)
66-
WPStyleGuide.configureTableViewCell(cell)
67-
68-
cell.textLabel?.text = Constants.messageCellLabelText
69-
cell.textLabel?.adjustsFontForContentSizeCategory = true
70-
cell.detailTextLabel?.text = shareMessage
71-
cell.detailTextLabel?.adjustsFontForContentSizeCategory = true
72-
if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
73-
cell.detailTextLabel?.numberOfLines = 3
74-
}
75-
cell.accessoryType = .disclosureIndicator
76-
77-
return cell
78-
}()
79-
8066
// MARK: Methods
8167

8268
required init?(coder: NSCoder) {
@@ -108,9 +94,10 @@ class PrepublishingSocialAccountsViewController: UITableViewController {
10894
override func viewDidLoad() {
10995
super.viewDidLoad()
11096

111-
title = Constants.navigationTitle
97+
title = Strings.navigationTitle
11298

11399
tableView.register(SwitchTableViewCell.self, forCellReuseIdentifier: Constants.accountCellIdentifier)
100+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: Constants.messageCellIdentifier)
114101

115102
// setting a custom spacer view will override the default 34pt padding from the grouped table view style.
116103
tableView.tableHeaderView = UIView(frame: .init(x: 0, y: 0, width: 0, height: Constants.tableTopPadding))
@@ -130,29 +117,48 @@ class PrepublishingSocialAccountsViewController: UITableViewController {
130117
extension PrepublishingSocialAccountsViewController {
131118

132119
override func numberOfSections(in tableView: UITableView) -> Int {
133-
return 1
120+
return 2
134121
}
135122

136123
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
137-
return connections.count + 1 // extra row for the sharing message
124+
switch section {
125+
case 0: connections.count
126+
case 1: 1
127+
default: fatalError("invalid section")
128+
}
138129
}
139130

140131
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
141-
if indexPath.row < connections.count {
132+
switch indexPath.section {
133+
case 0:
142134
return accountCell(for: indexPath)
135+
case 1:
136+
let cell = tableView.dequeueReusableCell(withIdentifier: Constants.messageCellIdentifier, for: indexPath)
137+
cell.contentConfiguration = UIHostingConfiguration {
138+
SocialSharingMessageRow(text: shareMessage)
139+
}
140+
cell.accessoryType = .disclosureIndicator
141+
return cell
142+
default: fatalError("invalid section")
143143
}
144-
145-
return messageCell
146144
}
147145

148146
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
149147
// interactions for the account switches are absorbed by the tap gestures set up in the SwitchTableViewCell,
150148
// so it shouldn't trigger this method. In any case, we should only care about handling taps on the message row.
151-
guard indexPath.row == connections.count else {
152-
return
149+
switch indexPath.section {
150+
case 0: break // Do nothing
151+
case 1: showEditMessageScreen()
152+
default: fatalError("invalid section")
153153
}
154+
}
154155

155-
showEditMessageScreen()
156+
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
157+
switch section {
158+
case 0: Strings.servicesSectionTitle
159+
case 1: Strings.messageCellLabelText
160+
default: fatalError("invalid section")
161+
}
156162
}
157163

158164
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
@@ -171,7 +177,6 @@ extension PrepublishingSocialAccountsViewController {
171177
// MARK: - Private Helpers
172178

173179
private extension PrepublishingSocialAccountsViewController {
174-
175180
var enabledCount: Int {
176181
connections
177182
.filter { connectionChanges[$0.keyringID] ?? $0.isOn }
@@ -247,12 +252,14 @@ private extension PrepublishingSocialAccountsViewController {
247252
}
248253

249254
func showEditMessageScreen() {
250-
let multiTextViewController = SettingsMultiTextViewController(text: shareMessage,
251-
placeholder: nil,
252-
hint: Constants.editShareMessageHint,
253-
isPassword: false)
255+
let multiTextViewController = SettingsMultiTextViewController(
256+
text: shareMessage,
257+
placeholder: nil,
258+
hint: Strings.editShareMessageHint,
259+
isPassword: false
260+
)
254261

255-
multiTextViewController.title = Constants.editShareMessageNavigationTitle
262+
multiTextViewController.title = Strings.editShareMessageNavigationTitle
256263
multiTextViewController.onValueChanged = { [weak self] newValue in
257264
self?.shareMessage = newValue
258265
}
@@ -340,38 +347,42 @@ private extension PrepublishingSocialAccountsViewController {
340347

341348
static let webViewSource = "prepublishing_social_accounts_subscribe"
342349
static let trackingSource = "pre_publishing"
343-
344-
static let navigationTitle = NSLocalizedString(
345-
"prepublishing.socialAccounts.navigationTitle",
346-
value: "Social",
347-
comment: "The navigation title for the pre-publishing social accounts screen."
348-
)
349-
350-
static let messageCellLabelText = NSLocalizedString(
351-
"prepublishing.socialAccounts.message.label",
352-
value: "Message",
353-
comment: """
354-
The label displayed for a table row that displays the sharing message for the post.
355-
Tapping on this row allows the user to edit the sharing message.
356-
"""
357-
)
358-
359-
static let editShareMessageNavigationTitle = NSLocalizedString(
360-
"prepublishing.socialAccounts.editMessage.navigationTitle",
361-
value: "Customize message",
362-
comment: "The navigation title for a screen that edits the sharing message for the post."
363-
)
364-
365-
static let editShareMessageHint = NSLocalizedString(
366-
"prepublishing.socialAccounts.editMessage.hint",
367-
value: """
368-
Customize the message you want to share.
369-
If you don't add your own text here, we'll use the post's title as the message.
370-
""",
371-
comment: "A hint shown below the text field when editing the sharing message from the pre-publishing flow."
372-
)
373350
}
351+
}
374352

353+
private enum Strings {
354+
static let navigationTitle = NSLocalizedString(
355+
"prepublishing.socialAccounts.navigationTitle",
356+
value: "Social",
357+
comment: "The navigation title for the pre-publishing social accounts screen."
358+
)
359+
360+
static let servicesSectionTitle = NSLocalizedString(
361+
"prepublishing.socialAccounts.servicesSectionTitle",
362+
value: "Services",
363+
comment: "Table section title"
364+
)
365+
366+
static let messageCellLabelText = NSLocalizedString(
367+
"prepublishing.socialAccounts.message.label",
368+
value: "Message",
369+
comment: "Table section title"
370+
)
371+
372+
static let editShareMessageNavigationTitle = NSLocalizedString(
373+
"prepublishing.socialAccounts.editMessage.navigationTitle",
374+
value: "Customize message",
375+
comment: "The navigation title for a screen that edits the sharing message for the post."
376+
)
377+
378+
static let editShareMessageHint = NSLocalizedString(
379+
"prepublishing.socialAccounts.editMessage.hint",
380+
value: """
381+
Customize the message you want to share.
382+
If you don't add your own text here, we'll use the post's title as the message.
383+
""",
384+
comment: "A hint shown below the text field when editing the sharing message from the pre-publishing flow."
385+
)
375386
}
376387

377388
private extension PostSocialSharingSettings {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import SwiftUI
2+
3+
struct SocialSharingMessageRow: View {
4+
var text: String
5+
6+
var body: some View {
7+
VStack(alignment: .leading, spacing: 6) {
8+
Text(text.isEmpty ? Strings.placeholder : text)
9+
.lineLimit(3)
10+
.foregroundColor(text.isEmpty ? Color(.tertiaryLabel) : .primary)
11+
.font(.body)
12+
.multilineTextAlignment(.leading)
13+
14+
if !text.isEmpty {
15+
Text("\(text.count) characters")
16+
.font(.caption)
17+
.foregroundColor(.secondary)
18+
}
19+
}
20+
.frame(maxWidth: .infinity, alignment: .leading)
21+
}
22+
23+
static var localizedPlaceholderText: String {
24+
Strings.placeholder
25+
}
26+
}
27+
28+
private enum Strings {
29+
static let placeholder = NSLocalizedString(
30+
"prepublishing.socialAccounts.messagePlaceholder",
31+
value: "Write a brief message to share on social media alognside the post",
32+
comment: "Placeholder text for the message field in Social Sharing"
33+
)
34+
}

0 commit comments

Comments
 (0)