goweii / AnyLayer

Android稳定高效的浮层创建管理框架
https://github.com/goweii/AnyLayer
Apache License 2.0
993 stars 114 forks source link

全局复用Layer会有问题 #32

Closed HarveyLee1228 closed 3 years ago

HarveyLee1228 commented 3 years ago

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

goweii commented 3 years ago

/**

HarveyLee1228 commented 3 years ago

/**

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

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

HarveyLee1228 commented 3 years ago
/**
 * 添加到父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才会继续监听返回键。

goweii commented 3 years ago

OK,抽空看看

goweii commented 3 years ago
/**
 * 添加到父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版本