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

Restart input if imeOptions are changed in TextInputSpec #876

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -362,6 +362,7 @@ static void onMount(
mountedEditTextRef.set(editText);

TextInputSpec.setParams(
c,
editText,
null,
TextInputSpec.getBackgroundOrDefault(c, inputBackground),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ static EditText createAndMeasureEditText(
text = text.toString();
}
setParams(
c,
forMeasure,
hint,
getBackgroundOrDefault(
Expand Down Expand Up @@ -406,6 +407,7 @@ static EditText createAndMeasureEditText(
}

static void setParams(
ComponentContext c,
EditText editText,
@Nullable CharSequence hint,
@Nullable Drawable background,
Expand Down Expand Up @@ -479,7 +481,6 @@ static void setParams(
editText.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
editText.setTypeface(typeface, 0);
editText.setGravity(gravity);
editText.setImeOptions(imeOptions);
editText.setFocusable(editable);
editText.setFocusableInTouchMode(editable);
editText.setLongClickable(editable);
Expand All @@ -490,6 +491,7 @@ static void setParams(
editText.setHighlightColor(highlightColor);
}
editText.setMovementMethod(movementMethod);
setImeOptionsAndRestartInputIfChanged(c, editText, editText.getImeOptions(), imeOptions);

/**
* Sets error state on the TextInput, which shows an error icon provided by errorDrawable and an
Expand Down Expand Up @@ -546,6 +548,18 @@ private static void setInputTypeAndKeyListenerIfChanged(
}
}

// If imeOptions are changed when the keyboard is visible, restartInput needs to be called for
// this change to be reflected.
private static void setImeOptionsAndRestartInputIfChanged(
ComponentContext c, EditText editText, int oldImeOptions, int newImeOptions) {
editText.setImeOptions(newImeOptions);
if (oldImeOptions != newImeOptions) {
InputMethodManager imm =
(InputMethodManager) c.getAndroidContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(editText);
}
}

@ShouldUpdate
static boolean shouldUpdate(
@Prop(optional = true, resType = ResType.STRING) Diff<CharSequence> initialText,
Expand Down Expand Up @@ -770,6 +784,7 @@ static void onMount(
mountedView.set(editText);

setParams(
c,
editText,
hint,
getBackgroundOrDefault(c, inputBackground),
Expand Down