1+ import UIKit
2+ import SwiftUI
13import WordPressData
24import WordPressShared
35import 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 {
130117extension 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
173179private 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
377388private extension PostSocialSharingSettings {
0 commit comments