зеркало из https://github.com/DeGsoft/maui-linux.git
[iOS] Use separate UIWindow for UIAlertController (#481)
* [iOS] Use separate UIWindow for UIAlertController * Add similar behavior for DisplayActionSheet; consolidate behavior into PresentAlert method
This commit is contained in:
Родитель
04cc360a39
Коммит
7f9f2530ca
|
@ -0,0 +1,78 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Bugzilla, 45743, "[iOS] Calling DisplayAlert via BeginInvokeOnMainThread blocking other calls on iOS", PlatformAffected.iOS)]
|
||||
public class Bugzilla45743 : TestNavigationPage
|
||||
{
|
||||
protected override void Init()
|
||||
{
|
||||
PushAsync(new ContentPage
|
||||
{
|
||||
Content = new StackLayout
|
||||
{
|
||||
AutomationId = "Page1",
|
||||
Children =
|
||||
{
|
||||
new Label { Text = "Page 1" }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await DisplayAlert("Title", "Message", "Accept", "Cancel");
|
||||
});
|
||||
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await PushAsync(new ContentPage
|
||||
{
|
||||
AutomationId = "Page2",
|
||||
Content = new StackLayout
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new Label { Text = "Page 2" }
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await DisplayAlert("Title 2", "Message", "Accept", "Cancel");
|
||||
});
|
||||
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await DisplayActionSheet("ActionSheet Title", "Cancel", "Close", new string[] { "Test", "Test 2" });
|
||||
});
|
||||
}
|
||||
|
||||
#if UITEST
|
||||
|
||||
#if __IOS__
|
||||
[Test]
|
||||
public void Bugzilla45743Test()
|
||||
{
|
||||
RunningApp.WaitForElement(q => q.Marked("ActionSheet Title"));
|
||||
RunningApp.Tap("Close");
|
||||
RunningApp.WaitForElement(q => q.Marked("Title 2"));
|
||||
RunningApp.Tap("Accept");
|
||||
RunningApp.WaitForElement(q => q.Marked("Title"));
|
||||
RunningApp.Tap("Accept");
|
||||
Assert.True(RunningApp.Query(q => q.Text("Page 2")).Length > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -133,6 +133,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42832.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44044.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44338.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45743.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />
|
||||
|
|
|
@ -54,9 +54,8 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
alert.AddAction(UIAlertAction.Create(arguments.Cancel, UIAlertActionStyle.Cancel, a => arguments.SetResult(false)));
|
||||
if (arguments.Accept != null)
|
||||
alert.AddAction(UIAlertAction.Create(arguments.Accept, UIAlertActionStyle.Default, a => arguments.SetResult(true)));
|
||||
var page = _modals.Any() ? _modals.Last() : Page;
|
||||
var vc = GetRenderer(page).ViewController;
|
||||
vc.PresentViewController(alert, true, null);
|
||||
|
||||
PresentAlert(alert);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -121,7 +120,7 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow
|
||||
}
|
||||
|
||||
pageRenderer.ViewController.PresentViewController(alert, true, null);
|
||||
PresentAlert(alert);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -431,6 +430,15 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
return Page == page || _modals.Contains(page);
|
||||
}
|
||||
|
||||
void PresentAlert(UIAlertController alert)
|
||||
{
|
||||
var window = new UIWindow { BackgroundColor = Color.Transparent.ToUIColor() };
|
||||
window.RootViewController = new UIViewController();
|
||||
window.RootViewController.View.BackgroundColor = Color.Transparent.ToUIColor();
|
||||
window.MakeKeyAndVisible();
|
||||
window.RootViewController.PresentViewController(alert, true, null);
|
||||
}
|
||||
|
||||
async Task PresentModal(Page modal, bool animated)
|
||||
{
|
||||
var modalRenderer = GetRenderer(modal);
|
||||
|
|
Загрузка…
Ссылка в новой задаче