Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fixed the SoftInputMode issues with modal pages #27553

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -256,6 +256,13 @@ public ModalFragment(IMauiContext mauiContext, Page modal)

dialog.Window.SetBackgroundDrawable(TransparentColorDrawable);

var attributes = Context?.GetActivity()?.Window?.Attributes;

if (attributes is not null)
{
dialog.Window.SetSoftInputMode(attributes.SoftInputMode);
}

return dialog;
}

Expand Down
97 changes: 97 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27242.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
using Button = Microsoft.Maui.Controls.Button;
using Entry = Microsoft.Maui.Controls.Entry;
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 27242, "[Android] WindowSoftInputModeAdjust is not working for modal pages", PlatformAffected.Android)]
public class Issue27242 : ContentPage
{
public Issue27242()
{
var layout = new VerticalStackLayout() { Padding = new Thickness(20) };
var button1 = new Button { Text = "Go to ResizeModalPage" };
button1.AutomationId = "Button1";
button1.Clicked += async (s, e) => await Navigation.PushModalAsync(new Issue27242Page1());
layout.Add(button1);

var button2 = new Button { Text = "Go to PanModalPage" };
button2.AutomationId = "Button2";
button2.Clicked += async (s, e) => await Navigation.PushModalAsync(new Issue27242Page2());
layout.Add(button2);
Content = layout;
}
}

public class Issue27242Page1 : ContentPage
{
protected override void OnAppearing()
{
base.OnAppearing();
App.Current!.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}
public Issue27242Page1()
{
var grid = new Grid
{
Padding = 20,
RowSpacing = 20,
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(50) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
}
};

var button = new Button { Text = "Back to Home Page" };
button.AutomationId = "BackButton";
button.Clicked += async (s, e) => await Navigation.PopModalAsync();
grid.Add(button, 0, 0);

var entry = new Entry();
entry.AutomationId = "Page1Entry";
grid.Add(entry, 0, 1);

var greenBox = new BoxView { BackgroundColor = Colors.Green };
grid.Add(greenBox, 0, 2);

Content = grid;
}
}

public class Issue27242Page2 : ContentPage
{
protected override void OnAppearing()
{
base.OnAppearing();
//default mode
App.Current!.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Pan);
}
public Issue27242Page2()
{
var grid = new Grid
{
Padding = 20,
RowSpacing = 20,
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(75) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
}
};

var redBox = new BoxView { BackgroundColor = Colors.Red };
grid.Add(redBox, 0, 0);

var entry = new Entry();
entry.AutomationId = "Page2Entry";
grid.Add(entry, 0, 1);

var greenBox = new BoxView { BackgroundColor = Colors.Green };
//scrollview
var scrollView = new ScrollView { Content = greenBox };
grid.Add(scrollView, 0, 2);
Content = grid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#if ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue27242 : _IssuesUITest
{
const string Button1 = "Button1";
const string Page1Entry = "Page1Entry";
const string Button2 = "Button2";
const string Page2Entry = "Page2Entry";

public Issue27242(TestDevice device) : base(device) { }

public override string Issue => "[Android] WindowSoftInputModeAdjust is not working for modal pages";

[Test, Order(1)]
[Category(UITestCategories.Page)]
public void WindowSoftInputModeAdjustSetToResizeForModalPage()
{
App.WaitForElement(Button1);
App.Tap(Button1);
App.WaitForElement(Page1Entry);
var beforeEntryRectY = App.WaitForElement(Page1Entry).GetRect().Y;
App.Tap(Page1Entry);
var afterEntryRectY = App.WaitForElement(Page1Entry).GetRect().Y;
Assert.That(beforeEntryRectY, Is.Not.EqualTo(afterEntryRectY));
App.Tap("BackButton");
}

[Test, Order(2)]
[Category(UITestCategories.Page)]
public void WindowSoftInputModeAdjustSetToPanForModalpage()
{
App.WaitForElement(Button2);
App.Tap(Button2);
App.WaitForElement(Page2Entry);
var beforeEntryRectY = App.WaitForElement(Page2Entry).GetRect().Y;
App.Tap(Page2Entry);
var afterEntryRectY = App.WaitForElement(Page2Entry).GetRect().Y;
Assert.That(beforeEntryRectY, Is.EqualTo(afterEntryRectY));
}
}
}
#endif
Loading