From 1118cc63273608430b254d4f5347b0b41674ceaa Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Tue, 1 Oct 2024 12:35:16 -0700 Subject: [PATCH] Share TextInputEventEmitter between C++ platforms (#46198) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46198 Extending on https://github.com/facebook/react-native/pull/43431 this change allows to share the TextInputEventEmitter with our C++ based platforms such as RN Windows > https://github.com/microsoft/react-native-windows/blob/main/vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputEventEmitter.h ## Changelog: [Internal] - Share TextInputEventEmitter between C++ platforms Reviewed By: NickGerleman Differential Revision: D61749959 fbshipit-source-id: 2526bf29200cd6a3dc6d5eaef5edbaf4b1df5751 --- .../react-native/ReactCommon/React-FabricComponents.podspec | 3 ++- .../components/iostextinput => }/TextInputEventEmitter.cpp | 4 +++- .../components/iostextinput => }/TextInputEventEmitter.h | 1 + .../renderer/components/iostextinput/TextInputShadowNode.h | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) rename packages/react-native/ReactCommon/react/renderer/components/textinput/{platform/ios/react/renderer/components/iostextinput => }/TextInputEventEmitter.cpp (97%) rename packages/react-native/ReactCommon/react/renderer/components/textinput/{platform/ios/react/renderer/components/iostextinput => }/TextInputEventEmitter.h (99%) diff --git a/packages/react-native/ReactCommon/React-FabricComponents.podspec b/packages/react-native/ReactCommon/React-FabricComponents.podspec index f108ac15c26..0681668f1e6 100644 --- a/packages/react-native/ReactCommon/React-FabricComponents.podspec +++ b/packages/react-native/ReactCommon/React-FabricComponents.podspec @@ -153,7 +153,8 @@ Pod::Spec.new do |s| ss.subspec "iostextinput" do |sss| sss.dependency folly_dep_name, folly_version sss.compiler_flags = folly_compiler_flags - sss.source_files = "react/renderer/components/textinput/platform/ios/**/*.{m,mm,cpp,h}" + sss.source_files = "react/renderer/components/textinput/**/*.{m,mm,cpp,h}" + sss.exclude_files = "react/renderer/components/textinput/platform/android" sss.header_dir = "react/renderer/components/iostextinput" end diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputEventEmitter.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp similarity index 97% rename from packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputEventEmitter.cpp rename to packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp index 6eb58c1681a..1d130feebb5 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputEventEmitter.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp @@ -19,6 +19,8 @@ static jsi::Value textInputMetricsPayload( "text", jsi::String::createFromUtf8(runtime, textInputMetrics.text)); + payload.setProperty(runtime, "target", textInputMetrics.target); + payload.setProperty(runtime, "eventCount", textInputMetrics.eventCount); { @@ -81,7 +83,7 @@ static jsi::Value textInputMetricsScrollPayload( payload.setProperty( runtime, "zoomScale", - textInputMetrics.zoomScale ? textInputMetrics.zoomScale : 1); + textInputMetrics.zoomScale != 0.0f ? textInputMetrics.zoomScale : 1); return payload; }; diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputEventEmitter.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h similarity index 99% rename from packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputEventEmitter.h rename to packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h index 9182dd3d2ed..dae4755e796 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputEventEmitter.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h @@ -27,6 +27,7 @@ class TextInputEventEmitter : public ViewEventEmitter { int eventCount; Size layoutMeasurement; Float zoomScale; + Tag target; }; struct KeyPressMetrics { diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputShadowNode.h index f553ea284ea..eef1e3321ab 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputShadowNode.h @@ -8,10 +8,10 @@ #pragma once #include -#include #include #include #include +#include #include #include #include