diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index 5aa7024c974..156a913c435 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -245,6 +245,11 @@ using namespace facebook::react; UIEdgeInsetsInsetRect(self.bounds, RCTUIEdgeInsetsFromEdgeInsets(layoutMetrics.borderWidth)); _backedTextInputView.textContainerInset = RCTUIEdgeInsetsFromEdgeInsets(layoutMetrics.contentInsets - layoutMetrics.borderWidth); + + if (_eventEmitter) { + auto const &textInputEventEmitter = *std::static_pointer_cast(_eventEmitter); + textInputEventEmitter.onContentSizeChange([self _textInputMetrics]); + } } - (void)prepareForRecycle diff --git a/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputEventEmitter.cpp b/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputEventEmitter.cpp index 494ab15d396..24a58027693 100644 --- a/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputEventEmitter.cpp +++ b/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputEventEmitter.cpp @@ -36,6 +36,23 @@ static jsi::Value textInputMetricsPayload( return payload; }; +static jsi::Value textInputMetricsContentSizePayload( + jsi::Runtime &runtime, + TextInputMetrics const &textInputMetrics) { + auto payload = jsi::Object(runtime); + + { + auto contentSize = jsi::Object(runtime); + contentSize.setProperty( + runtime, "width", textInputMetrics.contentSize.width); + contentSize.setProperty( + runtime, "height", textInputMetrics.contentSize.height); + payload.setProperty(runtime, "contentSize", contentSize); + } + + return payload; +}; + static jsi::Value keyPressMetricsPayload( jsi::Runtime &runtime, KeyPressMetrics const &keyPressMetrics) { @@ -82,7 +99,8 @@ void TextInputEventEmitter::onChangeSync( void TextInputEventEmitter::onContentSizeChange( TextInputMetrics const &textInputMetrics) const { - dispatchTextInputEvent("contentSizeChange", textInputMetrics); + dispatchTextInputContentSizeChangeEvent( + "contentSizeChange", textInputMetrics); } void TextInputEventEmitter::onSelectionChange( @@ -137,4 +155,16 @@ void TextInputEventEmitter::dispatchTextInputEvent( priority); } +void TextInputEventEmitter::dispatchTextInputContentSizeChangeEvent( + std::string const &name, + TextInputMetrics const &textInputMetrics, + EventPriority priority) const { + dispatchEvent( + name, + [textInputMetrics](jsi::Runtime &runtime) { + return textInputMetricsContentSizePayload(runtime, textInputMetrics); + }, + priority); +} + } // namespace facebook::react diff --git a/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputEventEmitter.h b/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputEventEmitter.h index 3dc1cefaff5..2e7e2f79ea9 100644 --- a/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputEventEmitter.h +++ b/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputEventEmitter.h @@ -54,6 +54,11 @@ class TextInputEventEmitter : public ViewEventEmitter { std::string const &name, TextInputMetrics const &textInputMetrics, EventPriority priority = EventPriority::AsynchronousBatched) const; + + void dispatchTextInputContentSizeChangeEvent( + std::string const &name, + TextInputMetrics const &textInputMetrics, + EventPriority priority = EventPriority::AsynchronousBatched) const; }; } // namespace react