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 PresentationStyle #1892

Merged
merged 4 commits into from
Jun 3, 2024
Merged

Add PresentationStyle #1892

merged 4 commits into from
Jun 3, 2024

Conversation

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

  • 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 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
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

acaliaro commented Jun 3, 2024

Thank you @cat0363

@bijington when this will be released? thanks

Copy link
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
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
7 checks passed
@acaliaro acaliaro mentioned this pull request Jun 11, 2024
2 tasks
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] Error using popup on iOS
3 participants