[Notifications Refresh] Resolve an issue where the comment moderation sheet not resizing properly when comment status changes#23272
Conversation
|
| App Name | WordPress Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr23272-304dfc9 | |
| Version | 24.8 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 304dfc9 | |
| App Center Build | WPiOS - One-Offs #10056 |
|
| App Name | Jetpack Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr23272-304dfc9 | |
| Version | 24.8 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 304dfc9 | |
| App Center Build | jetpack-installable-builds #9105 |
| import UIKit | ||
| import SwiftUI | ||
|
|
||
| final class CommentModerationSheetHostingView: UIView { |
There was a problem hiding this comment.
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.viewso 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
hitTestmethod. - 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.
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.
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.
| hostingController.rootView = content | ||
| } else { | ||
| let hostingController = UIHostingController<CommentContentHeaderView>(rootView: content) | ||
| hostingController.view.setContentCompressionResistancePriority(.required, for: .vertical) |
There was a problem hiding this comment.
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.
ℹ️ I'm planning to unit test this method.
| super.viewDidLoad() | ||
| configureView() | ||
| configureReplyView() | ||
| // configureReplyView() |
There was a problem hiding this comment.
Should we delete these?
There was a problem hiding this comment.
I can delete the method call in this PR, but I want to keep the implementation until the "reply" logic is refactored.
| self.hostingController = controller | ||
| } | ||
|
|
||
| override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { |
There was a problem hiding this comment.
Adding a short documentation to this would make sense I think as it isn't very obvious why it is needed.
|
🧪 Tested and it works well! Thanks for the fix @salimbraksa ! |
justtwago
left a comment
There was a problem hiding this comment.
Tested it and it worked as expected 🎸
Thanks for the fix, Salim!
9af6496 to
7832ce2
Compare


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.txtif necessary.Testing checklist: