Maui
Maui copied to clipboard
Add popup size update on iOS
This PR resolves the issue where Gestures do not work on Popups when changing the Popup's Size property.
Description of Change
Bounds of a UIView placed in a Popup will not be updated after calling the SetView method.
[src\CommunityToolkit.Maui.Core\Views\Popup\MauiPopup.macios.cs]
void SetView(UIView view, PageHandler control)
{
view.AddSubview(control.ViewController?.View ?? throw new InvalidOperationException($"{nameof(control.ViewController.View)} cannot be null."));
view.Bounds = new(0, 0, PreferredContentSize.Width, PreferredContentSize.Height); // <= Here
AddChildViewController(control.ViewController);
if (VirtualView is not null)
{
this.SetBackgroundColor(VirtualView);
}
}
Therefore, update the View's Bounds in the method below that is called when the View's size is updated.
[src\CommunityToolkit.Maui.Core\Views\Popup\MauiPopup.macios.cs]
public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
{
coordinator.AnimateAlongsideTransition(_ =>
{
// Before screen rotate
if (ViewController?.View is UIView view)
{
var overlayView = GetOverlayView(view);
overlayView.Frame = new CGRect(0, 0, view.Frame.Width, view.Frame.Height);
}
}, _ =>
{
// After screen rotate
if (VirtualView is not null)
{
PopupExtensions.SetSize(this, VirtualView);
PopupExtensions.SetLayout(this, VirtualView);
}
});
if (View is not null)
{
View.Bounds = new CGRect(0, 0, PreferredContentSize.Width, PreferredContentSize.Height);
}
base.ViewWillTransitionToSize(toSize, coordinator);
}
This will update the View's Bounds and allow the Gesture to work even after the size update.
Linked Issues
- Fixes #1522
PR Checklist
- [x] Has a linked Issue, and the Issue has been
approved
(bug) orChampioned
(feature/proposal) - [x] Has tests (if omitted, state reason in description)
- [ ] Has samples (if omitted, state reason in description)
- [x] Rebased on top of
main
at time of PR - [x] Changes adhere to coding standard
- [ ] Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls
Additional information
Below is the verification video. I used the issue reproduction code for verification.
https://github.com/CommunityToolkit/Maui/assets/125236133/f41fffb1-46a0-4127-9696-f8471653e8e2
You can see that the Gesture is still working after updating the Popup's size.
As an aside, I tried updating the View's Bounds within the method below, but it didn't work as intended.
[src\CommunityToolkit.Maui.Core\Handlers\Popup\PopupHandler.macios.cs]
public static void MapSize(PopupHandler handler, IPopup view)
[src\CommunityToolkit.Maui.Core\Views\Popup\PopupExtensions.macios.cs]
public static void SetSize(this MauiPopup mauiPopup, in IPopup popup)
The update within the ViewWillTransitionToSize method worked as intended.
@cat0363 sorry someone is just getting around to looking at this now. By your last comment does that mean this PR does not solve the issue entirely?
@bijington , I left a comment that updating the View's Bounds works as intended with the ViewWillTransitionToSize method, not the MapSize, SetSize methods. In this PR, the View's Bounds are updated within the ViewWillTransitionToSize method, so there is no problem. Therefore, the comment does not indicate that there is any other problem. Sorry for the confusing comment.
Can we get this merged please? It's been 2 months.