Jacksgong / JKeyboardPanelSwitch

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

能否在SwitchClickListener返回被点击的View #87

Closed farsunset closed 6 years ago

farsunset commented 6 years ago

能否在SwitchClickListener返回被点击的View,多个panel的情况下,需要这个View来做一些判断。还有如何在登录页面记录下来 键盘高度,这样就不需要使用min-panel-height的配置了

Jacksgong commented 6 years ago

已经在1.6.2-SNAPSHOT上实现,你可以添加以下仓库后,引入1.6.2-SNAPSHOT版本进行验证:

allprojects {
  repositories {
      maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
  }
}
farsunset commented 6 years ago

好的,谢谢

r17171709 commented 5 years ago

@Jacksgong 使用快照版本这样无效 api 'cn.dreamtobe.kpswitch:library:1.6.2-SNAPSHOT'

Jacksgong commented 5 years ago

@r17171709 你要先参考上面提到的申明仓库,anyway,我已经发布了1.6.2,你可以直接使用1.6.2了。

Harlber commented 5 years ago

感谢官方支持该功能,之前项目中采用hook performClick来实现

@r17171709 实在不行可以试试我的方案,将需要知道被点击的view用PostClickImageView替换

@SuppressLint("AppCompatCustomView")
public class PostClickImageView extends ImageView {
    private OnPostClickListener onPostClickListener;

    public PostClickImageView(Context context) {
        super(context);
    }

    public PostClickImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PostClickImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public PostClickImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public boolean performClick() {
        boolean shouldClick = super.performClick();
        if (shouldClick && onPostClickListener != null) {
            onPostClickListener.performClick(this);
        }
        return shouldClick;
    }

    public static interface OnPostClickListener {

        void performClick(View v);
    }

    public void setOnPostClickListener(OnPostClickListener onPostClickListener) {
        this.onPostClickListener = onPostClickListener;
    }
}
chentao7v commented 5 years ago

@Harlber 点击事件的回调没有修复啊,1.6.2的代码中依然是

               if (switchClickListener != null && switchToPanel != null) {
                    switchClickListener.onClickSwitch(v, switchToPanel);
                }
Harlber commented 5 years ago

那你可以试试上面我提及的hook performClick的方式,我项目中用的解决方案 @chentao7v

farsunset commented 5 years ago

大佬。1.6.2这个功能是加上了,但是有个bug ,场景如下 2个Switch 分别为Switch1, Switch2 当前panel1为Switch1,这个时候点击Switch2,切换到panel2,功能没有问题,但是onClickSwitch回调没有触发,这个时候再点击一次Switch2才会触发,我希望只要是点击了Switch,就一定回调onClickSwitch,希望早日解决,谢谢;

wangzhanxian commented 3 years ago

可以给点击的View设置setOnTouchListener,这个是在onClick之前执行的,如果返回true,还可以屏蔽掉点击事件