NativeScript / NativeScript/android

Support Kotlin higher-order functions/lambdas

Đang mở
#977 4 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feature severity: low
Ngôn ngữ chính
C++
Star
563
Fork
144
Merge trung bình
10 giờ 46 phút
Pull request đã merge (30 ngày)
14

Mô tả

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"  
  }  
} 

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Không có tệp hoặc bài kiểm thử nào trong repository được nêu tên. Hãy bắt đầu bằng cách lần theo quá trình marshalling bytecode Java của NativeScript Android và cách kotlin.jvm.functions.Function1, Function2 cùng các arity cao hơn được biểu diễn; so sánh điều đó với đường dẫn wrapping callback JavaScript hiện có. Công việc được coi là hoàn tất khi các tham số hàm Kotlin có thể nhận trực tiếp callback JavaScript mà không cần tạo thủ công các instance FunctionX.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, kotlin
Lĩnh vực
mobile
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.