From 39a90552cd4cbb6aa7e470e5ea7f32d414d330bb Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Fri, 2 May 2025 00:01:23 +0800 Subject: [PATCH 1/3] [iOS] Fabric: Only add selection of textinput payload when event is selectionChange --- .../components/textinput/TextInputEventEmitter.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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..ef657f03bc01 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp @@ -11,6 +11,7 @@ namespace facebook::react { static jsi::Value textInputMetricsPayload( jsi::Runtime& runtime, + const std::string& name, const TextInputEventEmitter::Metrics& textInputMetrics) { auto payload = jsi::Object(runtime); @@ -23,7 +24,7 @@ static jsi::Value textInputMetricsPayload( payload.setProperty(runtime, "eventCount", textInputMetrics.eventCount); - { + if (name == "selectionChange") { auto selection = jsi::Object(runtime); selection.setProperty( runtime, "start", textInputMetrics.selectionRange.location); @@ -179,8 +180,8 @@ 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); + dispatchEvent(name, [name, textInputMetrics](jsi::Runtime& runtime) { + return textInputMetricsPayload(runtime, name, textInputMetrics); }); } From 1f2c85808f77de8858f156888d621cd5476d5965 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 11 Jun 2025 10:38:58 +0800 Subject: [PATCH 2/3] Change to a bollean --- .../textinput/TextInputEventEmitter.cpp | 20 ++++++++++++------- .../textinput/TextInputEventEmitter.h | 3 ++- 2 files changed, 15 insertions(+), 8 deletions(-) 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 ef657f03bc01..50e6da4f7f76 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp @@ -12,7 +12,9 @@ namespace facebook::react { static jsi::Value textInputMetricsPayload( jsi::Runtime& runtime, const std::string& name, - const TextInputEventEmitter::Metrics& textInputMetrics) { + + const TextInputEventEmitter::Metrics& textInputMetrics, + bool includeSelectionState) { auto payload = jsi::Object(runtime); payload.setProperty( @@ -24,7 +26,7 @@ static jsi::Value textInputMetricsPayload( payload.setProperty(runtime, "eventCount", textInputMetrics.eventCount); - if (name == "selectionChange") { + if (includeSelectionState) { auto selection = jsi::Object(runtime); selection.setProperty( runtime, "start", textInputMetrics.selectionRange.location); @@ -151,7 +153,7 @@ void TextInputEventEmitter::onContentSizeChange( void TextInputEventEmitter::onSelectionChange( const Metrics& textInputMetrics) const { - dispatchTextInputEvent("selectionChange", textInputMetrics); + dispatchTextInputEvent("selectionChange", textInputMetrics, true); } void TextInputEventEmitter::onEndEditing( @@ -179,10 +181,14 @@ void TextInputEventEmitter::onScroll(const Metrics& textInputMetrics) const { void TextInputEventEmitter::dispatchTextInputEvent( const std::string& name, - const Metrics& textInputMetrics) const { - dispatchEvent(name, [name, textInputMetrics](jsi::Runtime& runtime) { - return textInputMetricsPayload(runtime, name, textInputMetrics); - }); + const Metrics& textInputMetrics, + bool includeSelectionState) const { + dispatchEvent( + name, + [name, includeSelectionState, textInputMetrics](jsi::Runtime& runtime) { + return textInputMetricsPayload( + runtime, name, 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, From d4327e69bab1fdf3f4dc2c7cfd7b415cc85bb124 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 11 Jun 2025 10:40:43 +0800 Subject: [PATCH 3/3] remove unused name --- .../components/textinput/TextInputEventEmitter.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 50e6da4f7f76..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,8 +11,6 @@ namespace facebook::react { static jsi::Value textInputMetricsPayload( jsi::Runtime& runtime, - const std::string& name, - const TextInputEventEmitter::Metrics& textInputMetrics, bool includeSelectionState) { auto payload = jsi::Object(runtime); @@ -184,10 +182,9 @@ void TextInputEventEmitter::dispatchTextInputEvent( const Metrics& textInputMetrics, bool includeSelectionState) const { dispatchEvent( - name, - [name, includeSelectionState, textInputMetrics](jsi::Runtime& runtime) { + name, [includeSelectionState, textInputMetrics](jsi::Runtime& runtime) { return textInputMetricsPayload( - runtime, name, textInputMetrics, includeSelectionState); + runtime, textInputMetrics, includeSelectionState); }); }