diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index 8d936feba22..35a2217e9dd 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -54,6 +54,7 @@ using namespace facebook::react; * In multiline text input this is undesirable as we don't want to be sending events for changes that JS triggered. */ BOOL _comingFromJS; + BOOL _didMoveToWindow; } - (instancetype)initWithFrame:(CGRect)frame @@ -67,12 +68,26 @@ using namespace facebook::react; _backedTextInputView.textInputDelegate = self; _ignoreNextTextInputCall = NO; _comingFromJS = NO; + _didMoveToWindow = NO; [self addSubview:_backedTextInputView]; } return self; } +- (void)didMoveToWindow +{ + [super didMoveToWindow]; + + if (self.window && !_didMoveToWindow) { + auto const &props = *std::static_pointer_cast(_props); + if (props.autoFocus) { + [_backedTextInputView becomeFirstResponder]; + } + _didMoveToWindow = YES; + } +} + #pragma mark - RCTComponentViewProtocol + (ComponentDescriptorProvider)componentDescriptorProvider @@ -237,6 +252,7 @@ using namespace facebook::react; _comingFromJS = NO; _lastStringStateWasUpdatedWith = nil; _ignoreNextTextInputCall = NO; + _didMoveToWindow = NO; } #pragma mark - RCTComponentViewProtocol diff --git a/ReactCommon/fabric/components/textinput/iostextinput/TextInputProps.cpp b/ReactCommon/fabric/components/textinput/iostextinput/TextInputProps.cpp index d98ac9d966d..91f4b61817a 100644 --- a/ReactCommon/fabric/components/textinput/iostextinput/TextInputProps.cpp +++ b/ReactCommon/fabric/components/textinput/iostextinput/TextInputProps.cpp @@ -54,7 +54,9 @@ TextInputProps::TextInputProps( rawProps, "mostRecentEventCount", sourceProps.mostRecentEventCount, - {})){}; + {})), + autoFocus( + convertRawProp(rawProps, "autoFocus", sourceProps.autoFocus, {})){}; TextAttributes TextInputProps::getEffectiveTextAttributes() const { auto result = TextAttributes::defaultTextAttributes(); diff --git a/ReactCommon/fabric/components/textinput/iostextinput/TextInputProps.h b/ReactCommon/fabric/components/textinput/iostextinput/TextInputProps.h index fa8d1365c42..440dbd9f10a 100644 --- a/ReactCommon/fabric/components/textinput/iostextinput/TextInputProps.h +++ b/ReactCommon/fabric/components/textinput/iostextinput/TextInputProps.h @@ -53,6 +53,8 @@ class TextInputProps final : public ViewProps, public BaseTextProps { std::string const text{}; int const mostRecentEventCount{0}; + bool autoFocus{false}; + /* * Accessors */