Skip to content

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

@iielse

Description

@iielse

当上个页面有输入框 使用过输入法时,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的下半部分区域一片空白。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions