Implement autoFocus in TextInput

Summary:
Changelog: [Internal]

Prop autoFocus was not implemented in Fabric's TextInput.

Reviewed By: mdvacca

Differential Revision: D22019333

fbshipit-source-id: 03f043b93e1079a5d0bff55b08ebc9d2f973c55b
This commit is contained in:
Samuel Susla
2020-06-13 11:04:40 -07:00
committed by Facebook GitHub Bot
parent 078e386024
commit ccf5c86bd7
3 changed files with 21 additions and 1 deletions
@@ -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<TextInputProps const>(_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
@@ -54,7 +54,9 @@ TextInputProps::TextInputProps(
rawProps,
"mostRecentEventCount",
sourceProps.mostRecentEventCount,
{})){};
{})),
autoFocus(
convertRawProp(rawProps, "autoFocus", sourceProps.autoFocus, {})){};
TextAttributes TextInputProps::getEffectiveTextAttributes() const {
auto result = TextAttributes::defaultTextAttributes();
@@ -53,6 +53,8 @@ class TextInputProps final : public ViewProps, public BaseTextProps {
std::string const text{};
int const mostRecentEventCount{0};
bool autoFocus{false};
/*
* Accessors
*/