Skip to content

Null Pointer Crash in KeyboardAutoScrollManager.AdjustPosition #21160

@frankus

Description

@frankus

Description

When testing a plugin that uses a third-party SDK to present UI, presenting a full-screen modal view controller with text fields results in a crash (null pointer exception) in the AdjustPosition method of KeyboardAutoScrollManager.

Changing the modal presentation style to something other than .FullScreen is a workaround that avoids the crash.

Steps to Reproduce

  1. Create a new Maui App from the template
  2. Replace the contents of MainPage.xaml with the code snippet below
  3. Build and run the app for iOS (dotnet build -f:net8.0-ios -t:Run)
  4. In the app, click the "click me" button, and click into one of the text fields, and then the other text field
  5. Observe a crash with a null pointer exception in KeyboardAutoScrollManager.AdjustPosition
using CoreGraphics;
using UIKit;

namespace keyboard_crash;

public partial class MainPage : ContentPage
{
	public MainPage()
	{
		InitializeComponent();
	}

	private void OnCounterClicked(object sender, EventArgs e)
	{
		var rootVC = UIApplication.SharedApplication.KeyWindow.RootViewController;

		if (rootVC != null) {
			var testVC = new TestViewController();

			var testNC = new UINavigationController(testVC);

			// Changing this from the default to "FullScreen" is the key to making it crash.
			testNC.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;

			rootVC.PresentViewController(testNC, true, null);
		}
	}
}

public class TestViewController: UIViewController {
	UITextField TextField1;
	UITextField TextField2;

	public override void ViewDidLoad() {
		base.ViewDidLoad();

		View.BackgroundColor = UIColor.White;

		TextField1 = new UITextField(new CGRect(20, 120, 200, 20));
		TextField2 = new UITextField(new CGRect(20, 220, 200, 20));

		TextField1.BorderStyle = UITextBorderStyle.RoundedRect;
		TextField2.BorderStyle = UITextBorderStyle.RoundedRect;

		View.AddSubview(TextField1);
		View.AddSubview(TextField2);
	}
}

Link to public reproduction project repository

No response

Version with bug

8.0.6 SR1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

Only tested with iOS 17.0

Did you find any workaround?

Yes, presenting the view controller with a ModalPresentationStyle of e.g. PageSheet avoids the crash.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions