Skip to content

[Android, iOS] Dynamically setting SearchHandler Query property does not update text in the search box #28400

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

Merged
merged 10 commits into from
Mar 28, 2025

Conversation

HarishwaranVijayakumar
Copy link
Contributor

@HarishwaranVijayakumar HarishwaranVijayakumar commented Mar 14, 2025

Reverting this PR

#30222

Root Cause of the issue

  • On Android and iOS, the change to the Query property was not implemented in the SearchHandlerPropertyChanged method, which results in the SearchHandler's Query property not being updated during runtime.

Description of Change

  • To resolve this, I have implemented the query property change in SearchHandlerPropertyChanged method on both Android and iOS platforms.

Issues Fixed

Fixes #14497

Tested the behaviour in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Output

Before Fix After Fix
SearchHandlerBeforeFixAndroid.mov
SearchHandlerAfterFixAndroid.mov
SearchHandlerBeforeFixiOS.mov
SearchHandlerAfterFixiOS.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Mar 14, 2025
Copy link
Contributor

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 dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Mar 14, 2025
@HarishwaranVijayakumar
Copy link
Contributor Author

@dotnet-policy-service agree company="Syncfusion, Inc."

@jsuarezruiz jsuarezruiz added platform/android platform/ios area-controls-shell Shell Navigation, Routes, Tabs, Flyout labels Mar 14, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@HarishwaranVijayakumar HarishwaranVijayakumar changed the title [Android][iOS] Dynamically setting SearchHandler Query property does not update text in the search box [Android, iOS] Dynamically setting SearchHandler Query property does not update text in the search box Mar 14, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you commit the pending test snapshot for macOS?

@HarishwaranVijayakumar HarishwaranVijayakumar marked this pull request as ready for review March 18, 2025 10:45
@HarishwaranVijayakumar HarishwaranVijayakumar requested a review from a team as a code owner March 18, 2025 10:45
@rmarinho
Copy link
Member

/azp run

@rmarinho rmarinho requested a review from jsuarezruiz March 18, 2025 17:30
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

{
App.WaitForElement(ChangeSearchText);
App.Tap(ChangeSearchText);
#if MACCATALYST || IOS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have sense to have an extension method to access the Shell SearchBar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz, as suggested modified the method UpdateText for android platform

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

{
IUIElement? element = null;

if (app is AppiumAndroidApp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
    };

@PureWeen PureWeen changed the base branch from main to inflight/current March 28, 2025 16:00
@PureWeen PureWeen merged commit f6353ac into dotnet:inflight/current Mar 28, 2025
126 of 128 checks passed
github-actions bot pushed a commit that referenced this pull request Apr 2, 2025
…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
github-actions bot pushed a commit that referenced this pull request Apr 3, 2025
…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
github-actions bot pushed a commit that referenced this pull request Apr 8, 2025
…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
bhavanesh2001 pushed a commit to bhavanesh2001/maui that referenced this pull request Apr 11, 2025
…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
PureWeen pushed a commit that referenced this pull request Apr 11, 2025
…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
github-actions bot pushed a commit that referenced this pull request Apr 11, 2025
…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
github-actions bot pushed a commit that referenced this pull request Apr 14, 2025
…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
github-actions bot pushed a commit that referenced this pull request Apr 15, 2025
…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
@github-actions github-actions bot locked and limited conversation to collaborators Apr 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android platform/ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Shell] Dynamically setting SearchHandler Query property does not update text in the search box
4 participants