Skip to content

Add popup size update on iOS#1653

Merged
TheCodeTraveler merged 7 commits intoCommunityToolkit:mainfrom
cat0363:Issue-1522
Mar 25, 2024
Merged

Add popup size update on iOS#1653
TheCodeTraveler merged 7 commits intoCommunityToolkit:mainfrom
cat0363:Issue-1522

Conversation

@cat0363
Copy link
Copy Markdown
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

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

Copy link
Copy Markdown
Collaborator

@TheCodeTraveler TheCodeTraveler 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!!

@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) March 25, 2024 22:53
@TheCodeTraveler TheCodeTraveler merged commit 7a144db into CommunityToolkit:main Mar 25, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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