-
Couldn't load subscription status.
- Fork 1.2k
Adding fix for Manual set value clearTextOnSubmit-style behavior not working on Fabric #15277
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?
Changes from 3 commits
d9ad94e
0e83625
8dde8cc
da2a4bf
13473ed
4c8e428
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "comment": "adding fix for TextInput", | ||
| "type": "prerelease", | ||
| "packageName": "react-native-windows", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |
| #include <Fabric/platform/react/renderer/graphics/PlatformColorUtils.h> | ||
| #include <Utils/ThemeUtils.h> | ||
| #include <Utils/ValueUtils.h> | ||
| #include <react/renderer/attributedstring/AttributedString.h> | ||
| #include <react/renderer/attributedstring/AttributedStringBox.h> | ||
| #include <react/renderer/components/textinput/TextInputState.h> | ||
| #include <react/renderer/graphics/HostPlatformColor.h> | ||
| #include <react/renderer/textlayoutmanager/WindowsTextLayoutManager.h> | ||
|
|
@@ -541,7 +543,10 @@ void WindowsTextInputComponentView::HandleCommand( | |
| std::optional<winrt::hstring> text; | ||
|
|
||
| winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), eventCount, text, begin, end); | ||
| if (eventCount >= m_nativeEventCount) { | ||
| // Allow text updates that are very close to the current native event count | ||
| // This handles the case where JavaScript immediately calls setValue during onSubmitEditing | ||
| // In that case, eventCount might be one less than m_nativeEventCount due to timing | ||
| if (eventCount >= m_nativeEventCount - 1) { | ||
protikbiswas100 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| m_comingFromJS = true; | ||
| { | ||
| if (text.has_value()) { | ||
|
|
@@ -961,6 +966,13 @@ void WindowsTextInputComponentView::OnCharacterReceived( | |
| if (m_clearTextOnSubmit) { | ||
| // clear text from RichEdit | ||
| m_textServices->TxSetText(L""); | ||
| // Also update the state to reflect the cleared text | ||
| // This ensures consistency between native and JS state | ||
| auto data = m_state->getData(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should already happen through WindowsTextInputComponentView::OnTextUpdated. -- Why are we not hitting that case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right that TxSetText(L"") should normally trigger [EN_CHANGE] → OnTextUpdated(). However, there are several timing and context issues that make the manual state update necessary. One reason why we are not hitting the case I believe is that OnTextUpdated() method has a condition if (m_eventEmitter && !m_comingFromJS) that prevents event emission when m_comingFromJS is true. While we're not setting m_comingFromJS = true here, there might be other state flags or timing issues that could suppress the automatic notification. |
||
| data.attributedStringBox = facebook::react::AttributedStringBox{facebook::react::AttributedString{}}; | ||
| data.mostRecentEventCount = m_nativeEventCount; | ||
|
|
||
| m_state->updateState(std::move(data)); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.