mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Implement native TextInput autoFocus on Android (#27924)
Summary: Follow up to https://github.com/facebook/react-native/issues/27803. To keep consistency between the implementations this also implements autoFocus natively on Android. This will allow removing the JS auto focus logic completely. ## Changelog [Android] [Fixed] - Implement native TextInput autoFocus on Android Pull Request resolved: https://github.com/facebook/react-native/pull/27924 Test Plan: Test using the TextInput example in RN tester. Differential Revision: D19674506 Pulled By: TheSavior fbshipit-source-id: 9cbb517fc69bccd11f5292a1ccb4acea2e3713e9
This commit is contained in:
committed by
Facebook Github Bot
parent
e4194a20a7
commit
055a41b081
@@ -100,6 +100,8 @@ public class ReactEditText extends AppCompatEditText {
|
||||
private @Nullable String mFontFamily = null;
|
||||
private int mFontWeight = ReactTypefaceUtils.UNSET;
|
||||
private int mFontStyle = ReactTypefaceUtils.UNSET;
|
||||
private boolean mAutoFocus = false;
|
||||
private boolean mDidAttachToWindow = false;
|
||||
|
||||
private ReactViewBackgroundManager mReactBackgroundManager;
|
||||
|
||||
@@ -750,6 +752,14 @@ public class ReactEditText extends AppCompatEditText {
|
||||
span.onAttachedToWindow();
|
||||
}
|
||||
}
|
||||
|
||||
if (mAutoFocus && !mDidAttachToWindow) {
|
||||
mShouldAllowFocus = true;
|
||||
requestFocus();
|
||||
mShouldAllowFocus = false;
|
||||
}
|
||||
|
||||
mDidAttachToWindow = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -813,6 +823,10 @@ public class ReactEditText extends AppCompatEditText {
|
||||
}
|
||||
}
|
||||
|
||||
public void setAutoFocus(boolean autoFocus) {
|
||||
mAutoFocus = autoFocus;
|
||||
}
|
||||
|
||||
protected void applyTextAttributes() {
|
||||
// In general, the `getEffective*` functions return `Float.NaN` if the
|
||||
// property hasn't been set.
|
||||
|
||||
+5
@@ -795,6 +795,11 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
view.setShowSoftInputOnFocus(showKeyboardOnFocus);
|
||||
}
|
||||
|
||||
@ReactProp(name = "autoFocus", defaultBoolean = false)
|
||||
public void setAutoFocus(ReactEditText view, boolean autoFocus) {
|
||||
view.setAutoFocus(autoFocus);
|
||||
}
|
||||
|
||||
@ReactPropGroup(
|
||||
names = {
|
||||
ViewProps.BORDER_WIDTH,
|
||||
|
||||
Reference in New Issue
Block a user