Skip to content

Commit 6d1a24b

Browse files
author
Protik Biswas
committed
changing synchronization logic between JS and Native side
1 parent ab4fa57 commit 6d1a24b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,21 @@ void WindowsTextInputComponentView::HandleCommand(
545545
std::optional<winrt::hstring> text;
546546

547547
winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), eventCount, text, begin, end);
548-
// Accept text updates that match current event count, or are within a reasonable
549-
// tolerance for async JS responses to recent events (like onSubmitEditing)
548+
549+
// Standard synchronization check
550550
bool isCurrentEvent = eventCount >= m_nativeEventCount;
551-
bool isRecentAsyncResponse = (m_nativeEventCount - eventCount) <= 2; // Allow up to 2 events behind
551+
552+
// Special case: Allow setValue('') if it's responding to a recent onSubmitEditing event
553+
// This is safe because clearing text doesn't depend on intermediate state
554+
bool isSubmitClearResponse = false;
555+
if (!isCurrentEvent && text.has_value() && winrt::to_string(text.value()).empty()) {
556+
// Check if this could be a response to a recent onSubmitEditing event
557+
// Only allow if the event is recent (within last 3 events) and we have clearTextOnSubmit behavior
558+
isSubmitClearResponse = (m_nativeEventCount - eventCount) <= 3 &&
559+
(m_clearTextOnSubmit || m_lastSubmitEventCount == eventCount);
560+
}
552561

553-
if (isCurrentEvent || isRecentAsyncResponse) {
562+
if (isCurrentEvent || isSubmitClearResponse) {
554563
m_comingFromJS = true;
555564
{
556565
if (text.has_value()) {
@@ -964,6 +973,7 @@ void WindowsTextInputComponentView::OnCharacterReceived(
964973
facebook::react::WindowsTextInputEventEmitter::OnSubmitEditing onSubmitEditingArgs;
965974
onSubmitEditingArgs.text = GetTextFromRichEdit();
966975
onSubmitEditingArgs.eventCount = ++m_nativeEventCount;
976+
m_lastSubmitEventCount = m_nativeEventCount; // Track this submit event
967977
emitter->onSubmitEditing(onSubmitEditingArgs);
968978
}
969979

0 commit comments

Comments
 (0)