Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Force iOS 13 to use Full Screen for Modal #7172

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Xamarin.Forms.Platform.iOS/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using UIKit;
using Xamarin.Forms.Internals;

Expand Down Expand Up @@ -74,6 +75,19 @@ public static void ApplyKeyboard(this IUITextInputTraits textInput, Keyboard key
}
}

internal static UIModalPresentationStyle ToNativeModalPresentationStyle(this PlatformConfiguration.iOSSpecific.UIModalPresentationStyle style)
{
switch (style)
{
case PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.FormSheet:
return UIModalPresentationStyle.FormSheet;
case PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.FullScreen:
return UIModalPresentationStyle.FullScreen;
default:
throw new ArgumentOutOfRangeException(nameof(style));
}
}

internal static UIReturnKeyType ToUIReturnKeyType(this ReturnType returnType)
{
switch (returnType)
Expand Down
4 changes: 2 additions & 2 deletions Xamarin.Forms.Platform.iOS/ModalWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ internal ModalWrapper(IVisualElementRenderer modal)
_modal = modal;

var elementConfiguration = modal.Element as IElementConfiguration<Page>;
if (elementConfiguration?.On<PlatformConfiguration.iOS>().ModalPresentationStyle() == PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.FormSheet)
ModalPresentationStyle = UIKit.UIModalPresentationStyle.FormSheet;
var modalPresentationStyle = elementConfiguration?.On<PlatformConfiguration.iOS>()?.ModalPresentationStyle() ?? PlatformConfiguration.iOSSpecific.UIModalPresentationStyle.FullScreen;
ModalPresentationStyle = modalPresentationStyle.ToNativeModalPresentationStyle();
Copy link
Contributor Author

@PureWeen PureWeen Aug 16, 2019

Choose a reason for hiding this comment

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

@samhouts the change here forces ModalPresentationStyle to explicitly be set to FullScreen by default where as before ModalPresentationStyle would only get set if you set it to FormSheet

on iOS12 ModalPresentationStyle is set to FullScreen by default but on iOS13 it's set to Automatic (Which is a new property on iOS13)

Automatic causes the ModalPresentationStyle to be FullScreen on ios12 but PageSheet on iOS13

By just setting the ModalPresentationStyle ourselves explicitly it will be FullScreen by default on iOS13 as well which makes it so users can't dismiss the Modal and break everything

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect! That's the blurb I was hoping for. Thanks!


View.BackgroundColor = UIColor.White;
View.AddSubview(modal.ViewController.View);
Expand Down