-
Notifications
You must be signed in to change notification settings - Fork 1.9k
ModalInPresentation flag in iOS not working #12301
Comments
@btschumy Hi Bill, I have been having the same problem as you. Here's my work-around. I created an extension that walks up the UIViewController hierarchy and sets the ModalInPresentation property for every UIViewController. I call this extension from the ViewDidAppear method of a custom NavigationRenderer. NOTE: It's possible that you can call this from other places in the ViewController lifecycle, but I have not tested that and I found that the ViewController didn't get wrapped in a ModalWrapper until pretty late in the lifecycle.
I was able to find a work-around because of your observation that the ModalInPresentation property worked on Xamarin.iOS but not on Xamarin.Forms. It seems like the issue is that modal ViewControllers are wrapped in a class called ModalWrapper and it's possible that ModalInPresentation is not being bubbled up through the ViewControllers. I read that you can set ModalInPresentation on any modal page in a navigation stack for the modal behavior to be updated, and it's possible that there is a disconnect where the navigation stack is not structured how the iOS system is expecting. Thanks for sharing your observations and I hope this helps! |
Hello from 2023! I came across this problem in .NET MAUI. I've created a Frakenstien's monster of a fix using a suggestion here: dotnet/maui#7174 In the iOS folder, I created the following class:
Also in the iOS folder, added the following class (thanks to @jeffington above for the extension method):
And in my MauiProgram.cs:
I feel quite dirty. I'm not sure if there's a better way, but it does work. |
Description
Setting the ModalInPresentation flag for a UIViewController should, according to Apple:
The default value of this property is NO. When you set it to YES, UIKit ignores events outside the view controller's bounds and prevents the interactive dismissal of the view controller while it is onscreen.
However, this flag does not seem to work in Xamarin Forms (all versions I've tried). If you set it YES, you can still dismiss the modal page by dragging it to the bottom of the screen. If the flag is set NO, you should be able to dismiss the page by tapping outside the pages boundary but this seems to fail as well.
I've created an example app at www.otherwise.com/ModalPresentation.zip that illustrates the problems. The example app uses a custom PageRenderer to set the ModalInPresentation flag in multiple places (since it wasn't really clear where it needs to be set).
Note, I've been told that this flag is working correctly in a native Xamarin iOS app. It seems to only fail in Xamarin Forms.
Note that this bug may be related to another problem I've reported in issue #12300. This refers to a crash when tapping outside the modal page and then dismissing the page.
Steps to Reproduce
Expected Behavior
The panel should not be able to be dismissed by dragging down with this flag set to true.
Actual Behavior
It can be dismissed by dragging.
Basic Information
All versions of the Xamarin Forms package that I've tried (3.6.709228 to 4.8.0.1364)
None
Jetbrains Rider
Observed on iPads running iOS 13 and 14
Screenshots
Reproduction Link
www.otherwise.com/ModalPresentation.zip
Workaround
None that I've found
The text was updated successfully, but these errors were encountered: