-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS] Crash upon resuming the app - fix (#23360)
* [iOS] Crash upon resuming the app - fix (#21948) * Refactor * Update UIApplicationExtensions.cs * Update UIApplicationExtensions.cs * Update UIApplicationExtensions.cs * Added a UI test (#21948) * Added a test category (#23428) * remove "'" --------- Co-authored-by: Shane Neuville <[email protected]>
- Loading branch information
Showing
4 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue21948"> | ||
<Button Text="Open a new window" | ||
AutomationId="button" | ||
Clicked="OpenNewWindowClicked" /> | ||
</ContentPage> |
79 changes: 79 additions & 0 deletions
79
src/Controls/tests/TestCases.HostApp/Issues/Issue21948.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
using Microsoft.Maui.Platform; | ||
using Microsoft.Maui; | ||
using System.Linq; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
#if IOS || MACCATALYST | ||
using UIKit; | ||
using CoreGraphics; | ||
#endif | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 21948, "Crash upon resuming the app window was already activated", PlatformAffected.iOS)] | ||
public partial class Issue21948 : ContentPage | ||
{ | ||
public Issue21948() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public void OpenNewWindowClicked(object obj, EventArgs e) | ||
{ | ||
#if IOS || MACCATALYST | ||
OpenNewWindow(); | ||
#endif | ||
} | ||
|
||
#if IOS || MACCATALYST | ||
async void OpenNewWindow() | ||
{ | ||
var uIWindow = new UIWindow(); | ||
var keyWindow = (this.Window.Handler.PlatformView as UIWindow); | ||
if (keyWindow?.WindowLevel == UIWindowLevel.Normal) | ||
keyWindow.WindowLevel = -1; | ||
|
||
var page = new ContentPage(); | ||
this.AddLogicalChild(page); | ||
var handler = page.ToHandler(this.Handler.MauiContext); | ||
|
||
uIWindow.RootViewController = new UIViewController(); | ||
uIWindow.WindowLevel = UIWindowLevel.Normal; | ||
uIWindow.MakeKeyAndVisible(); | ||
|
||
// Simulate backgrounding the app | ||
nint taskId = UIApplication.BackgroundTaskInvalid; | ||
taskId = UIApplication.SharedApplication.BeginBackgroundTask(() => | ||
{ | ||
UIApplication.SharedApplication.EndBackgroundTask(taskId); | ||
}); | ||
|
||
// Simulate background time | ||
await Task.Delay(2000); | ||
UIApplication.SharedApplication.EndBackgroundTask(taskId); | ||
|
||
var rvc = uIWindow.RootViewController; | ||
|
||
if (rvc != null) | ||
{ | ||
await rvc.DismissViewControllerAsync(false); | ||
rvc.Dispose(); | ||
} | ||
|
||
// Simulate bringing the app back to the foreground | ||
await Task.Delay(1000); | ||
|
||
uIWindow.RootViewController = null; | ||
uIWindow.Hidden = true; | ||
keyWindow.WindowLevel = UIWindowLevel.Normal; | ||
this.RemoveLogicalChild(page); | ||
} | ||
#endif | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23360.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#if IOS || MACCATALYST | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues | ||
{ | ||
public class Issue21948 : _IssuesUITest | ||
{ | ||
public Issue21948(TestDevice device) : base(device) { } | ||
|
||
public override string Issue => "Crash upon resuming the app window was already activated"; | ||
|
||
[Test] | ||
[Category(UITestCategories.Window)] | ||
public void OpenAlertWithModals() | ||
{ | ||
App.WaitForElement("button"); | ||
App.Click("button"); | ||
|
||
// The test passes if no exception is thrown | ||
App.WaitForElement("button"); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters