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

Fix the problem that the editbox shifts too far away when the keyboard pops up #16461

Merged
merged 3 commits into from
Nov 8, 2023
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 @@ -208,6 +208,18 @@ private void removeListeners() {
this.removeTextChangedListener(mTextWatcher);
}

private boolean isSystemAdjustUIWhenPopKeyboard(int bottom) {
int bottomOffset = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
bottomOffset = getWindow().getDecorView().getRootWindowInsets().getSystemWindowInsetBottom();
}
// view will be scrolled to the target position by system,
if (Math.abs(bottom - bottomOffset) < 10) {
return true;
}
return false;
}

private void registKeyboardVisible() {
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
Expand All @@ -220,7 +232,9 @@ public void onGlobalLayout() {
if (!keyboardVisible) {
keyboardVisible = true;
}
getRootView().scrollTo(0, heightDiff);
if (!isSystemAdjustUIWhenPopKeyboard(heightDiff)) {
getRootView().scrollTo(0, heightDiff);
}
} else {
getRootView().scrollTo(0, 0);
if (mCheckKeyboardShowNormally && !keyboardVisible) {
Expand Down
Loading