[Android, iOS] Dynamically setting SearchHandler Query property does not update text in the search box#28400
Conversation
|
Hey there @HarishwaranVijayakumar! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
@dotnet-policy-service agree company="Syncfusion, Inc." |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14497.cs
Outdated
Show resolved
Hide resolved
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
jsuarezruiz
left a comment
There was a problem hiding this comment.
Could you commit the pending test snapshot for macOS?
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14497.cs
Outdated
Show resolved
Hide resolved
This reverts commit d3959fe.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| { | ||
| App.WaitForElement(ChangeSearchText); | ||
| App.Tap(ChangeSearchText); | ||
| #if MACCATALYST || IOS |
There was a problem hiding this comment.
Maybe have sense to have an extension method to access the Shell SearchBar.
There was a problem hiding this comment.
@jsuarezruiz, as suggested added a method in the helper extension class to access Shell SearchBar
| UpdateTextTransform(); | ||
|
|
||
| // Prevents the cursor to reset to position zero when the text is set programmatically | ||
| _editText.SetSelection(_editText.Text?.Length ?? 0); |
There was a problem hiding this comment.
This will always places the cursor at the end of the text. I think could manage the cursor position in this way:
- Storing the cursor position before changing the text
- Only placing the cursor at the end if there was a selection or if necessary
There was a problem hiding this comment.
Something like:
void UpdateText()
{
int cursorPosition = editText.SelectionStart;
bool selectionExists = editText.HasSelection;
editText.Text = searchHandler.Query ?? string.Empty;
UpdateTextTransform();
// If we had a selection, place the cursor at the end of text
// Otherwise try to maintain the cursor at its previous position
int textLength = editText.Text?.Length ?? 0;
int newPosition = selectionExists ? textLength : Math.Min(cursorPosition, textLength);
// Prevents the cursor from resetting to position zero when text is set programmatically
editText.SetSelection(newPosition);
}
There was a problem hiding this comment.
@jsuarezruiz, as suggested modified the method UpdateText for android platform
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| { | ||
| IUIElement? element = null; | ||
|
|
||
| if (app is AppiumAndroidApp) |
There was a problem hiding this comment.
Could be:
IUIElement? element = app switch
{
AppiumAndroidApp => app.WaitForElement(AppiumQuery.ByXPath("//android.widget.EditText")),
AppiumIOSApp or AppiumCatalystApp => app.WaitForElement(AppiumQuery.ByXPath("//XCUIElementTypeSearchField")),
AppiumWindowsApp => app.WaitForElement("TextBox"),
_ => null // Fallback for unsupported platforms
};
…not update text in the search box (#28400) * Fix for query not updating during runtime * Fix for SearchHandler * Fix for SearchHandler Dynamic Update * Fix for Dynamic SearchHandler QueryProperty * Fix for query not updating in runtime * Fix for searchHandler * Updating the images * Revert "Updating the images" This reverts commit d3959fe. * Modified Test case for search Handler * Modifying the testcase and. the code
…not update text in the search box (#28400) * Fix for query not updating during runtime * Fix for SearchHandler * Fix for SearchHandler Dynamic Update * Fix for Dynamic SearchHandler QueryProperty * Fix for query not updating in runtime * Fix for searchHandler * Updating the images * Revert "Updating the images" This reverts commit d3959fe. * Modified Test case for search Handler * Modifying the testcase and. the code
…not update text in the search box (#28400) * Fix for query not updating during runtime * Fix for SearchHandler * Fix for SearchHandler Dynamic Update * Fix for Dynamic SearchHandler QueryProperty * Fix for query not updating in runtime * Fix for searchHandler * Updating the images * Revert "Updating the images" This reverts commit d3959fe. * Modified Test case for search Handler * Modifying the testcase and. the code
…not update text in the search box (dotnet#28400) * Fix for query not updating during runtime * Fix for SearchHandler * Fix for SearchHandler Dynamic Update * Fix for Dynamic SearchHandler QueryProperty * Fix for query not updating in runtime * Fix for searchHandler * Updating the images * Revert "Updating the images" This reverts commit d3959fe. * Modified Test case for search Handler * Modifying the testcase and. the code
…not update text in the search box (#28400) * Fix for query not updating during runtime * Fix for SearchHandler * Fix for SearchHandler Dynamic Update * Fix for Dynamic SearchHandler QueryProperty * Fix for query not updating in runtime * Fix for searchHandler * Updating the images * Revert "Updating the images" This reverts commit d3959fe. * Modified Test case for search Handler * Modifying the testcase and. the code
…not update text in the search box (#28400) * Fix for query not updating during runtime * Fix for SearchHandler * Fix for SearchHandler Dynamic Update * Fix for Dynamic SearchHandler QueryProperty * Fix for query not updating in runtime * Fix for searchHandler * Updating the images * Revert "Updating the images" This reverts commit d3959fe. * Modified Test case for search Handler * Modifying the testcase and. the code
…not update text in the search box (#28400) * Fix for query not updating during runtime * Fix for SearchHandler * Fix for SearchHandler Dynamic Update * Fix for Dynamic SearchHandler QueryProperty * Fix for query not updating in runtime * Fix for searchHandler * Updating the images * Revert "Updating the images" This reverts commit d3959fe. * Modified Test case for search Handler * Modifying the testcase and. the code
…not update text in the search box (#28400) * Fix for query not updating during runtime * Fix for SearchHandler * Fix for SearchHandler Dynamic Update * Fix for Dynamic SearchHandler QueryProperty * Fix for query not updating in runtime * Fix for searchHandler * Updating the images * Revert "Updating the images" This reverts commit d3959fe. * Modified Test case for search Handler * Modifying the testcase and. the code
Reverting this PR
#30222
Root Cause of the issue
Description of Change
Issues Fixed
Fixes #14497
Tested the behaviour in the following platforms
Output
SearchHandlerBeforeFixAndroid.mov
SearchHandlerAfterFixAndroid.mov
SearchHandlerBeforeFixiOS.mov
SearchHandlerAfterFixiOS.mov