Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug input区域空白 && 键盘无法升起 #70

Open
iielse opened this issue Mar 14, 2019 · 2 comments
Open

bug input区域空白 && 键盘无法升起 #70

iielse opened this issue Mar 14, 2019 · 2 comments

Comments

@iielse
Copy link

iielse commented Mar 14, 2019

当上个页面有输入框 使用过输入法时,xhsEmoticonsKeyboard 初始化可能会发生错误。

例子 ActivityA(普通的inputView) 开启-> ActivityB(xhsEmoticonsKeyboard)
在部分手机比如锤子(默认输入法是讯飞输入法)等,在ActivityB启动后,键盘还没收起。

此时XhsEmoticonsKeyboard在父类 SoftKeyboardSizeWatchLayout 中通过 getWindow().getDecorView().getWindowVisibleDisplayFrame(r) 计算出来的 Rect 区域仅仅是除开输入法之后的区域。 所以这里screenHeight的赋值出现了错误。
比如屏幕高度2000,输入法高度500。 rect.bottom取出得值为1500

public SoftKeyboardSizeWatchLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.mContext = context;
    this.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
      public void onGlobalLayout() {
        Rect r = new Rect();
        ((Activity)SoftKeyboardSizeWatchLayout.this.mContext).getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
        if (SoftKeyboardSizeWatchLayout.this.mScreenHeight == 0) {
          SoftKeyboardSizeWatchLayout.this.mScreenHeight = r.bottom;
        }

        SoftKeyboardSizeWatchLayout.this.mNowh = SoftKeyboardSizeWatchLayout.this.mScreenHeight - r.bottom;
        if (SoftKeyboardSizeWatchLayout.this.mOldh != -1 && SoftKeyboardSizeWatchLayout.this.mNowh != SoftKeyboardSizeWatchLayout.this.mOldh) {
          Iterator i$;
          SoftKeyboardSizeWatchLayout.OnResizeListener l;
          if (SoftKeyboardSizeWatchLayout.this.mNowh > 0) {
            SoftKeyboardSizeWatchLayout.this.mIsSoftKeyboardPop = true;
            if (SoftKeyboardSizeWatchLayout.this.mListenerList != null) {
              i$ = SoftKeyboardSizeWatchLayout.this.mListenerList.iterator();

              while(i$.hasNext()) {
                l = (SoftKeyboardSizeWatchLayout.OnResizeListener)i$.next();
                l.OnSoftPop(SoftKeyboardSizeWatchLayout.this.mNowh);
              }
            }
          } else {
            SoftKeyboardSizeWatchLayout.this.mIsSoftKeyboardPop = false;
            if (SoftKeyboardSizeWatchLayout.this.mListenerList != null) {
              i$ = SoftKeyboardSizeWatchLayout.this.mListenerList.iterator();

              while(i$.hasNext()) {
                l = (SoftKeyboardSizeWatchLayout.OnResizeListener)i$.next();
                l.OnSoftClose();
              }
            }
          }
        }

        SoftKeyboardSizeWatchLayout.this.mOldh = SoftKeyboardSizeWatchLayout.this.mNowh;
      }
    });
  }

因此在之后逻辑的对比计算中,点击输入框升起键盘 mNowh的值结果为0。代码判定为 “布局变动后的区域并没有缩小”,走了 onSoftClose分支触发resetEmoticonsKeyboardUtils.closeSoftKeyboard(this) 被调用。

表现为 点击输入框 输入法升起,再立马下降。

=================

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int expandSpec;
    if (this.mConfigurationChangedFlag) {
      this.mConfigurationChangedFlag = false;
      Rect r = new Rect();
      ((Activity)this.mContext).getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
      if (this.mScreenHeight == 0) {
        this.mScreenHeight = r.bottom;
      }

      expandSpec = this.mScreenHeight - r.bottom;
      this.mMaxParentHeight = expandSpec;
    }

    if (this.mMaxParentHeight != 0) {
      int heightMode = MeasureSpec.getMode(heightMeasureSpec);
      expandSpec = MeasureSpec.makeMeasureSpec(this.mMaxParentHeight, heightMode);
      super.onMeasure(widthMeasureSpec, expandSpec);
    } else {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
  }

这里的mMaxParentHeight的初始化存在同样的问题。 会使XhsEmoticonsKeyboard的下半部分区域一片空白。

@arvinljw
Copy link

arvinljw commented Dec 4, 2019

在mNowh<0时,加一段判断:(因为mNowh正常的话,最小值就是0)
if (mNowh < 0) { mNowh = 0; mScreenHeight = 0; }
然后子类在横竖屏切换时隐藏所有内容,同时funcLayout的高度可以自己手动调整。

@weilange
Copy link

weilange commented Jan 3, 2021

问题最后怎么解决的呢,请教一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants