Skip to content

Commit

Permalink
Remove WPRichText usage from ReaderComments (#24076)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Feb 14, 2025
1 parent 4c03aa8 commit d5b641e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 259 deletions.
4 changes: 0 additions & 4 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ enum FeatureFlag: Int, CaseIterable {
case newGutenbergThemeStyles
case newGutenbergPlugins
case selfHostedSiteUserManagement
case readerCommentsWebKit
case readerGutenbergCommentComposer
case pluginManagementOverhaul

Expand Down Expand Up @@ -52,8 +51,6 @@ enum FeatureFlag: Int, CaseIterable {
return false
case .selfHostedSiteUserManagement:
return false
case .readerCommentsWebKit:
return BuildConfiguration.current != .appStore
case .readerGutenbergCommentComposer:
return false
case .pluginManagementOverhaul:
Expand Down Expand Up @@ -93,7 +90,6 @@ extension FeatureFlag {
case .newGutenbergThemeStyles: "Experimental Block Editor Styles"
case .newGutenbergPlugins: "Experimental Block Editor Plugins"
case .selfHostedSiteUserManagement: "Self-hosted Site User Management"
case .readerCommentsWebKit: "Render Comments using WebKit"
case .pluginManagementOverhaul: "Plugin Management Overhaul"
case .readerGutenbergCommentComposer: "Gutenberg Comment Composer"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ class CommentContentTableViewCell: UITableViewCell, NibReusable {
case info
}

enum RenderMethod: Equatable {
/// Uses WebKit to render the comment body.
case web

/// Uses WPRichContent to render the comment body.
case richContent(NSAttributedString)
}

// MARK: - Public Properties

/// A closure that's called when the accessory button is tapped.
Expand All @@ -31,8 +23,6 @@ class CommentContentTableViewCell: UITableViewCell, NibReusable {

@objc var contentLinkTapAction: ((URL) -> Void)? = nil

@objc weak var richContentDelegate: WPRichContentViewDelegate? = nil

/// Encapsulate the accessory button image assignment through an enum, to apply a standardized image configuration.
/// See `accessoryIconConfiguration` in `WPStyleGuide+CommentDetail`.
var accessoryButtonType: AccessoryButtonType = .share {
Expand Down Expand Up @@ -107,7 +97,6 @@ class CommentContentTableViewCell: UITableViewCell, NibReusable {

private var comment: Comment?
private var renderer: CommentContentRenderer?
private var renderMethod: RenderMethod?
private var helper: ReaderCommentsHelper?
private var viewModel: CommentCellViewModel?
private var cancellables: [AnyCancellable] = []
Expand Down Expand Up @@ -165,11 +154,9 @@ class CommentContentTableViewCell: UITableViewCell, NibReusable {
///
/// - Parameters:
/// - comment: The `Comment` object to display.
/// - renderMethod: Specifies how to display the comment body. See `RenderMethod`.
/// - onContentLoaded: Callback to be called once the content has been loaded. Provides the new content height as parameter.
func configure(
viewModel: CommentCellViewModel,
renderMethod: RenderMethod = .web,
helper: ReaderCommentsHelper,
onContentLoaded: ((CGFloat) -> Void)?
) {
Expand All @@ -188,7 +175,7 @@ class CommentContentTableViewCell: UITableViewCell, NibReusable {
}.store(in: &cancellables)

viewModel.$content.sink { [weak self] in
self?.configureContent($0 ?? "", renderMethod: renderMethod, helper: helper)
self?.configureContent($0 ?? "", helper: helper)
}.store(in: &cancellables)

// Configure feature availability.
Expand All @@ -215,17 +202,6 @@ class CommentContentTableViewCell: UITableViewCell, NibReusable {
isAccessoryButtonEnabled = false
}

@objc func ensureRichContentTextViewLayout() {
switch renderMethod {
case .richContent:
if let richContentTextView = contentContainerView.subviews.first as? WPRichContentView {
richContentTextView.updateLayoutForAttachments()
}
default:
return
}
}

private func configure(with state: CommentCellViewModel.State) {
nameLabel.text = state.title
dateLabel.text = state.dateCreated?.toMediumString()
Expand All @@ -241,18 +217,14 @@ class CommentContentTableViewCell: UITableViewCell, NibReusable {

extension CommentContentTableViewCell: CommentContentRendererDelegate {
func renderer(_ renderer: CommentContentRenderer, asyncRenderCompletedWithHeight height: CGFloat, comment: String) {
if renderMethod == .web {
if let constraint = contentContainerHeightConstraint {
if height != constraint.constant {
constraint.constant = height
helper?.setCachedContentHeight(height, for: comment)
onContentLoaded?(height) // We had the right size from the get-go
}
} else {
wpAssertionFailure("constraint missing")
if let constraint = contentContainerHeightConstraint {
if height != constraint.constant {
constraint.constant = height
helper?.setCachedContentHeight(height, for: comment)
onContentLoaded?(height) // We had the right size from the get-go
}
} else {
onContentLoaded?(height)
wpAssertionFailure("constraint missing")
}
}

Expand Down Expand Up @@ -433,44 +405,20 @@ private extension CommentContentTableViewCell {

// MARK: Content Rendering

func configureContent(_ content: String, renderMethod: RenderMethod, helper: ReaderCommentsHelper) {
if self.renderMethod != renderMethod {
self.renderer = nil
}
self.renderMethod = renderMethod

func configureContent(_ content: String, helper: ReaderCommentsHelper) {
let renderer = self.renderer ?? {
let renderer = makeRenderer()
let renderer = helper.makeWebRenderer()
renderer.delegate = self
self.renderer = renderer
return renderer
}()

func makeRenderer() -> CommentContentRenderer {
switch renderMethod {
case .web:
let renderer = helper.makeWebRenderer()
renderer.delegate = self
return renderer
case .richContent(let attributedText):
let renderer = RichCommentContentRenderer()
renderer.richContentDelegate = self.richContentDelegate
renderer.attributedText = attributedText
renderer.comment = viewModel?.comment
renderer.delegate = self
return renderer
}
}

if renderMethod == .web {
// reset height constraint to handle cases where the new content requires the webview to shrink.
contentContainerHeightConstraint?.isActive = true
// - warning: It's important to set height to the minimum supported
// value because `WKWebView` can only increase the content height and
// never decreases it when the content changes.
contentContainerHeightConstraint?.constant = helper.getCachedContentHeight(for: content) ?? 20
} else {
contentContainerHeightConstraint?.isActive = false
}
// reset height constraint to handle cases where the new content requires the webview to shrink.
contentContainerHeightConstraint?.isActive = true
// - warning: It's important to set height to the minimum supported
// value because `WKWebView` can only increase the content height and
// never decreases it when the content changes.
contentContainerHeightConstraint?.constant = helper.getCachedContentHeight(for: content) ?? 20

let contentView = renderer.view
if contentContainerView.subviews.first != contentView {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ final class ReaderCommentsTableViewController: UIViewController, UITableViewData
tableView.cellLayoutMarginsFollowReadableWidth = true
tableView.preservesSuperviewLayoutMargins = true

if Feature.enabled(.readerCommentsWebKit) {
// We use this to mask the initial WebKit warmup that takes a bit of time
// the first time you initialize a web view. It renders asynchronously, and
// we don't want to show cells with empty messages.
tableView.alpha = 0.0
}
// We use this to mask the initial WebKit warmup that takes a bit of time
// the first time you initialize a web view. It renders asynchronously, and
// we don't want to show cells with empty messages.
tableView.alpha = 0.0

let nib = UINib(nibName: CommentContentTableViewCell.classNameWithoutNamespaces(), bundle: nil)
tableView.register(nib, forCellReuseIdentifier: commentCellReuseID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ typedef NS_ENUM(NSUInteger, ReaderCommentsSource) {
// Comment moderation support.
@property (nonatomic, assign, readwrite) BOOL commentModified;
- (void)refreshAfterCommentModeration;
- (NSAttributedString *)cacheContentForComment:(Comment *)comment;
- (void)trackReplyTo:(BOOL)replyTarget;
- (void)configureCell:(CommentContentTableViewCell *)cell viewModel:(CommentCellViewModel *)viewModel indexPath:(NSIndexPath *)indexPath;
- (UIView *)cachedHeaderView;
Expand Down
Loading

0 comments on commit d5b641e

Please sign in to comment.