Skip to content

Commit f6ca4d0

Browse files
jainkuniyagrabbou
authored andcommittedMar 12, 2019
Add prop to configure importantForAutofill. (#22763)
Summary: In API 26, autofill framework was introduced in Android. Read more about Autofill at https://developer.android.com/guide/topics/text/autofill. Now, if in case for some text input if developer wants to disable autofill then he can take help from this `importantForAutoFill` prop and pass `no` to it. Also important of auto fill can be configured with this prop, like: * `auto`: Let the Android System use its heuristics to determine if the view is important for autofill. * `no`: This view isn't important for autofill. * `noExcludeDescendants`: This view and its children aren't important for autofill. * `yes`: This view is important for autofill. * `yesExcludeDescendants`: This view is important for autofill, but its children aren't important for autofill. Default value if `auto`. Read more at: https://developer.android.com/guide/topics/text/autofill-optimize Changelog: ---------- [Android] [Added] - Add prop to configure `importantForAutofill` in `TextInput`. Pull Request resolved: #22763 Differential Revision: D14121242 Pulled By: cpojer fbshipit-source-id: aa4360480dd19f6dde66f0409d26a41a6a318c94
1 parent ffa6d29 commit f6ca4d0

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎Libraries/Components/TextInput/TextInput.js

+7
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ type AndroidProps = $ReadOnly<{|
245245
underlineColorAndroid?: ?ColorValue,
246246
inlineImageLeft?: ?string,
247247
inlineImagePadding?: ?number,
248+
importantForAutofill?: ?(
249+
| 'auto'
250+
| 'no'
251+
| 'noExcludeDescendants'
252+
| 'yes'
253+
| 'yesExcludeDescendants'
254+
),
248255
|}>;
249256

250257
type Props = $ReadOnly<{|

‎ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

+19
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.graphics.PorterDuff;
1111
import android.graphics.Typeface;
1212
import android.graphics.drawable.Drawable;
13+
import android.os.Build;
1314
import android.support.v4.content.ContextCompat;
1415
import android.text.Editable;
1516
import android.text.InputFilter;
@@ -280,6 +281,24 @@ public void setSelection(ReactEditText view, @Nullable ReadableMap selection) {
280281
}
281282
}
282283

284+
@ReactProp(name = "importantForAutofill")
285+
public void setImportantForAutofill(ReactEditText view, @Nullable String value) {
286+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
287+
return;
288+
}
289+
int mode = View.IMPORTANT_FOR_AUTOFILL_AUTO;
290+
if ("no".equals(value)) {
291+
mode = View.IMPORTANT_FOR_AUTOFILL_NO;
292+
} else if ("noExcludeDescendants".equals(value)) {
293+
mode = View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS;
294+
} else if ("yes".equals(value)) {
295+
mode = View.IMPORTANT_FOR_AUTOFILL_YES;
296+
} else if ("yesExcludeDescendants".equals(value)) {
297+
mode = View.IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS;
298+
}
299+
view.setImportantForAutofill(mode);
300+
}
301+
283302
@ReactProp(name = "onSelectionChange", defaultBoolean = false)
284303
public void setOnSelectionChange(final ReactEditText view, boolean onSelectionChange) {
285304
if (onSelectionChange) {

0 commit comments

Comments
 (0)
Please sign in to comment.