NativeScript / NativeScript/android
Support Kotlin higher-order functions/lambdas
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 563
- 派生
- 144
- 平均合并
- 10 小时 46 分钟
- 30 天内合并 PR
- 14
描述
NativeScript supports marshalling Java bytecode generated by Kotlin. But Kotlin has a way to specify that a function takes another function in a much better way than Java.
Like this:
fun myfun(callback: (arg: String) -> Void)
It compiles to something like
public final void myfun(@org.jetbrains.annotations.NotNull final kotlin.jvm.functions.Function1<? super String, Void> callback)
where Function1 is a class containing an invoke method. Depending on how many args the function takes, it'll be called Function2, Function3 and so on.
Interacting with myfun from JavaScript would be done this way:
myfun(new kotlin.jvm.functions.Function1({ invoke: () => console.log("invoked") }))
It would be so cool if NativeScript supported Kotlin-functions out of the box, so the callback wouldn't need to be wrapped in FunctionX and myfun could be run via myfun(() => console.log("invoked")). This would make it easier to align with an Objective-C library, where blocks are supported.
To support Kotlin, my app.gradle currently looks like this:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.30"
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.30"
}
android {
defaultConfig {
generatedDensities = []
applicationId = "org.nativescript.test"
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
未指定仓库文件或测试。首先追踪 NativeScript Android 的 Java 字节码封送,以及 kotlin.jvm.functions.Function1、Function2 和更高元数如何表示;将其与现有的 JavaScript 回调包装路径进行比较。完成标准是 Kotlin 函数参数可以直接接收 JavaScript 回调,而无需手动构造 FunctionX 实例。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, kotlin
- 领域
- mobile
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100