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

Editor - Move Undo/Redo to the header #20930

Merged
merged 21 commits into from
Jul 11, 2023
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 Gutenberg/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# LOCAL_GUTENBERG=../my-gutenberg-fork bundle exec pod install
GUTENBERG_CONFIG = {
# commit: ''
tag: 'v1.99.0'
tag: 'v1.100.0-alpha1'
}

GITHUB_ORG = 'wordpress-mobile'
Expand Down
196 changes: 98 additions & 98 deletions Podfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
22.9
-----

* [**] Block editor: Move undo/redo buttons to the navigation bar [#20930]

22.8
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ extension UIColor {
static var prologueBackground: UIColor {
return UIColor(light: muriel(color: MurielColor(name: .blue, shade: .shade0)), dark: .systemBackground)
}

// MARK: - Editor

static var editorActionText: UIColor {
return UIColor(light: .black, dark: .white)
}
}

@objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ class AztecPostViewController: UIViewController, PostEditor {
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.accessibilityIdentifier = "Azctec Editor Navigation Bar"
navigationItem.leftBarButtonItems = navigationBarManager.leftBarButtonItems
navigationItem.rightBarButtonItems = navigationBarManager.rightBarButtonItems
navigationItem.rightBarButtonItems = navigationBarManager.rightBarButtonItemsAztec
navigationItem.titleView = navigationBarManager.blogTitleViewLabel
}

Expand Down Expand Up @@ -862,7 +862,6 @@ class AztecPostViewController: UIViewController, PostEditor {
}

func refreshInterface() {
reloadBlogTitleView()
reloadEditorContents()
reloadPublishButton()
refreshTitleViewForMediaUploadIfNeeded()
Expand Down Expand Up @@ -916,15 +915,6 @@ class AztecPostViewController: UIViewController, PostEditor {
setHTML(content)
}

func reloadBlogTitleView() {
var blogTitle = post.blog.url ?? String()
if let blogName = post.blog.settings?.name, blogName.isEmpty == false {
blogTitle = blogName
}

navigationBarManager.reloadBlogTitleView(text: blogTitle)
}

func reloadPublishButton() {
navigationBarManager.reloadPublishButton()
}
Expand Down Expand Up @@ -3549,6 +3539,12 @@ extension AztecPostViewController: PostEditorNavigationBarManagerDelegate {
closeWasPressed()
}

func navigationBarManager(_ manager: PostEditorNavigationBarManager, undoWasPressed sender: UIButton) {
}

func navigationBarManager(_ manager: PostEditorNavigationBarManager, redoWasPressed sender: UIButton) {
}

func navigationBarManager(_ manager: PostEditorNavigationBarManager, moreWasPressed sender: UIButton) {
moreWasPressed()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class SiteIconView: UIView {
@objc func touchedButton() {
tapped?()
}

func removeButtonBorder() {
button.layer.borderWidth = 0
}
}

extension SiteIconView: UIDropInteractionDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,31 @@ class GutenbergViewController: UIViewController, PostEditor, FeaturedImageDelega
navigationController?.navigationBar.accessibilityIdentifier = "Gutenberg Editor Navigation Bar"
navigationItem.leftBarButtonItems = navigationBarManager.leftBarButtonItems
navigationItem.rightBarButtonItems = navigationBarManager.rightBarButtonItems
navigationItem.titleView = navigationBarManager.blogTitleViewLabel

// Add bottom border line
let screenScale = UIScreen.main.scale
let borderWidth: CGFloat = 1.0 / screenScale
let borderColor = UIColor(red: 60/255, green: 60/255, blue: 67/255, alpha: 0.36).cgColor

let borderBottom = UIView()
borderBottom.backgroundColor = UIColor(cgColor: borderColor)
borderBottom.frame = CGRect(x: 0, y: navigationController?.navigationBar.frame.size.height ?? 0 - borderWidth, width: navigationController?.navigationBar.frame.size.width ?? 0, height: borderWidth)
borderBottom.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
navigationController?.navigationBar.addSubview(borderBottom)
}

private func reloadBlogTitleView() {
var blogTitle = post.blog.url ?? String()
if let blogName = post.blog.settings?.name, blogName.isEmpty == false {
blogTitle = blogName
}
private func reloadBlogIconView() {
let blog = post.blog

navigationBarManager.reloadBlogTitleView(text: blogTitle)
if blog.hasIcon == true {
let size = CGSize(width: 24, height: 24)
navigationBarManager.siteIconView.imageView.downloadSiteIcon(for: blog, imageSize: size)
} else if blog.isWPForTeams() {
navigationBarManager.siteIconView.imageView.tintColor = UIColor.listIcon
navigationBarManager.siteIconView.imageView.image = UIImage.gridicon(.p2)
} else {
navigationBarManager.siteIconView.imageView.image = UIImage.siteIconPlaceholder
}
}

private func reloadEditorContents() {
Expand All @@ -479,7 +494,7 @@ class GutenbergViewController: UIViewController, PostEditor, FeaturedImageDelega
}

private func refreshInterface() {
reloadBlogTitleView()
reloadBlogIconView()
reloadEditorContents()
reloadPublishButton()
}
Expand Down Expand Up @@ -584,7 +599,6 @@ extension GutenbergViewController {
// MARK: - GutenbergBridgeDelegate

extension GutenbergViewController: GutenbergBridgeDelegate {

func gutenbergDidGetRequestFetch(path: String, completion: @escaping (Result<Any, NSError>) -> Void) {
post.managedObjectContext!.perform {
GutenbergNetworkRequest(path: path, blog: self.post.blog, method: .get).request(completion: completion)
Expand Down Expand Up @@ -1333,10 +1347,36 @@ extension GutenbergViewController: PostEditorNavigationBarManagerDelegate {
return AztecPostViewController.Constants.savingDraftButtonSize
}

func gutenbergDidRequestToggleUndoButton(_ isDisabled: Bool) {
DispatchQueue.main.async {
UIView.animate(withDuration: 0.2) {
self.navigationBarManager.undoButton.isUserInteractionEnabled = isDisabled ? false : true
self.navigationBarManager.undoButton.alpha = isDisabled ? 0.3 : 1.0
}
}
}

func gutenbergDidRequestToggleRedoButton(_ isDisabled: Bool) {
DispatchQueue.main.async {
UIView.animate(withDuration: 0.2) {
self.navigationBarManager.redoButton.isUserInteractionEnabled = isDisabled ? false : true
self.navigationBarManager.redoButton.alpha = isDisabled ? 0.3 : 1.0
}
}
}

func navigationBarManager(_ manager: PostEditorNavigationBarManager, closeWasPressed sender: UIButton) {
requestHTML(for: .close)
}

func navigationBarManager(_ manager: PostEditorNavigationBarManager, undoWasPressed sender: UIButton) {
self.gutenberg.onUndoPressed()
}

func navigationBarManager(_ manager: PostEditorNavigationBarManager, redoWasPressed sender: UIButton) {
self.gutenberg.onRedoPressed()
}

func navigationBarManager(_ manager: PostEditorNavigationBarManager, moreWasPressed sender: UIButton) {
requestHTML(for: .more)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ extension PostEditor {
return
}

navigationBarManager.reloadTitleView(navigationBarManager.generatingPreviewTitleView)
SVProgressHUD.setDefaultMaskType(.clear)
SVProgressHUD.show(withStatus: NSLocalizedString("Generating Preview", comment: "Message to indicate progress of generating preview"))

postService.autoSave(post, success: { [weak self] savedPost, previewURL in

Expand Down Expand Up @@ -83,8 +84,7 @@ extension PostEditor {
return
}

let navigationBarManager = self.navigationBarManager
navigationBarManager.reloadTitleView(navigationBarManager.blogTitleViewLabel)
SVProgressHUD.dismiss()

if error != nil {
let title = NSLocalizedString("Preview Unavailable", comment: "Title on display preview error" )
Expand Down
Loading