-
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.
Fix null reference exception in KeyboardAutoManagerScroll when UIWind…
…ow is null (#21753) * Fix null reference when window is null When using certain controls ie bottom sheets and search bars there can be a crash when the keyboard displays. Check for null & return early if it is. * set flag to false if returning * remove change on line 1 * Add IsDescendant of ContainerVC * remove the extra IsKeyboardAutoScrollHandling flag * remove extra style changes * Add UITest * Use UIView AccessibilityIdentifier on UITest * Add ignore in platform and remove catch in favor of rebasing main --------- Co-authored-by: tj-devel709 <[email protected]>
- Loading branch information
1 parent
63eb6b6
commit 7a37ebf
Showing
4 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/Controls/samples/Controls.Sample.UITests/Issues/Issue21726.xaml
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,9 @@ | ||
<?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.Issue21726" | ||
Title="Issue21726"> | ||
<VerticalStackLayout> | ||
<Button Text="AddVC" AutomationId="AddVC" Clicked="AddVC"/> | ||
</VerticalStackLayout> | ||
</ContentPage> |
77 changes: 77 additions & 0 deletions
77
src/Controls/samples/Controls.Sample.UITests/Issues/Issue21726.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,77 @@ | ||
using System; | ||
using System.Linq; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
using System.Threading.Tasks; | ||
|
||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 21726, "Modal with a bottom sheet should not crash iOS Keyboard Scroll", PlatformAffected.iOS)] | ||
public partial class Issue21726 : ContentPage | ||
{ | ||
public Issue21726() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
void AddVC (object sender, EventArgs e) | ||
{ | ||
#if IOS | ||
var window = UIKit.UIApplication.SharedApplication | ||
.ConnectedScenes | ||
.OfType<UIKit.UIWindowScene>() | ||
.SelectMany(s => s.Windows) | ||
.FirstOrDefault(w => w.IsKeyWindow); | ||
|
||
var rootVC = window?.RootViewController; | ||
while (rootVC?.PresentedViewController != null) | ||
{ | ||
rootVC = rootVC.PresentedViewController; | ||
} | ||
|
||
if (rootVC is not null) { | ||
var testVC = new TestViewController(); | ||
|
||
var testNC = new UIKit.UINavigationController(testVC) | ||
{ | ||
ModalPresentationStyle = UIKit.UIModalPresentationStyle.FullScreen | ||
}; | ||
|
||
rootVC.PresentViewController(testNC, true, null); | ||
} | ||
#endif | ||
} | ||
|
||
#if IOS | ||
public class TestViewController: UIKit.UIViewController { | ||
|
||
UIKit.UITextField TextField1; | ||
UIKit.UIButton Button1; | ||
|
||
public override void ViewDidLoad() { | ||
base.ViewDidLoad(); | ||
|
||
View.BackgroundColor = UIKit.UIColor.White; | ||
|
||
TextField1 = new UIKit.UITextField(new CoreGraphics.CGRect(20, 120, 200, 20)) | ||
{ | ||
Placeholder = "TextField1", | ||
BorderStyle = UIKit.UITextBorderStyle.RoundedRect, | ||
AccessibilityIdentifier = "TextField1" | ||
}; | ||
|
||
Button1 = new UIKit.UIButton(new CoreGraphics.CGRect(20, 320, 200, 40)); | ||
Button1.SetTitle("Dismiss", UIKit.UIControlState.Normal); | ||
Button1.BackgroundColor = UIKit.UIColor.SystemBlue; | ||
Button1.AccessibilityIdentifier = "Button1"; | ||
Button1.TouchUpInside += (sender, e) => { | ||
DismissViewController(true, null); | ||
}; | ||
|
||
View.AddSubview(TextField1); | ||
View.AddSubview(Button1); | ||
} | ||
} | ||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.AppiumTests.Issues | ||
{ | ||
public class Issue21726 : _IssuesUITest | ||
{ | ||
public Issue21726(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
public override string Issue => "Modal with a bottom sheet should not crash iOS Keyboard Scroll"; | ||
|
||
[Test] | ||
public void PushViewControllerWithNullWindow() | ||
{ | ||
this.IgnoreIfPlatforms([TestDevice.Android, TestDevice.Mac, TestDevice.Windows]); | ||
|
||
App.WaitForElement("AddVC"); | ||
App.Click("AddVC"); | ||
App.WaitForElement("TextField1").Click(); | ||
App.WaitForElement("Button1").Click(); | ||
var mainPageElement = App.WaitForElement("AddVC"); | ||
Assert.NotNull(mainPageElement); | ||
} | ||
} | ||
} |
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