NativeScript / NativeScript/android
Support Kotlin higher-order functions/lambdas
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C++
- Estrellas
- 563
- Forks
- 144
- Merge medio
- 10 h 46 min
- PR fusionados (30 d)
- 14
Descripción
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"
}
}
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
No se nombran archivos ni pruebas del repositorio. Empieza por rastrear el marshalling del bytecode Java de NativeScript Android y cómo se representan kotlin.jvm.functions.Function1, Function2 y las aridades superiores; compáralo con la ruta existente de wrapping de callbacks de JavaScript. La tarea estará completada cuando los parámetros de funciones Kotlin puedan recibir callbacks de JavaScript directamente sin construir manualmente instancias de FunctionX.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, kotlin
- Área
- mobile
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100