diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp index d5a7beab4663..a9bc219f8bf7 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp @@ -11,7 +11,8 @@ namespace facebook::react { static jsi::Value textInputMetricsPayload( jsi::Runtime& runtime, - const TextInputEventEmitter::Metrics& textInputMetrics) { + const TextInputEventEmitter::Metrics& textInputMetrics, + bool includeSelectionState) { auto payload = jsi::Object(runtime); payload.setProperty( @@ -23,7 +24,7 @@ static jsi::Value textInputMetricsPayload( payload.setProperty(runtime, "eventCount", textInputMetrics.eventCount); - { + if (includeSelectionState) { auto selection = jsi::Object(runtime); selection.setProperty( runtime, "start", textInputMetrics.selectionRange.location); @@ -150,7 +151,7 @@ void TextInputEventEmitter::onContentSizeChange( void TextInputEventEmitter::onSelectionChange( const Metrics& textInputMetrics) const { - dispatchTextInputEvent("selectionChange", textInputMetrics); + dispatchTextInputEvent("selectionChange", textInputMetrics, true); } void TextInputEventEmitter::onEndEditing( @@ -178,10 +179,13 @@ void TextInputEventEmitter::onScroll(const Metrics& textInputMetrics) const { void TextInputEventEmitter::dispatchTextInputEvent( const std::string& name, - const Metrics& textInputMetrics) const { - dispatchEvent(name, [textInputMetrics](jsi::Runtime& runtime) { - return textInputMetricsPayload(runtime, textInputMetrics); - }); + const Metrics& textInputMetrics, + bool includeSelectionState) const { + dispatchEvent( + name, [includeSelectionState, textInputMetrics](jsi::Runtime& runtime) { + return textInputMetricsPayload( + runtime, textInputMetrics, includeSelectionState); + }); } void TextInputEventEmitter::dispatchTextInputContentSizeChangeEvent( diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h index dae4755e7964..dbce57515938 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h @@ -48,7 +48,8 @@ class TextInputEventEmitter : public ViewEventEmitter { private: void dispatchTextInputEvent( const std::string& name, - const Metrics& textInputMetrics) const; + const Metrics& textInputMetrics, + bool includeSelectionState = false) const; void dispatchTextInputContentSizeChangeEvent( const std::string& name,