Skip to content

Add PresentationStyle#1892

Merged
bijington merged 4 commits into
CommunityToolkit:mainfrom
cat0363:Issue-1844
Jun 3, 2024
Merged

Add PresentationStyle#1892
bijington merged 4 commits into
CommunityToolkit:mainfrom
cat0363:Issue-1844

Conversation

@cat0363
Copy link
Copy Markdown
Contributor

@cat0363 cat0363 commented May 17, 2024

This PR resolves the following issue that occurs when displaying Popup on iPhone 11 or lower, iPhone Plus, and iPhone Pro Max.

  1. An issue that caused a crash when displaying a Popup when the device was in landscape orientation.
  2. An issue where rotating the device while viewing a popup would cause a crash.

The exception is occurring at the location below, but it is not caused by the SetShadowView method.

[src\CommunityToolkit.Maui.Core\Views\Popup\MauiPopup.macios.cs]

static void SetShadowView(in UIView target)
{
	if (target.Class.Name is "_UICutoutShadowView")
	{
		target.RemoveFromSuperview();
	}

	if (target.Class.Name is "_UIPopoverDimmingView")
	{
		target.BackgroundColor = UIColor.Black.ColorWithAlpha(0.4f);
	}

	foreach (var view in target.Subviews)
	{
		SetShadowView(view);
	}
}

Description of Change

Below is the solution.

sealed class PopoverDelegate : UIPopoverPresentationControllerDelegate
{
	... omit 

	public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController) =>
		UIModalPresentationStyle.None;

	// ADD-START
	public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController controller, UITraitCollection traitCollection) =>
		UIModalPresentationStyle.None;
	// ADD-END

	... omit                
}

The newly added code is the two lines above.

Resolving the Null reference exception in the SetSahdowView method causes the popup to display in modal form sheet style when the device orientation is landscape. To solve the problem, I focused on its behavior.

When I investigated the behavior for each device, we found that iPhone 11 or lower, iPhone Plue, and iPhone Pro Max exhibit this behavior. On devices other than those listed above, the Popup was displayed as intended, and on the devices listed above, the Popup was not displayed.

I was looking for a case where it is displayed in a modal form sheet format when the device is in landscape orientation.
I found the post below.
https://developer.apple.com/forums/thread/71350
https://stackoverflow.com/questions/30378249/uimodalpresentationpopover-for-iphone-6-plus-in-landscape-doesnt-display-popove

According to the above post, you need to override the method below and explicitly return UIModalPresentationStyle.none as the return value.

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle 
{
	return UIModalPresentationStyle.none
}

The same method as above is shown below.

public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController controller, UITraitCollection traitCollection) =>
	UIModalPresentationStyle.None;

On the device where the problem occurs, you need to override the above method and return UIModalPresentationStyle.None as the return value.

Linked Issues

PR Checklist

Additional information

Below are the verification results.

[iPhone 11]

Case 1 Case 2
iPhone11.iOS.14.5.iOS.14.5.2024-05-17.10-17-50.mp4
iPhone11.iOS.14.5.iOS.14.5.2024-05-17.10-18-07.mp4

[iPhone 15 Plus]

Case 1 Case 2
iPhone.15.Plus.iOS.17.0.2024-05-17.10-07-33.mp4
iPhone.15.Plus.iOS.17.0.2024-05-17.10-07-52.mp4

[iPhone 15 Pro Max]

Case 1 Case 2
iPhone.15.Pro.Max.iOS.17.0.2024-05-17.10-13-42.mp4
iPhone.15.Pro.Max.iOS.17.0.2024-05-17.10-14-01.mp4

[iPhone 15]

Case 1 Case 2
iPhone.15.iOS.17.0.2024-05-17.10-02-45.mp4
iPhone.15.iOS.17.0.2024-05-17.10-03-03.mp4

You can see that the crash does not occur even if you rotate the orientation of the device while viewing the Popup.
You'll notice that if your device is in landscape orientation, it won't crash when you display the popup.

Copy link
Copy Markdown
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

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

Thank you @cat0363

@bijington bijington enabled auto-merge (squash) May 27, 2024 08:31
@acaliaro
Copy link
Copy Markdown

acaliaro commented Jun 3, 2024

Thank you @cat0363

@bijington when this will be released? thanks

Copy link
Copy Markdown
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

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

Thanks @cat0363 for this. Sorry I must have missed this PR somehow

@bijington
Copy link
Copy Markdown
Contributor

Oh no I didn't, I remember now... the pipeline was broken. We can merge now 🎉

@acaliaro It's likely there will be a release around the end of the week given CameraView is pretty much there too

@bijington bijington merged commit 2622d0a into CommunityToolkit:main Jun 3, 2024
@acaliaro acaliaro mentioned this pull request Jun 11, 2024
2 tasks
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 20, 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] Error using popup on iOS

3 participants