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

[iOS] Fix crash/closing wrong modal with FormSheet and tap outside #14527

Merged
merged 3 commits into from
Sep 2, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
using NavigationPage = Xamarin.Forms.NavigationPage;
using Page = Xamarin.Forms.Page;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 12300, "Crash when dismissing modally presented page on iOS", PlatformAffected.iOS)]
public class Issue12300 : TestContentPage
{
protected override void Init()
{
var button = new Button()
{
Text = "Show Modal Page",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand,
};

button.Clicked += (s, a) =>
{
Navigation.PushModalAsync(new OTNavigationPage(new ModalPage()));
};

Content = new StackLayout()
{
Children =
{
button
}
};
}

public class OTNavigationPage : NavigationPage
{
public OTNavigationPage(Page page) : base(page)
{
On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.PageSheet);
}
}

public class ModalPage : ContentPage
{
public ModalPage()
{
var button = new Button()
{
Text = "Hide Modal Page",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand,
};

button.Clicked += (s, a) =>
{
Navigation.PopModalAsync();
};

Content = new StackLayout()
{
Children =
{
button
}
};
}

private void ButtonClicked(object sender, EventArgs e)
{
Navigation.PopModalAsync();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue13616.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13670.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13684.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12300.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12150.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
11 changes: 0 additions & 11 deletions Xamarin.Forms.Platform.iOS/ModalWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ public async void DidDismiss(UIPresentationController presentationController)

public override void DismissViewController(bool animated, Action completionHandler)
{
if (PresentedViewController == null)
{
// After dismissing a UIDocumentMenuViewController, (for instance, if a WebView with an Upload button
// is asking the user for a source (camera roll, etc.)), the view controller accidentally calls dismiss
// again on itself before presenting the UIImagePickerController; this leaves the UIImagePickerController
// without an anchor to the view hierarchy and it doesn't show up. This appears to be an iOS bug.

// We can work around it by ignoring the dismiss call when PresentedViewController is null.
return;
}

base.DismissViewController(animated, completionHandler);
}

Expand Down