Skip to content

Commit

Permalink
#0 Dialog 场景支持Android 11 键盘动画效果
Browse files Browse the repository at this point in the history
  • Loading branch information
linzheng committed Aug 30, 2022
1 parent 99cefdc commit 530609d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Toast;

import androidx.core.content.ContextCompat;
Expand All @@ -17,6 +18,7 @@
import com.effective.R;
import com.effective.android.panel.PanelSwitchHelper;
import com.effective.android.panel.interfaces.listener.OnPanelChangeListener;
import com.effective.android.panel.utils.KeyboardExtKt;
import com.effective.android.panel.view.panel.IPanelView;
import com.effective.android.panel.view.panel.PanelView;
import com.effective.android.panel.window.PanelDialog;
Expand Down Expand Up @@ -58,7 +60,10 @@ public ChatDialog(Activity context) {
@Override
public void show() {
if (mHelper == null) {
mHelper = new PanelSwitchHelper.Builder(activity.getWindow(), mBinding.getRoot())
Window window = getWindow();
boolean support = KeyboardExtKt.isSystemInsetsAnimationSupport(window);
Window bindWindow = support ? window : activity.getWindow();
mHelper = new PanelSwitchHelper.Builder(bindWindow, mBinding.getRoot())
//可选
.addKeyboardStateListener((visible, height) -> Log.d(TAG, "系统键盘是否可见 : " + visible + " 高度为:" + height))
//可选
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package com.effective.android.panel.utils
import android.app.Activity
import android.content.Context
import android.view.View
import android.view.Window
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.core.view.ViewCompat
Expand Down Expand Up @@ -86,4 +87,9 @@ internal fun View.isSystemInsetsAnimationSupport(): Boolean {
return !(windowInsetsController == null || windowInsetsController.systemBarsBehavior == 0)
}

fun Window.isSystemInsetsAnimationSupport() : Boolean {
return this.decorView.isSystemInsetsAnimationSupport()
}



Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,17 @@ class PanelSwitchLayout : LinearLayout, ViewAssertion {
transitionY = offset
}
} else if (!hasSoftInput) {
val offset = min(transitionY - transitionY * (fraction + 0.5f), 0f)
if (offset >= 0) {
// 有些设备隐藏键盘时,softInputHeight的值一直等于0,此时用 fraction 来计算偏移量
if (softInputHeight > 0) {
val offset = min(softInputTop - floatInitialBottom, 0).toFloat()
panelContainer.translationY = offset
contentContainer.translationContainer(contentScrollMeasurers, lastKeyboardHeight, offset)
logFormatter.addContent("translationY", "$offset")
} else {
logFormatter.addContent("translationY", "$offset , skip")
val offset = min(transitionY - transitionY * (fraction + 0.5f), 0f)
panelContainer.translationY = offset
contentContainer.translationContainer(contentScrollMeasurers, lastKeyboardHeight, offset)
logFormatter.addContent("translationY", "$offset")
}
}
logFormatter.log("onProgress")
Expand All @@ -400,7 +404,7 @@ class PanelSwitchLayout : LinearLayout, ViewAssertion {
* 是否支持键盘过渡动画
*/
private fun supportKeyboardAnimation(): Boolean {
return window.decorView.isSystemInsetsAnimationSupport()
return isSystemInsetsAnimationSupport()
}


Expand Down

0 comments on commit 530609d

Please sign in to comment.