Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
  • Loading branch information
bofeng-song committed Nov 2, 2023
1 parent d96debc commit dc83bb2
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ private void removeListeners() {
this.removeTextChangedListener(mTextWatcher);
}

private boolean isScrollBySystem(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,14 +232,9 @@ public void onGlobalLayout() {
if (!keyboardVisible) {
keyboardVisible = true;
}
int bottomOffset = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
bottomOffset = getWindow().getDecorView().getRootWindowInsets().getSystemWindowInsetBottom();
}
if (Math.abs(heightDiff - bottomOffset) < 10) {
heightDiff = 0;// view will be scrolled to the target position by system
if (!isScrollBySystem(heightDiff)) {
getRootView().scrollTo(0, heightDiff);
}
getRootView().scrollTo(0, heightDiff);
} else {
getRootView().scrollTo(0, 0);
if (mCheckKeyboardShowNormally && !keyboardVisible) {
Expand Down

0 comments on commit dc83bb2

Please sign in to comment.