Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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>
Expand Down Expand Up @@ -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) {
m_comingFromJS = true;
{
if (text.has_value()) {
Expand Down Expand Up @@ -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();
data.attributedStringBox = facebook::react::AttributedStringBox{facebook::react::AttributedString{}};
data.mostRecentEventCount = m_nativeEventCount;

m_state->updateState(std::move(data));
}
return;
}
Expand Down
Loading