goweii / AnyLayer

Android稳定高效的浮层创建管理框架

Home Page:https://github.com/goweii/AnyLayer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

全局复用Layer会有问题

HarveyLee1228 opened this issue · comments

compatSoftInput处理有点问题,在remove时没有将softInputHelper置空。或者在重新调用compatSoftInput时应该重新attach,不然复用dialog会有问题

/**
* 适配软键盘的弹出,布局自动上移
* 在某几个EditText获取焦点时布局上移
* 在{@link OnVisibleChangeListener#onShow(Layer)}中调用
* 应该和{@link #removeSoftInput()}成对出现
*
* @param editTexts 焦点EditTexts
*/

/**

  • 适配软键盘的弹出,布局自动上移
  • 在某几个EditText获取焦点时布局上移
  • 在{@link OnVisibleChangeListener#onShow(Layer)}中调用
  • 应该和{@link #removeSoftInput()}成对出现
  • @param editTexts 焦点EditTexts
    */

我的意思是当我复用dialogLayer时,我如果在OnVisibleChangeListener监听中removeSoftInput,再次show时就不会适配键盘了。同时还存在我复用dialogLayer时,返回键的监听也不起作用了。

/**
 * 添加到父View
 */
private void onAttach() {
    if (mOnKeyListener != null) {
        mChild.setFocusable(true);
        mChild.setFocusableInTouchMode(true);
        mChild.requestFocus();
        currentKeyView = mChild;
        mLayerGlobalFocusChangeListener = new LayerGlobalFocusChangeListener();
        mChild.getViewTreeObserver().addOnGlobalFocusChangeListener(mLayerGlobalFocusChangeListener);
        mLayerKeyListener = new LayerKeyListener();
        currentKeyView.setOnKeyListener(mLayerKeyListener);
    }
    mParent.addView(mChild);
    if (mOnLifeListener != null) {
        mOnLifeListener.onAttach();
    }
}

这段代码的这三句:
mChild.setFocusable(true);
mChild.setFocusableInTouchMode(true);
mChild.requestFocus();
应该放到
mLayerGlobalFocusChangeListener = new LayerGlobalFocusChangeListener();
mChild.getViewTreeObserver().addOnGlobalFocusChangeListener(mLayerGlobalFocusChangeListener);
这两句的后面,复用的layer才会继续监听返回键。

OK,抽空看看

/**
 * 添加到父View
 */
private void onAttach() {
    if (mOnKeyListener != null) {
        mChild.setFocusable(true);
        mChild.setFocusableInTouchMode(true);
        mChild.requestFocus();
        currentKeyView = mChild;
        mLayerGlobalFocusChangeListener = new LayerGlobalFocusChangeListener();
        mChild.getViewTreeObserver().addOnGlobalFocusChangeListener(mLayerGlobalFocusChangeListener);
        mLayerKeyListener = new LayerKeyListener();
        currentKeyView.setOnKeyListener(mLayerKeyListener);
    }
    mParent.addView(mChild);
    if (mOnLifeListener != null) {
        mOnLifeListener.onAttach();
    }
}

这段代码的这三句:
mChild.setFocusable(true);
mChild.setFocusableInTouchMode(true);
mChild.requestFocus();
应该放到
mLayerGlobalFocusChangeListener = new LayerGlobalFocusChangeListener();
mChild.getViewTreeObserver().addOnGlobalFocusChangeListener(mLayerGlobalFocusChangeListener);
这两句的后面,复用的layer才会继续监听返回键。

已修复,更新4.1.1版本