-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
WebKit Reader Comments (Groundwork) #24022
base: trunk
Are you sure you want to change the base?
Conversation
Generated by 🚫 Danger |
📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
|
292a91d
to
108380e
Compare
} | ||
|
||
public func render(comment: String) -> UIView { | ||
guard self.comment != comment else { |
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.
It was part of the existing CommentContentRenderer
protocol, and I don't want to change it too much just yet.
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | ||
// Wait until the HTML document finished loading. | ||
// This also waits for all of resources within the HTML (images, video thumbnail images) to be fully loaded. | ||
webView.evaluateJavaScript("document.readyState") { complete, _ in |
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.
This was the existing code. I just moved it. Not sure if it works the way it says it does.
// remove empty HTML elements from the `content`, as the content often contains empty paragraph elements which adds unnecessary padding/margin. | ||
// `rawContent` does not have this problem, but it's not used because `rawContent` gets rid of links (<a> tags) for mentions. | ||
let comment = comment | ||
.replacingOccurrences(of: Self.emptyElementRegexPattern, with: "", options: [.regularExpression]) |
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.
Ideally, I want to preprocess this in the background and store in Core Data in this way.
|
||
// MARK: - ReaderDisplaySetting (CSS) | ||
|
||
extension ReaderDisplaySettings { |
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 is an opportunity to reuse this with ReaderWebView
. I'm going to look into it.
import WordPressShared | ||
|
||
struct ReaderDisplaySetting: Codable, Equatable { | ||
public struct ReaderDisplaySettings: Codable, Equatable, Hashable, Sendable { |
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.
I renamed it because I kept typing ReaderDisplaySettings
.
return renderer | ||
} | ||
|
||
func getCachedContentHeight(for commentID: TaggedManagedObjectID<Comment>) -> CGFloat? { |
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.
I'll probably change the keys to use comment's content (String
). I'm not sure yet because comparing long strings isn't ideal.
} | ||
|
||
func getRenderer(for comment: Comment) -> WebCommentContentRenderer { | ||
if let renderer = renderers.object(forKey: comment) { |
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.
I'm not sure it's a good idea to reuse web view across different cells this way, but it helps with cell reload. UITableView
does little to nothing to ensure the same cells are used for the same comments on reload.
6c43b39
to
075261c
Compare
This is the initial PR that enabled WebKit-based rendering for comments in the "Comments" screen.
The app already had
WebCommentContentRenderer
. It was used only in a subset of screens, for example, for a single comment displayed right under the article. This PR introduces a few performance and other improvements that made it possible to use in the lists.This PR also introduces a new
WordPressReader
module. I movedWebCommentContentRenderer
andReaderDisplaySettings
to this new module and added Xcode previews to make it easy to iterate on it.The feature is not complete, so it's currently hidden behind a feature flag, so it should be safe to merge now and continue iterating in
trunk
. I'm planning more performance optimizations, better styles for some Gutenberg blocks, and better handling for URLs.Future Plans
The main issues is that rendering in
WKWebView
is inherently asynchronous and depending on how fast you scroll and how slow your device is, you might end up seeing empty cells until the comment loads. I'm planning to work this around by adding prefetching to this screen. It will ensure that in the vast majority of cases, you are never going to see the empty cells. I will also add loading state (skeletons?) for empty cells.I also haven't measured the impact on the battery life yet. It might be worth adding a simple
UITextView
-based implementation for plain text cells. It will also free the resources for otherWKWebView
instances that do needWebKit
to render the content.Testing
Future
Regression Notes
Potential unintended areas of impact
What I did to test those areas of impact (or what existing automated tests I relied on)
What automated tests I added (or what prevented me from doing so)
PR submission checklist:
RELEASE-NOTES.txt
if necessary.Testing checklist: