Skip to content
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 numberDiff line numberDiff line change
Expand Up@@ -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;

Expand DownExpand Up@@ -750,6 +752,14 @@ public void onAttachedToWindow() {
span.onAttachedToWindow();
}
}

if (mAutoFocus && !mDidAttachToWindow) {
mShouldAllowFocus = true;
requestFocus();
mShouldAllowFocus = false;
}

mDidAttachToWindow = true;
}

@Override
Expand DownExpand Up@@ -813,6 +823,10 @@ public void setMaxFontSizeMultiplier(float maxFontSizeMultiplier) {
}
}

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.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -795,6 +795,11 @@ public void showKeyboardOnFocus(ReactEditText view, boolean showKeyboardOnFocus)
view.setShowSoftInputOnFocus(showKeyboardOnFocus);
}

@ReactProp(name = "autoFocus", defaultBoolean = false)
public void setAutoFocus(ReactEditText view, boolean autoFocus) {
view.setAutoFocus(autoFocus);
}

@ReactPropGroup(
names = {
ViewProps.BORDER_WIDTH,
Expand Down