-
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
[Notifications Refresh] Resolve an issue where the comment moderation sheet not resizing properly when comment status changes #23272
Conversation
📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
|
import UIKit | ||
import SwiftUI | ||
|
||
final class CommentModerationSheetHostingView: UIView { |
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 is the view that fixes this bug.
For context, the bug was occurring because the moderation hosting view was not resizing automatically when its content changed. This is a known issue in UIKit and SwiftUI integration, where the hosting view doesn't resize when the SwiftUI view's size changes.
While it's possible to resize the hosting view by calling hostingView.invalidateIntrinsicContentSize
, the resize will occur without animation which might break the moderation view animation.
There is a workaround to resolve this issue and it works as following:
- Constrain the moderation hosting view to the edges of
viewController.view
so that it matches the size of its parent view. - By default, the Hosting View will prevent touches from passing through. To allow touches outside the moderation view to pass through, we are overriding the hosting view
hitTest
method. - Make the Hosting View transparent.
- Now the Bottom Sheet can resize freely, and the user doesn't see the “Hosting View”.
hitView === hostingView | ||
else { | ||
return super.hitTest(point, with: event) | ||
} |
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.
If the touch happens inside the moderation view (for example, if the user taps the Approve
button or any other button), then everything will proceed as normal.
if let respondingView = subview.hitTest(point, with: event) { | ||
return respondingView | ||
} | ||
} |
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.
If the hosting view is tapped, the touch is forwarded to one of the hosting view's siblings. In the case of the CommentDetailViewController
, the viewController.view
has two subviews: the tableView
and the hostingView
. Therefore, the touch is forward to the tableView
.
@@ -67,6 +67,7 @@ private extension CommentDetailContentTableViewCell { | |||
hostingController.rootView = content | |||
} else { | |||
let hostingController = UIHostingController<CommentContentHeaderView>(rootView: content) | |||
hostingController.view.setContentCompressionResistancePriority(.required, for: .vertical) |
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.
Sometimes the comment cell header is compressed ( height is 0 ) and a constraints ambiguity warning is thrown in the console. Setting the compression resistance fixed this issue.
This change is not part of the fix, but I thought of including in this PR because it's just a 1 line.
self.hostingController = controller | ||
} | ||
|
||
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { |
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 planning to unit test this method.
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.
Resolved in 7832ce2
@@ -187,9 +187,9 @@ class CommentDetailViewController: UIViewController, NoResultsViewHost { | |||
override func viewDidLoad() { | |||
super.viewDidLoad() | |||
configureView() | |||
configureReplyView() | |||
// configureReplyView() |
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.
Should we delete these?
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 can delete the method call in this PR, but I want to keep the implementation until the "reply" logic is refactored.
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.
Resolved in e1e6826
self.hostingController = controller | ||
} | ||
|
||
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { |
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.
Adding a short documentation to this would make sense I think as it isn't very obvious why it is needed.
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.
Resolved in 304dfc9
🧪 Tested and it works well! Thanks for the fix @salimbraksa ! |
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.
Tested it and it worked as expected 🎸
Thanks for the fix, Salim!
9af6496
to
7832ce2
Compare
02d452c
into
feature/notifications_refresh_p2
Fixes #23225 (comment)
Description
This PR resolves an issue where the moderation view doesn't resize properly when the comment status changes.
CleanShot.2024-05-29.at.13.10.58.mp4
Test Instructions
Approved.
Regression Notes
Smoke test the comment moderation screen:
What I did to test those areas of impact (or what existing automated tests I relied on)
Manual testing
What automated tests I added (or what prevented me from doing so)
None.
PR submission checklist:
RELEASE-NOTES.txt
if necessary.Testing checklist: