Skip to content

[Android] Fixed keyboard flickering issue with SearchHandler #30166

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

Closed

Conversation

Tamilarasan-Paranthaman
Copy link
Contributor

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!

Regression PR

Root Cause of the issue

  • The PR 28400 addresses a dynamic update issue with SearchHandler.Query by properly handling property changes.
  • When typing directly into the SearchHandler, the Query value was being updated using SetValue(SearchHandler.QueryProperty, value). This triggered the Query property changed event, which unnecessarily reassigned the same value. As a result, SearchHandler.Query was updated redundantly, causing flickering in both the keyboard and the SearchHandler itself.

Description of Change

  • Updated the property change logic to set the SearchHandler.Query property only when the new value differs from the current one, preventing redundant updates and resolving both the flickering issue and the dynamic value-setting problem.

Test Case

  • Since this issue is related to animations on older Android versions, reliably automating it does not seem to be feasible.

Issues Fixed

Fixes #30072

Tested the behaviour in the following platforms

  • Android
  • iOS
  • Mac
  • Windows

Screenshot

Before Fix After Fix
Before-Fix.mp4
After-Fix.mp4

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jun 24, 2025
@PureWeen PureWeen added this to the .NET 9 SR9 milestone Jun 24, 2025
@PureWeen PureWeen added the p/0 Work that we can't release without label Jun 24, 2025
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman marked this pull request as ready for review June 24, 2025 14:08
@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 14:08
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman requested a review from a team as a code owner June 24, 2025 14:08
Copy link
Contributor

@Copilot Copilot AI left a 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 the keyboard flickering issue by updating the SearchHandler.Query only when its new value differs from the current text field value. The changes prevent redundant updates on both iOS and Android platforms.

  • On iOS, the UITextField is updated only if its current text differs from the new query.
  • On Android, the EditText is similarly updated only when necessary.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs Adds a null and equality check before updating UITextField.Text to prevent unnecessary updates.
src/Controls/src/Core/Compatibility/Handlers/Shell/Android/SearchHandlerAppearanceTracker.cs Implements an equivalent check by comparing _editText.Text with the new query value to avoid redundant assignments.

Copy link
Contributor

@bhavanesh2001 bhavanesh2001 left a comment

Choose a reason for hiding this comment

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

I'm fairly certain that with these changes, TextTransform won't work. (bit of context here #30084 (comment))

Could you also verify if the keyboard issue occurs with InputView's (Entry, Editor, and SearchBar)?

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

@github-project-automation github-project-automation bot moved this from Todo to Changes Requested in MAUI SDK Ongoing Jun 24, 2025
@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen requested a review from bhavanesh2001 June 25, 2025 11:09
@Tamilarasan-Paranthaman
Copy link
Contributor Author

Tamilarasan-Paranthaman commented Jun 25, 2025

I'm fairly certain that with these changes, TextTransform won't work. (bit of context here #30084 (comment))

Could you also verify if the keyboard issue occurs with InputView's (Entry, Editor, and SearchBar)?

@bhavanesh2001 / @PureWeen, yes, after these changes, TextTransform is not working as expected. Before version 9.0.70, it was not functioning correctly, and changes were introduced in this PR 28400 to address that as well.

I have now fixed it, but the issue reoccurs when TextTransform is applied, because the transformed text is reassigned to the control, which triggers the same keyboard flickering problem.

I tested this behavior with Editor, Entry, and SearchBar, and observed the same issue across all these controls when TextTransform is set. It appears that this affects all InputView-based controls.

For now, I have resolved the original issue, excluding the TextTransform scenario, which was a regression introduced in 9.0.70. Since the issue reported by the user is unrelated to TextTransform, this fix should be sufficient for their case.

Without TextTransform With TextTransform
Without-TT.mp4
With-TT.mp4

@@ -106,12 +106,17 @@ void UpdateCharacterSpacing()

void UpdateText()
{
string newText = _searchHandler.Query ?? string.Empty;

if (_editText.Text == newText)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think skipping it like this is okay, this is what we do with InputView's as well.

_editText.Text = _searchHandler.Query ?? string.Empty;

UpdateTextTransform();
_editText.Text = _searchHandler.UpdateFormsText(newText, _searchHandler.TextTransform);
Copy link
Contributor

@bhavanesh2001 bhavanesh2001 Jun 25, 2025

Choose a reason for hiding this comment

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

I checked the Android Entry implementation, and I think we can simplify the cursor management here by using SetTextKeepState() .

Also I think we should call TextTransform only inside this method.

So we can update the method like this:

		void UpdateText()
		{
			string newText = _searchHandler.UpdateFormsText(_searchHandler.Query ?? string.Empty, _searchHandler.TextTransform);

			if (_editText.Text == newText)
			{
				return;
			}
			_editText.SetTextKeepState(newText);
		}

This doesn’t cover an edge case, but that’s fine, our current implementation doesn’t handle it either.

For reference:

if (oldText != newText)
{
// This update is happening while inputting text into the EditText, so we want to avoid
// resettting the cursor position and selection
editText.SetTextKeepState(newText);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated it as suggested.

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

@bhavanesh2001 makes a lot of valid points

I think what we need to do for this work is synchronize code we've already written for InputView to the SearchHandler

All of these Same APIs already exist on Entry so we should be just running it all through the same methods and process

Each of the "Update methods" inside the SearchHandlerAppearanceTracker basically maps to the equivalent of an EntryHandler.

Can we just make it so SearchHandler implements ITextInput explicitly? (so we don't add any new APIs) and then we basically just reuse all the logic that's already inside the mappers to the SearchHandler?

The AfterText method on ShellSearchView.cs should mimic

void OnTextChanged(object? sender, TextChangedEventArgs e) inside EntryHandler.Android.cs

UpdateText inside SearchHandlerAppearanceTracker should mimic Entry.MapText

@github-project-automation github-project-automation bot moved this from Changes Requested to Done in MAUI SDK Ongoing Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution p/0 Work that we can't release without partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

SearchHandler causes keyboard flickering and character loss on Android
3 participants