Skip to content

Disable onKeyPress logic when handler not defined #18443

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class ReactEditText extends EditText {
private @Nullable ScrollWatcher mScrollWatcher;
private final InternalKeyListener mKeyListener;
private boolean mDetectScrollMovement = false;
private boolean mOnKeyPress = false;
private float mLetterSpacingPt = 0;

private ReactViewBackgroundManager mReactBackgroundManager;
Expand Down Expand Up @@ -175,7 +176,7 @@ protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) {
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
ReactContext reactContext = (ReactContext) getContext();
InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
if (inputConnection != null) {
if (inputConnection != null && mOnKeyPress) {
inputConnection = new ReactEditTextInputConnectionWrapper(inputConnection, reactContext, this);
}

Expand Down Expand Up @@ -274,6 +275,10 @@ public void setBlurOnSubmit(@Nullable Boolean blurOnSubmit) {
mBlurOnSubmit = blurOnSubmit;
}

public void setOnKeyPress(boolean onKeyPress) {
mOnKeyPress = onKeyPress;
}

public boolean getBlurOnSubmit() {
if (mBlurOnSubmit == null) {
// Default blurOnSubmit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ public void setOnScroll(final ReactEditText view, boolean onScroll) {
}
}

@ReactProp(name = "onKeyPress", defaultBoolean = false)
public void setOnKeyPress(final ReactEditText view, boolean onKeyPress) {
view.setOnKeyPress(onKeyPress);
}

// Sets the letter spacing as an absolute point size.
// This extra handling, on top of what ReactBaseTextShadowNode already does, is required for the
// correct display of spacing in placeholder (hint) text.
Expand Down