-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix SearchBar text bleeding between instances after navigation #34703
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 20348, "SearchBar text incorrectly copied between multiple SearchBars on Android after back navigation", PlatformAffected.Android)] | ||
| public class Issue20348 : NavigationPage | ||
| { | ||
| public Issue20348() : base(new MainPage()) | ||
| { | ||
| } | ||
|
|
||
| public class MainPage : ContentPage | ||
| { | ||
| public MainPage() | ||
| { | ||
| SearchBar firstSearchBar = new SearchBar | ||
| { | ||
| AutomationId = "FirstSearchBar" | ||
| }; | ||
|
|
||
| Label firstSearchBarTextLabel = new Label | ||
| { | ||
| AutomationId = "FirstSearchBarText", | ||
| Text = "Pass" | ||
| }; | ||
|
|
||
| firstSearchBar.TextChanged += (s, e) => | ||
| { | ||
| firstSearchBarTextLabel.Text = string.IsNullOrEmpty(e.NewTextValue) | ||
| ? "Pass" | ||
| : "Fail"; | ||
| }; | ||
|
|
||
| SearchBar secondSearchBar = new SearchBar | ||
| { | ||
| AutomationId = "SecondSearchBar" | ||
| }; | ||
|
|
||
| Button navigateButton = new Button | ||
| { | ||
| Text = "Navigate", | ||
| AutomationId = "NavigateButton" | ||
| }; | ||
|
|
||
| navigateButton.Clicked += async (s, e) => | ||
| { | ||
| await Navigation.PushAsync(new SecondPage()); | ||
| }; | ||
|
|
||
| Label descriptionLabel = new Label | ||
| { | ||
| Text = "Test passes if SecondSearchBar text is NOT applied to FirstSearchBar after typing in SecondSearchBar, navigating to page 2, and pressing back.", | ||
| FontSize = 12, | ||
| TextColor = Colors.Gray, | ||
| HorizontalTextAlignment = TextAlignment.Center | ||
| }; | ||
|
|
||
| Content = new VerticalStackLayout | ||
| { | ||
| Padding = 20, | ||
| Spacing = 10, | ||
| Children = { descriptionLabel, firstSearchBar, firstSearchBarTextLabel, secondSearchBar, navigateButton } | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| public class SecondPage : ContentPage | ||
| { | ||
| public SecondPage() | ||
| { | ||
| Title = "Second Page"; | ||
| Content = new Label | ||
| { | ||
| Text = "Second Page", | ||
| AutomationId = "SecondPageLabel", | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| VerticalOptions = LayoutOptions.Center | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||||||
| using NUnit.Framework; | ||||||||||
| using UITest.Appium; | ||||||||||
| using UITest.Core; | ||||||||||
|
|
||||||||||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||||||||||
|
|
||||||||||
| public class Issue20348 : _IssuesUITest | ||||||||||
| { | ||||||||||
| public override string Issue => "SearchBar text incorrectly copied between multiple SearchBars on Android after back navigation"; | ||||||||||
|
|
||||||||||
| public Issue20348(TestDevice device) : base(device) { } | ||||||||||
|
|
||||||||||
| [Test] | ||||||||||
| [Category(UITestCategories.SearchBar)] | ||||||||||
| public void SearchBarTextShouldNotBleedToOtherInstances() | ||||||||||
| { | ||||||||||
| App.WaitForElement("FirstSearchBar"); | ||||||||||
| App.WaitForElement("SecondSearchBar"); | ||||||||||
|
|
||||||||||
| App.EnterText("SecondSearchBar", "TestText"); | ||||||||||
|
||||||||||
| App.EnterText("SecondSearchBar", "TestText"); | |
| App.EnterText("SecondSearchBar", "TestText"); | |
| App.DismissKeyboard(); | |
| App.WaitForElement("NavigateButton"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FirstSearchBarTextis updated only viafirstSearchBar.TextChanged. If the Android state-restore path updates the platform text without raising the managedTextChangedevent (or does so before the handler is attached in future refactors), this issue page can show "Pass" while the first SearchBar actually contains leaked text, making the UI test a false negative. Consider also updating the label based onfirstSearchBar.TextinOnAppearing(or after returning from navigation).