Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Implement missing showSoftInputOnFocus prop on TextInput on the new arch #35878

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
[self _setMultiline:newTextInputProps.traits.multiline];
}

if (newTextInputProps.traits.showSoftInputOnFocus != oldTextInputProps.traits.showSoftInputOnFocus) {
[self _setShowSoftInputOnFocus:newTextInputProps.traits.showSoftInputOnFocus];
}

if (newTextInputProps.traits.autocapitalizationType != oldTextInputProps.traits.autocapitalizationType) {
_backedTextInputView.autocapitalizationType =
RCTUITextAutocapitalizationTypeFromAutocapitalizationType(newTextInputProps.traits.autocapitalizationType);
Expand Down Expand Up @@ -617,6 +621,26 @@ - (void)_setMultiline:(BOOL)multiline
RCTCopyBackedTextInput(_backedTextInputView, backedTextInputView);
_backedTextInputView = backedTextInputView;
[self addSubview:_backedTextInputView];

auto const &currentTextInputProps = *std::static_pointer_cast<TextInputProps const>(_props);
[self _setShowSoftInputOnFocus:currentTextInputProps.traits.showSoftInputOnFocus];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we couple this logic with multiline? regardless, the initial props should go through the updateProps:oldProps pipeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply, I must've missed the notification 😅. It's there because setting multiline causes the creation of a new underlying component (either RCTUITextView or RCTUITextField) and we need to apply the showSoftInputOnFocus prop again to the newly created view. Otherwise, it will be reset every time the multiline is set.

}

- (void)_setShowSoftInputOnFocus:(BOOL)showSoftInputOnFocus
{
if (showSoftInputOnFocus) {
// Resets to default keyboard.
_backedTextInputView.inputView = nil;

// Without the call to reloadInputViews, the keyboard will not change until the textInput field (the first
// responder) loses and regains focus.
if (_backedTextInputView.isFirstResponder) {
[_backedTextInputView reloadInputViews];
}
} else {
// Hides keyboard, but keeps blinking cursor.
_backedTextInputView.inputView = [UIView new];
}
}

- (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ TextInputProps::TextInputProps(
"maxLength",
sourceProps.maxLength,
{})),
showSoftInputOnFocus(convertRawProp(
context,
rawProps,
"showSoftInputOnFocus",
sourceProps.showSoftInputOnFocus,
{})),
cursorColor(convertRawProp(
context,
rawProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class TextInputProps final : public ViewProps, public BaseTextProps {

int maxLength{};

bool showSoftInputOnFocus{true};

/*
* Tint colors
*/
Expand Down