Jacksgong / JKeyboardPanelSwitch

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

关于全屏适配,在应用安全的第一次进入会有闪的问题 #20

Open w446108264 opened 8 years ago

w446108264 commented 8 years ago

我们之前讨论过这个问题哈,然后我发现我也遇到了这个问题,我看到JKeyboardPanelSwitch是如下解决的,本质是通过提前改变焦点位置,使其高于软键盘避免界面顶起。

 if (ViewUtil.isFullScreen(activity)) {
            focusView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        /**
                         * Show the fake empty keyboard-same-height panel to fix the conflict when
                         * keyboard going to show.
                         * @see KPSwitchConflictUtil#showKeyboard(View, View)
                         */
                        panelLayout.setVisibility(View.INVISIBLE);
                    }
                    return false;
                }
            });
        }

实质demo中即可发现存在2个问题。 1首次高度无法获取,2动态调整软件高度时,当软键盘高度增大,高于当前焦点view时,是无法促发上面的代码的,另外如录音之类的按钮假如要变低应该也同样存在该问题。

我是如下解决的,有点粗暴,暂未发现不足,哈哈希望对你有帮助

@Override
    public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
        if (EmoticonsKeyboardUtils.isFullScreen((Activity) getContext())) {
            return false;
        }
        return super.requestFocus(direction, previouslyFocusedRect);
    }

    @Override
    public void requestChildFocus(View child, View focused) {
        if (EmoticonsKeyboardUtils.isFullScreen((Activity) getContext())) {
            return;
        }
        super.requestChildFocus(child, focused);
    }

    public boolean dispatchKeyEventInFullScreen(KeyEvent event) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_BACK:
                if (EmoticonsKeyboardUtils.isFullScreen((Activity) getContext()) && mLyKvml.isShown()) {
                    reset();
                    return true;
                }
        }
        return false;
    }
w446108264 commented 8 years ago

😂😂😂

本来想直接pull request好了,发现还不好改。

那同学,只能到这里了

Jacksgong commented 8 years ago

💯 恩。你说的问题确实存在的, 你看看最好是能研究研究提PR,我抽空也看看。

w446108264 commented 8 years ago

😁😁😁

嘻嘻我就不研究了,我在我的工程已经很好的实现了,满足了产品需求

https://github.com/w446108264/XhsEmoticonsKeyboard

w446108264 commented 8 years ago

因为我也遇到了全屏这个问题,后来参考了JKeyboardPanelSwitch的解决方法,不过发现还是没能解决,当我解决了之后,自然是要回来分享一下我的解决的办法

Jacksgong commented 8 years ago

屌屌地。