From 4bcda12d60a7a7fec2175b8847bdb3cdce6670f5 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 17 Aug 2021 18:09:48 -0600 Subject: [PATCH 1/4] Add feature flag for new comment edit view. --- WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift b/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift index 4c431648153a..688f175ea1e7 100644 --- a/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift +++ b/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift @@ -13,6 +13,7 @@ enum FeatureFlag: Int, CaseIterable, OverrideableFlag { case siteIconCreator case editorOnboardingHelpMenu case unifiedCommentsAndNotificationsList + case newCommentEdit /// Returns a boolean indicating if the feature is enabled var enabled: Bool { @@ -43,6 +44,8 @@ enum FeatureFlag: Int, CaseIterable, OverrideableFlag { return BuildConfiguration.current ~= [.localDeveloper, .a8cBranchTest] case .unifiedCommentsAndNotificationsList: return true + case .newCommentEdit: + return false } } @@ -91,6 +94,8 @@ extension FeatureFlag { return "Editor Onboarding Help Menu" case .unifiedCommentsAndNotificationsList: return "Unified List for Comments and Notifications" + case .newCommentEdit: + return "New Comment Edit" } } From d8cf1c9429c46ab9ff11ce74c26dab31460b4430 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 17 Aug 2021 18:10:05 -0600 Subject: [PATCH 2/4] Add initial edit comment view. --- .../EditCommentTableViewController.swift | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 WordPress/Classes/ViewRelated/Comments/EditCommentTableViewController.swift diff --git a/WordPress/Classes/ViewRelated/Comments/EditCommentTableViewController.swift b/WordPress/Classes/ViewRelated/Comments/EditCommentTableViewController.swift new file mode 100644 index 000000000000..d20da9983d4b --- /dev/null +++ b/WordPress/Classes/ViewRelated/Comments/EditCommentTableViewController.swift @@ -0,0 +1,88 @@ +import Foundation + + +class EditCommentTableViewController: UITableViewController { + + // MARK: - Properties + + private let sectionHeaders = + [NSLocalizedString("Name", comment: "Header for a comment author's name, shown when editing a comment.").localizedUppercase, + NSLocalizedString("Comment", comment: "Header for a comment's content, shown when editing a comment.").localizedUppercase, + NSLocalizedString("Web Address", comment: "Header for a comment author's web address, shown when editing a comment.").localizedUppercase, + NSLocalizedString("Email Address", comment: "Header for a comment author's email address, shown when editing a comment.").localizedUppercase] + + // MARK: - Init + + required convenience init() { + self.init(style: .insetGrouped) + } + + override init(style: UITableView.Style) { + super.init(style: style) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - View + + override func viewDidLoad() { + super.viewDidLoad() + setupNavBar() + } + + // MARK: - UITableViewDelegate + + override func numberOfSections(in tableView: UITableView) -> Int { + return sectionHeaders.count + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + return sectionHeaders[safe: section] + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + // TODO: return custom cell + return UITableViewCell() + } + + override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + // Make sure no SectionFooter is rendered + return CGFloat.leastNormalMagnitude + } + + override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { + // Make sure no SectionFooter is rendered + return nil + } + +} + +private extension EditCommentTableViewController { + + // MARK: - View Config + + func setupNavBar() { + title = NSLocalizedString("Edit Comment", comment: "View title when editing a comment.") + navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelButtonTapped)) + navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(doneButtonTapped)) + } + + // MARK: - Nav bar button actions + + @objc func cancelButtonTapped(sender: UIBarButtonItem) { + // TODO: discard changes + dismiss(animated: true) + } + + @objc func doneButtonTapped(sender: UIBarButtonItem) { + // TODO: save changes + dismiss(animated: true) + } + +} From 2555545dfcc8012552ba9e182a4011f02325f042 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 17 Aug 2021 18:10:24 -0600 Subject: [PATCH 3/4] Show new edit comment view based on feature flag. --- .../Comments/CommentViewController.m | 32 ++++++++++++------- .../NotificationDetailsViewController.swift | 31 +++++++++++------- WordPress/WordPress.xcodeproj/project.pbxproj | 6 ++++ 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Comments/CommentViewController.m b/WordPress/Classes/ViewRelated/Comments/CommentViewController.m index 3b7b4646bf3f..208a13cf3497 100644 --- a/WordPress/Classes/ViewRelated/Comments/CommentViewController.m +++ b/WordPress/Classes/ViewRelated/Comments/CommentViewController.m @@ -640,19 +640,27 @@ - (void)spamAction - (void)editComment { - EditCommentViewController *editViewController = [EditCommentViewController newEditViewController]; - editViewController.content = [self.comment contentForEdit]; - - __typeof(self) __weak weakSelf = self; - editViewController.onCompletion = ^(BOOL hasNewContent, NSString *newContent) { - [self dismissViewControllerAnimated:YES completion:^{ - if (hasNewContent) { - [weakSelf updateCommentForNewContent:newContent]; - } - }]; - }; + UINavigationController *navController; + + if ([Feature enabled:FeatureFlagNewCommentEdit]) { + EditCommentTableViewController *editViewController = [[EditCommentTableViewController alloc] init]; + navController = [[UINavigationController alloc] initWithRootViewController:editViewController]; + } else { + EditCommentViewController *editViewController = [EditCommentViewController newEditViewController]; + editViewController.content = [self.comment contentForEdit]; + + __typeof(self) __weak weakSelf = self; + editViewController.onCompletion = ^(BOOL hasNewContent, NSString *newContent) { + [self dismissViewControllerAnimated:YES completion:^{ + if (hasNewContent) { + [weakSelf updateCommentForNewContent:newContent]; + } + }]; + }; + + navController = [[UINavigationController alloc] initWithRootViewController:editViewController]; + } - UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:editViewController]; navController.modalPresentationStyle = UIModalPresentationFormSheet; navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; navController.navigationBar.translucent = NO; diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift index 9a764443ad42..4ee4607083a5 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift @@ -1223,19 +1223,28 @@ private extension NotificationDetailsViewController { } func displayCommentEditorWithBlock(_ block: FormattableCommentContent) { - let editViewController = EditCommentViewController.newEdit() - editViewController?.content = block.text - editViewController?.onCompletion = { (hasNewContent, newContent) in - self.dismiss(animated: true, completion: { - guard hasNewContent else { - return - } - let newContent = newContent ?? "" - self.updateComment(with: block, content: newContent) - }) + + var navController: UINavigationController + + if FeatureFlag.newCommentEdit.enabled { + let editViewController = EditCommentTableViewController() + navController = UINavigationController(rootViewController: editViewController) + } else { + let editViewController = EditCommentViewController.newEdit() + editViewController?.content = block.text + editViewController?.onCompletion = { (hasNewContent, newContent) in + self.dismiss(animated: true, completion: { + guard hasNewContent else { + return + } + let newContent = newContent ?? "" + self.updateComment(with: block, content: newContent) + }) + } + + navController = UINavigationController(rootViewController: editViewController!) } - let navController = UINavigationController(rootViewController: editViewController!) navController.modalPresentationStyle = .formSheet navController.modalTransitionStyle = .coverVertical navController.navigationBar.isTranslucent = false diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index d443efa8dd02..c74290e01a37 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -1586,6 +1586,8 @@ 98906508237CC1DF00218CD2 /* WidgetTwoColumnCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 989064FE237CC1DE00218CD2 /* WidgetTwoColumnCell.xib */; }; 98906509237CC1DF00218CD2 /* WidgetTwoColumnCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 989064FE237CC1DE00218CD2 /* WidgetTwoColumnCell.xib */; }; 98921EF721372E12004949AA /* MediaCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98921EF621372E12004949AA /* MediaCoordinator.swift */; }; + 9895401126C1F39300EDEB5A /* EditCommentTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9895401026C1F39300EDEB5A /* EditCommentTableViewController.swift */; }; + 9895401226C1F39300EDEB5A /* EditCommentTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9895401026C1F39300EDEB5A /* EditCommentTableViewController.swift */; }; 9895B6E021ED49160053D370 /* TopTotalsCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9895B6DF21ED49160053D370 /* TopTotalsCell.xib */; }; 989643E223A02F080070720A /* WidgetUnconfiguredCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 989064FB237CC1DE00218CD2 /* WidgetUnconfiguredCell.swift */; }; 989643E423A02F4E0070720A /* UIColor+MurielColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 435B762122973D0600511813 /* UIColor+MurielColors.swift */; }; @@ -6235,6 +6237,7 @@ 989064FD237CC1DE00218CD2 /* WidgetTwoColumnCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidgetTwoColumnCell.swift; sourceTree = ""; }; 989064FE237CC1DE00218CD2 /* WidgetTwoColumnCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WidgetTwoColumnCell.xib; sourceTree = ""; }; 98921EF621372E12004949AA /* MediaCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaCoordinator.swift; sourceTree = ""; }; + 9895401026C1F39300EDEB5A /* EditCommentTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditCommentTableViewController.swift; sourceTree = ""; }; 9895B6DF21ED49160053D370 /* TopTotalsCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TopTotalsCell.xib; sourceTree = ""; }; 989643EA23A0437B0070720A /* WidgetDifferenceCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetDifferenceCell.swift; sourceTree = ""; }; 989643EB23A0437B0070720A /* WidgetDifferenceCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = WidgetDifferenceCell.xib; sourceTree = ""; }; @@ -12379,6 +12382,7 @@ 313AE49B19E3F20400AAFABE /* CommentViewController.h */, 313AE49C19E3F20400AAFABE /* CommentViewController.m */, B0AC50B3251E959B0039E022 /* CommentViewController.swift */, + 9895401026C1F39300EDEB5A /* EditCommentTableViewController.swift */, 2906F80F110CDA8900169D56 /* EditCommentViewController.h */, 2906F810110CDA8900169D56 /* EditCommentViewController.m */, 328CEC5D23A532BA00A6899E /* FullScreenCommentReplyViewController.swift */, @@ -17276,6 +17280,7 @@ 400A2C772217A8A0000A8A59 /* VisitsSummaryStatsRecordValue+CoreDataClass.swift in Sources */, D8212CB320AA6861008E8AE8 /* ReaderFollowAction.swift in Sources */, F5D399302541F25B0058D0AB /* SheetActions.swift in Sources */, + 9895401126C1F39300EDEB5A /* EditCommentTableViewController.swift in Sources */, 8B7F51C924EED804008CF5B5 /* ReaderTracker.swift in Sources */, E6F2788421BC1A4A008B4DB5 /* PlanFeature.swift in Sources */, 3F421DF524A3EC2B00CA9B9E /* Spotlightable.swift in Sources */, @@ -19712,6 +19717,7 @@ FABB23F12602FC2C00C8785C /* DefaultStockPhotosService.swift in Sources */, FABB23F22602FC2C00C8785C /* Animator.swift in Sources */, FABB23F32602FC2C00C8785C /* SiteStatsDashboardViewController.swift in Sources */, + 9895401226C1F39300EDEB5A /* EditCommentTableViewController.swift in Sources */, FABB23F42602FC2C00C8785C /* MediaSettings.swift in Sources */, FABB23F52602FC2C00C8785C /* DomainCreditRedemptionSuccessViewController.swift in Sources */, FABB23F62602FC2C00C8785C /* ActivityLogDetailViewController.m in Sources */, From b6e490507e31681c3585705d1f059757eac7e5c8 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 18 Aug 2021 12:46:48 -0600 Subject: [PATCH 4/4] Show new edit comment in full screen modal. --- WordPress/Classes/ViewRelated/Comments/CommentViewController.m | 3 ++- .../Controllers/NotificationDetailsViewController.swift | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Comments/CommentViewController.m b/WordPress/Classes/ViewRelated/Comments/CommentViewController.m index 208a13cf3497..f6fec4907443 100644 --- a/WordPress/Classes/ViewRelated/Comments/CommentViewController.m +++ b/WordPress/Classes/ViewRelated/Comments/CommentViewController.m @@ -645,6 +645,7 @@ - (void)editComment if ([Feature enabled:FeatureFlagNewCommentEdit]) { EditCommentTableViewController *editViewController = [[EditCommentTableViewController alloc] init]; navController = [[UINavigationController alloc] initWithRootViewController:editViewController]; + navController.modalPresentationStyle = UIModalPresentationFullScreen; } else { EditCommentViewController *editViewController = [EditCommentViewController newEditViewController]; editViewController.content = [self.comment contentForEdit]; @@ -659,9 +660,9 @@ - (void)editComment }; navController = [[UINavigationController alloc] initWithRootViewController:editViewController]; + navController.modalPresentationStyle = UIModalPresentationFormSheet; } - navController.modalPresentationStyle = UIModalPresentationFormSheet; navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; navController.navigationBar.translucent = NO; diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift index 4ee4607083a5..7ab56ddd88bf 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift @@ -1229,6 +1229,7 @@ private extension NotificationDetailsViewController { if FeatureFlag.newCommentEdit.enabled { let editViewController = EditCommentTableViewController() navController = UINavigationController(rootViewController: editViewController) + navController.modalPresentationStyle = .fullScreen } else { let editViewController = EditCommentViewController.newEdit() editViewController?.content = block.text @@ -1243,9 +1244,9 @@ private extension NotificationDetailsViewController { } navController = UINavigationController(rootViewController: editViewController!) + navController.modalPresentationStyle = .formSheet } - navController.modalPresentationStyle = .formSheet navController.modalTransitionStyle = .coverVertical navController.navigationBar.isTranslucent = false