Jacksgong / JKeyboardPanelSwitch

For resolve the layout conflict when keybord & panel are switching (Android键盘面板冲突 布局闪动处理方案)
Apache License 2.0
4.19k stars 684 forks source link

切换到其它界面再切换回来后,点击按钮,面板不显示 #83

Open lyzyjoyo opened 6 years ago

lyzyjoyo commented 6 years ago

切换到其它界面再切换回来后,点击按钮,面板不显示。 经过排查,发现是KeyboardUtil中的这段代码引起的:

if(!isOverlayLayoutDisplayHContainStatusBar) {
    // in case of the keyboard is hiding, the display height of the
    // action-bar-overlay-layout would be possible equal to the screen height.

    // and if isOverlayLayoutDisplayHContainStatusBar has already been true, the
    // display height of action-bar-overlay-layout must include the height of the
    // status bar always.
    isOverlayLayoutDisplayHContainStatusBar =
            overlayLayoutDisplayHeight == screenHeight;
}

if (!isOverlayLayoutDisplayHContainStatusBar) {
    // In normal case, we need to plus the status bar height manually.
    displayHeight = overlayLayoutDisplayHeight + statusBarHeight;
} else {
    // In some case(such as Samsung S7 edge), the height of the
    // action-bar-overlay-layout display bound already included the height of the
    // status bar, in this case we doesn't need to plus the status bar height
    // manually.
    displayHeight = overlayLayoutDisplayHeight;
}

因为切换到其它界面再切换回来后isOverlayLayoutDisplayHContainStatusBar为true,displayHeight = overlayLayoutDisplayHeight,导致后面的运算:isKeyboardShowing = actionBarOverlayLayoutHeight > displayHeight中的isKeyboardShowing结果为true,表示键盘显示,但是其实键盘没有显示。

而调用面板KPSwitchPanelLinearLayout的setVisibility(View.VISIBLE)方法的时候,调用了KPSwitchPanelLayoutHandler的filterSetVisibility方法,filterSetVisibility方法里面有一段代码:

if (isKeyboardShowing() && visibility == View.VISIBLE) {
    return true;
}

isKeyboardShowing()为true,导致跳过了KPSwitchPanelLinearLayout的super.setVisibility()方法,所以面板不显示。

目前我的解决方法是去掉if(!isOverlayLayoutDisplayHContainStatusBar)这个判断,让每次计算displayHeight前都给isOverlayLayoutDisplayHContainStatusBar重新赋值。 @Jacksgong,您看下有没有更好的解决方法。