-
Notifications
You must be signed in to change notification settings - Fork 113
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
Custom Fields: Refactor AztecEditorView to be reusable #13925
Custom Fields: Refactor AztecEditorView to be reusable #13925
Conversation
…he regular text editor.
…nge to the regular text editor." This reverts commit 53494ce.
…avigation bar appears. Also add optional Cancel button.
@hafizrahman Is this PR ready for another review yet? |
@itsmeichigo thanks for the ping! I left this PR this week for HACK week, but I'll get back to you on this on Monday. At the very least I still need to update this with the latest |
📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.
|
Also fixes "Modifying state during view update" in AztecEditorView
HTML should not be stripped now since they need stay there for editing purposes.
@itsmeichigo We had a last minute design change yesterday so I had to rework everything. This should be good to review again. I have updated the original post with the latest instruction and screenshots/video, so perhaps it's easiest to treat this as a new review. In terms of reviewing by commits, I had a few revert commits to undo the previous work, and the latest ones to review are the commits starting from 31cf7e3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @hafizrahman. Since you updated some code in EditorFactory
affecting Product description and short description, it's worth it to do smoke test on the features to ensure they still work as expected.
I left some other comments for improvements below.
WooCommerce/Classes/ViewRelated/Custom Fields/CustomFieldEditorView.swift
Outdated
Show resolved
Hide resolved
WooCommerce/Classes/ViewRelated/Custom Fields/CustomFieldEditorView.swift
Outdated
Show resolved
Hide resolved
DispatchQueue.main.async { | ||
value = content | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Could you explain the need for using DispatchQueue.main.async
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I added this in the commit message but it wasn't obvious:
Also fixes "Modifying state during view update" in AztecEditorView
This fixes the same issue as in the 314a522 commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That error hints an incorrect use of SwiftUI. Using DispatchQueue.main.async
is just a workaround, and I'm unsure it actually fixes the problem.
Instead, try using @Binding
only:
struct AztecEditorView: UIViewControllerRepresentable {
@Binding var content: String
func makeUIViewController(context: Context) -> AztecEditorViewController {
let controller = EditorFactory().customFieldRichTextEditor(initialValue: content)
guard let aztecController = controller as? AztecEditorViewController else {
fatalError("EditorFactory must return an AztecEditorViewController, but returned \(type(of: controller))")
}
aztecController.onContentChanged = { content in
self.content = content
}
return aztecController
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 60d5f4b
WooCommerce/Classes/ViewRelated/Custom Fields/CustomFieldEditorView.swift
Show resolved
Hide resolved
WooCommerce/Classes/ViewRelated/Custom Fields/CustomFieldEditorView.swift
Show resolved
Hide resolved
Also, I tried this sample HTML code in the HTML mode but the body content does not show up. Is that an issue with Aztec, should we raise an issue for the library? Simulator.Screen.Recording.-.iPad.10th.generation.-.2024-09-24.at.17.00.37.mp4 |
Co-authored-by: Huong Do <[email protected]>
That is indeed Aztec's default behavior, it:
Here's the same behavior from Short Descriptions in Products. I'm using the Code icon toggle in the toolbar to switch from code to rich text mode, and the autoformatting happened there too: Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-09-24.at.18.39.07.mp4This seems to stem from the fact that Aztec is meant for writing blog posts, thus tags like We discussed this in Slack p1725529996823859/1724862433.885169-slack-C03L1NF1EA3 . Initially we wanted to use Aztec immediately if HTML content is detected, but the issue you saw made us change it so that merchants have to intentionally choose HTML editor for this to happen. Our hypothesis also is that HTML editing is going to be a small subset of the usage, and it's more like a nice-to-have feature. This is just the i1 decision though, and we should listen to users for future iterations. |
Thanks for your reviews @itsmeichigo , this is good for another round. Update: I also updated the original post with my smoke testing Aztec on Product. Thank you for the suggestion! |
I left some responses in the discussions above, could you take a look? They were not set as a new round of review. |
…achieve the same effect.
…he view controller. This helps avoid the "Modifying state during view update, this will cause undefined behavior" issue.
@itsmeichigo This is good for another review, thanks. Do let me know if I miss something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
This PR continues the feedback in #13863 to make
AztecEditorView
reusable.Description
With the Custom Fields Editing project, we want to be able to use the Aztec Editor within SwiftUI, as the custom fields editing area are built with it. This is done by creating
AztecEditorView
asUIViewControllerRepresentable
.What this PR adds:
AztecEditorView
moved to its own file for reusability.EditorFactory
updated withcustomFieldRichTextEditor()
function and made more generic for non-product contexts.onContentChanged
to retrieve the latest content in Aztec.AztecEditorView
inCustomFieldEditorView
.In hindsight, the implementation could probably be better in a separate PR, but I hope this is small enough to check both.
Steps to reproduce
** Known behavior / possible issue **
<p>
tag is automatically stripped. This is still being discussed and if any change is needed, it will be handled in a separate PR. Feel free to ignore for now.Testing information
I tested this in Simulator for iPhone with iOS 17.5. Check video below for more details.
As suggested downthread, I also smoke-tested Aztec editor in Product Description and Short Description and they worked fine in my test. Check video below also.
Video
Aztec Editor:
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-09-24.at.14.48.10.mp4
Smoke tests in Products:
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-09-24.at.19.54.39.mp4
Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: