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

多次点击,防抖动的插件相关问题 #54

Open
lany192 opened this issue Jan 18, 2022 · 8 comments
Open

多次点击,防抖动的插件相关问题 #54

lany192 opened this issue Jan 18, 2022 · 8 comments

Comments

@lany192
Copy link

lany192 commented Jan 18, 2022

使用了你的点击防抖动插件,发现对Java有效,对kotlin无效。我的项目是Java和kotlin混合开发的。请问有什么解决方法,是不是没有适配kotlin?

@Leifzhang
Copy link
Owner

用的kotlin版本多少 试验下非lambda写法

@lany192
Copy link
Author

lany192 commented Jan 19, 2022

kotlin v1.6.10 非Lambda写法正常,Lambda写法无效:

.setOnClickListener { Log.i("demo", "这种写法无效") }

.setOnClickListener(object : View.OnClickListener {
override fun onClick(v: View) {
Log.i("demo", "这种写法有效")
}
})

大佬,有空的时候帮忙看看

@Leifzhang
Copy link
Owner

哦 lambda 问题我大概知道了, 我偷懒了 没写 你随便在lambda加个外部引用应该也行

@xuexixuexijpg
Copy link

kotlin v1.6.10 非Lambda写法正常,Lambda写法无效:

.setOnClickListener { Log.i("demo", "这种写法无效") }

.setOnClickListener(object : View.OnClickListener { override fun onClick(v: View) { Log.i("demo", "这种写法有效") } })

大佬,有空的时候帮忙看看

大佬有什么想法解决了吗?我看是字节码是有个invokeDynamic的指令,有个静态方法作为类似的点击方法,是不是判断找到这个点击的静态方法插入代码就行了

@Leifzhang
Copy link
Owner

没有外部引用的lambda会被变成一个静态的 所以只是需要把原来的double tap的类转化成一个静态函数,所以我就偷懒没写而已 ,整体思路一致 没有太大变化

@JohnsonJLi
Copy link

@Leifzhang 大佬:

我给每一个 lambda 都生成了 静态的 DoubleTapCheck

public static final DoubleTapCheck doubleTapStatic_onCreate$lambda_0 = null;
public static final DoubleTapCheck doubleTapStatic_onCreate$lambda_1 = null;
public static final DoubleTapCheck doubleTapStatic_onCreate$lambda_2 = null;

public MainActivity() {
    doubleTapStatic_onCreate$lambda_0 = new DoubleTapCheck();
    doubleTapStatic_onCreate$lambda_1 = new DoubleTapCheck();
    doubleTapStatic_onCreate$lambda_2 = new DoubleTapCheck();
}

不知道这样做会不会有什么问题

@Leifzhang
Copy link
Owner

我觉得没啥问题 讲道理

@JohnsonJLi
Copy link

已经改成 这种写法了 。。。。。

private static final DoubleTapCheck doubleTapStatic_onCreate$lambda_0 = new DoubleTapCheck();
private static final DoubleTapCheck doubleTapStatic_onCreate$lambda_1 = new DoubleTapCheck();

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

4 participants