-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix Entry/Editor crash when setting Text in TextChanged event handler #32005
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
- Defer text updates when DataFlowDirection is FromPlatform to avoid re-entering TextWatcher callbacks - Prevents "end should be < than charSequence length" crash in androidx.emoji2.text.EmojiCompat - Added UI test case to validate the fix Co-authored-by: rmarinho <[email protected]>
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
@copilot Tests should match the name of the issue being fixed
Can you please fix the name on this test and update any copilot instructions that led you to create this name incorrectly
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.
Renamed test files to match issue number #32004. Updated in commit 0e3c907.
- Renamed EntryTextChangedCrash to Issue32004 for HostApp test files - Renamed EntryTextChangedCrash to Issue32004 for shared test file - Updated class names and issue tracker number to 32004 Co-authored-by: PureWeen <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
|
||
| [Test] | ||
| [Category(UITestCategories.Entry)] | ||
| public void EntryDoesNotCrashWhenSettingTextInTextChangedEvent() |
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.
This test is failing on Android.
The app was expected to be running still, investigate as possible crash
TearDown : The app was expected to be running still, investigate as possible crash
@copilot Review
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.
Fixed the test crash by using PostDelayed(10ms) instead of Post() to ensure TextWatcher callbacks complete before the deferred update runs. Also added a wait in the test to allow the deferred update to complete. Updated in commit e7a9312.
- Changed from Post() to PostDelayed(10ms) to ensure TextWatcher callbacks complete - Added null checks for PlatformView in deferred callbacks - Added Task.Delay in test to wait for deferred update to complete - This should prevent the app crash during test execution Co-authored-by: jsuarezruiz <[email protected]>
Root Cause
When user deletes text in an Entry, Android's TextWatcher callbacks are triggered. During these callbacks, if the MAUI TextChanged event handler modifies the Text property, it causes a re-entrant call to set EditText.Text while EmojiCompat is still processing the original change. This leads to "end should be < than charSequence length" crash in
androidx.emoji2.text.EmojiCompat.Solution
Modified
MapTextin bothEntryHandler.Android.csandEditorHandler.Android.csto check ifDataFlowDirectionisFromPlatform. When true, the text update is deferred usingPostDelayed()with a 10ms delay to ensure TextWatcher callbacks have fully completed before applying the new value.Changes Made:
Test Case
Created
Issue32004test that:How It Works
DataFlowDirectionis set toFromPlatformPostDelayed(10ms)to defer the updateOriginal prompt
This section details on the original issue you should resolve
<issue_title>end should be < than charSequence length</issue_title>
<issue_description>### Description
I am getting a crash when using
TextChangedon aEntrymodifying the value.Steps to Reproduce
Link to public reproduction project repository
https://github.com/jdarwood007/MauiApp9
Version with bug
9.0.110 SR11
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 14
Did you find any workaround?
The problem seems to be entirely calling this:
Relevant log output