Commit 3676984b authored by lixuan's avatar lixuan

feat:IR12

parent 67eef1b9
package com.lx.IR12
import kotlinx.cinterop.ExperimentalForeignApi
import platform.PerformanceAnalysisKit.HiLog.OH_LOG_Print
import kotlin.experimental.ExperimentalNativeApi
class TestLambda {
val stringPlus: (String, String) -> String = String::plus
}
@OptIn(ExperimentalNativeApi::class, ExperimentalForeignApi::class)
@CName("TestLambdaStringPlus")
fun TestLambdaStringPlus() {
val stringPlus = TestLambda().stringPlus("a========================", "b")
OH_LOG_Print(0u, 4u, 4660u, "TestLambda", stringPlus)
}
package com.lx.IR12
import kotlinx.cinterop.ExperimentalForeignApi
import platform.PerformanceAnalysisKit.HiLog.OH_LOG_Print
import kotlin.experimental.ExperimentalNativeApi
class TestLambda {
val stringPlus: (String, String) -> String = String::plus
}
@OptIn(ExperimentalNativeApi::class, ExperimentalForeignApi::class)
@CName("TestLambdaStringPlus")
fun TestLambdaStringPlus() {
val stringPlus = TestLambda().stringPlus("a========================", "b")
OH_LOG_Print(0u, 4u, 4660u, "TestLambda", stringPlus)
}
...@@ -13,7 +13,13 @@ static napi_value NapiMainArkUIViewController(napi_env env, napi_callback_info / ...@@ -13,7 +13,13 @@ static napi_value NapiMainArkUIViewController(napi_env env, napi_callback_info /
return reinterpret_cast<napi_value>(::MainArkUIViewController(env)); return reinterpret_cast<napi_value>(::MainArkUIViewController(env));
} }
static napi_value nativeTestLambdaStringPlus(napi_env env, napi_callback_info /*info*/) {
TestLambdaStringPlus();
napi_value undefined;
napi_get_undefined(env, &undefined);
return undefined;
}
static napi_value nativeTestArkTsToKotin(napi_env env, napi_callback_info info) { static napi_value nativeTestArkTsToKotin(napi_env env, napi_callback_info info) {
testArkTsToKotin(); testArkTsToKotin();
...@@ -29,6 +35,7 @@ static napi_value Init(napi_env env, napi_value exports) { ...@@ -29,6 +35,7 @@ static napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor desc[] = { napi_property_descriptor desc[] = {
{"MainArkUIViewController", nullptr, NapiMainArkUIViewController, nullptr, nullptr, nullptr, napi_default, nullptr}, {"MainArkUIViewController", nullptr, NapiMainArkUIViewController, nullptr, nullptr, nullptr, napi_default, nullptr},
{"testArkTsToKotin", nullptr, nativeTestArkTsToKotin, nullptr, nullptr, nullptr, napi_default, nullptr}, {"testArkTsToKotin", nullptr, nativeTestArkTsToKotin, nullptr, nullptr, nullptr, napi_default, nullptr},
{"testLambdaStringPlus", nullptr, nativeTestLambdaStringPlus, nullptr, nullptr, nullptr, napi_default, nullptr},
}; };
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
return exports; return exports;
......
...@@ -4,9 +4,12 @@ export const MainArkUIViewController: () => ArkUIViewController ...@@ -4,9 +4,12 @@ export const MainArkUIViewController: () => ArkUIViewController
export const testArkTsToKotin: () => void export const testArkTsToKotin: () => void
export const testLambdaStringPlus: () => void
declare const nativeApi: { declare const nativeApi: {
MainArkUIViewController: typeof MainArkUIViewController MainArkUIViewController: typeof MainArkUIViewController
testArkTsToKotin: typeof testArkTsToKotin testArkTsToKotin: typeof testArkTsToKotin
testLambdaStringPlus: typeof testLambdaStringPlus
} }
export default nativeApi export default nativeApi
...@@ -57,6 +57,12 @@ struct Index { ...@@ -57,6 +57,12 @@ struct Index {
build() { build() {
Column() { Column() {
Button('测试 Lambda')
.onClick(() => {
hilog.info(DOMAIN, 'Compose', 'testLambdaStringPlus button clicked');
nativeApi.testLambdaStringPlus();
hilog.info(DOMAIN, 'Compose', 'testLambdaStringPlus native call returned');
})
if (this.controller) { if (this.controller) {
Compose({ Compose({
controller: this.controller, controller: this.controller,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment