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

Added a minimal delay to call setSelection() to enforce special focus handling cases #765

Merged
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 @@ -30,16 +30,25 @@ public void onTakeFocus(TextView view, Spannable text, int dir) {
if ((dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0) {
if (view.getLayout() == null) {
// This shouldn't be null, but do something sensible if it is.
Selection.setSelection(text, 0); // <-- setting caret to start of text
handleSelectionOnEnd(view, text);
}
else if (!reactAztecText.isTouched()) {
Selection.setSelection(text, text.length()); // <-- setting caret to end of text after two blocks are merged
handleSelectionOnEnd(view, text); // <-- setting caret to end of text after two blocks are merged
}
} else {
Selection.setSelection(text, text.length()); // <-- same as original Android implementation. Not sure if we should change this too
}
}

private void handleSelectionOnEnd(TextView view, final Spannable text) {
view.postDelayed(new Runnable() {
@Override
public void run() {
Selection.setSelection(text, text.length()); // <-- setting caret to end of text
}
}, 20);
}

@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
((ReactAztecText)widget).setTouched(true);
Expand Down