-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Android] Fix for SearchHandler retaining previous page SearchView data in pages within Shell sections #29545
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
base: main
Are you sure you want to change the base?
Conversation
…tent search behavior during navigation.
Hey there @@BagavathiPerumal! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
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.
Pull Request Overview
This PR fixes an Android issue where the SearchHandler retained outdated SearchView data when navigating between Shell pages.
- Updates the SearchHandler reference during page navigation in Shell to ensure it reflects the current page's configuration.
- Adds corresponding tests in the shared and host app test projects.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue8716.cs | Adds a UI test verifying that the SearchHandler updates correctly during page navigation. |
src/Controls/tests/TestCases.HostApp/Issues/Issue8716.cs | Implements Shell pages for Cats and Dogs with distinct SearchHandler settings. |
src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarTracker.cs | Introduces logic to update the SearchView’s SearchHandler if it mismatches the current page’s SearchHandler. |
Comments suppressed due to low confidence (1)
src/Controls/tests/TestCases.HostApp/Issues/Issue8716.cs:92
- [nitpick] Consider using a more descriptive AutomationId to differentiate this button from similar elements on other pages (e.g. using 'CatsPageButton' instead of 'MainPageButton').
var button = new Button { Text = "Button", AutomationId = "MainPageButton" }
@@ -646,6 +646,11 @@ protected virtual void UpdateToolbarItems(AToolbar toolbar, Page page) | |||
_searchView.View.LayoutParameters = new LP(LP.MatchParent, LP.MatchParent); | |||
_searchView.SearchConfirmed += OnSearchConfirmed; | |||
} | |||
else if (_searchView.SearchHandler != SearchHandler) |
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.
Consider adding explicit null checks when comparing _searchView.SearchHandler with SearchHandler to ensure robust handling in cases where one of them might be null.
else if (_searchView.SearchHandler != SearchHandler) | |
else if (_searchView.SearchHandler != null && SearchHandler != null && _searchView.SearchHandler != SearchHandler) |
Copilot uses AI. Check for mistakes.
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root cause
The issue occurs because SearchHandler references don't update properly during ShellSection page navigation. While SearchView instances are intentionally preserved for performance, the system failed to synchronize the SearchHandler reference when transitioning between pages. This caused search functionality to continue using the previous page's configuration instead of adopting the current page's settings, resulting in inconsistent search behavior and incorrect UI elements.
Description of Issue Fix
The fix involves adding a synchronization check that detects when the SearchView's SearchHandler doesn't match the current page's SearchHandler. When a mismatch is detected, the code updates the SearchView with the correct SearchHandler and refreshes the view. This ensures search functionality always reflects the current page context during navigation, preventing inconsistent behavior and UI elements.
Tested the behavior in the following platforms.
Issues Fixed
Fixes #8716
Output
SearchHandler-BeforeFix.mov
SearchHandler-AfterFix.mov