From a9f685079a8ef03b05da81ac8cedd2fb648de802 Mon Sep 17 00:00:00 2001 From: Martyna Wieczorek Date: Thu, 15 Jul 2021 16:53:42 +0100 Subject: [PATCH] Restart input if imeOptions are changed in TextInputSpec --- .../litho/widget/MaterialTextInputSpec.java | 1 + .../facebook/litho/widget/TextInputSpec.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/litho-widget-material/src/main/java/com/facebook/litho/widget/MaterialTextInputSpec.java b/litho-widget-material/src/main/java/com/facebook/litho/widget/MaterialTextInputSpec.java index f2f8a0b3670..9ac6eb00144 100644 --- a/litho-widget-material/src/main/java/com/facebook/litho/widget/MaterialTextInputSpec.java +++ b/litho-widget-material/src/main/java/com/facebook/litho/widget/MaterialTextInputSpec.java @@ -362,6 +362,7 @@ static void onMount( mountedEditTextRef.set(editText); TextInputSpec.setParams( + c, editText, null, TextInputSpec.getBackgroundOrDefault(c, inputBackground), diff --git a/litho-widget/src/main/java/com/facebook/litho/widget/TextInputSpec.java b/litho-widget/src/main/java/com/facebook/litho/widget/TextInputSpec.java index b1fbd883fa8..423d398b66e 100644 --- a/litho-widget/src/main/java/com/facebook/litho/widget/TextInputSpec.java +++ b/litho-widget/src/main/java/com/facebook/litho/widget/TextInputSpec.java @@ -370,6 +370,7 @@ static EditText createAndMeasureEditText( text = text.toString(); } setParams( + c, forMeasure, hint, getBackgroundOrDefault( @@ -406,6 +407,7 @@ static EditText createAndMeasureEditText( } static void setParams( + ComponentContext c, EditText editText, @Nullable CharSequence hint, @Nullable Drawable background, @@ -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); @@ -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 @@ -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 initialText, @@ -770,6 +784,7 @@ static void onMount( mountedView.set(editText); setParams( + c, editText, hint, getBackgroundOrDefault(c, inputBackground),