Skip to content
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

Add popup size update on iOS #1653

Merged
merged 7 commits into from Mar 25, 2024
Merged

Conversation

cat0363
Copy link
Contributor

@cat0363 cat0363 commented Jan 19, 2024

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

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • 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.

iPhone.15.iOS.17.0.2024-01-19.15-35-07.mp4

You can see that the Gesture is still working after updating the Popup's size.

@cat0363
Copy link
Contributor Author

cat0363 commented Jan 19, 2024

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.

@bijington
Copy link
Contributor

@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?

@cat0363
Copy link
Contributor Author

cat0363 commented Feb 27, 2024

@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.

@primozcerar
Copy link

Can we get this merged please? It's been 2 months.

Copy link
Collaborator

@brminnick brminnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Kenji!!

@brminnick brminnick enabled auto-merge (squash) March 25, 2024 22:53
@brminnick brminnick merged commit 7a144db into CommunityToolkit:main Mar 25, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] After increasing Popup height any elements outside of original bounds do not receive touches on iOS
4 participants