Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
TestToolChainDemo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
dsq
TestToolChainDemo
Commits
48e80fb4
Commit
48e80fb4
authored
Jul 03, 2026
by
dong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
恢复nativeApi.ArkTsToKotlin()
parent
0cbeb711
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
26 deletions
+56
-26
napi_init.cpp
harmonyApp/entry/src/main/cpp/napi_init.cpp
+1
-1
Index.d.ts
harmonyApp/entry/src/main/cpp/types/libentry/Index.d.ts
+9
-2
Index.ets
harmonyApp/entry/src/main/ets/pages/Index.ets
+46
-23
No files found.
harmonyApp/entry/src/main/cpp/napi_init.cpp
View file @
48e80fb4
...
@@ -27,7 +27,7 @@ EXTERN_C_START
...
@@ -27,7 +27,7 @@ EXTERN_C_START
static
napi_value
Init
(
napi_env
env
,
napi_value
exports
)
{
static
napi_value
Init
(
napi_env
env
,
napi_value
exports
)
{
androidx_compose_ui_arkui_init
(
env
,
exports
);
androidx_compose_ui_arkui_init
(
env
,
exports
);
napi_property_descriptor
desc
[]
=
{
napi_property_descriptor
desc
[]
=
{
{
"MainArkUIVi
s
ewController"
,
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
},
};
};
napi_define_properties
(
env
,
exports
,
sizeof
(
desc
)
/
sizeof
(
desc
[
0
]),
desc
);
napi_define_properties
(
env
,
exports
,
sizeof
(
desc
)
/
sizeof
(
desc
[
0
]),
desc
);
...
...
harmonyApp/entry/src/main/cpp/types/libentry/Index.d.ts
View file @
48e80fb4
import
{
ArkUIViewController
,
testArkTsToKotin
}
from
"@cpf-kmp-cmp/compose/src/main/cpp/types/libcompose_arkui_utils"
;
import
{
ArkUIViewController
}
from
"@cpf-kmp-cmp/compose/src/main/cpp/types/libcompose_arkui_utils"
;
export
const
MainArkUIViewController
:
()
=>
ArkUIViewController
export
const
MainArkUIViewController
:
()
=>
ArkUIViewController
export
const
testArkTsToKotin
:()
=>
void
export
const
testArkTsToKotin
:
()
=>
void
declare
const
nativeApi
:
{
MainArkUIViewController
:
typeof
MainArkUIViewController
testArkTsToKotin
:
typeof
testArkTsToKotin
}
export
default
nativeApi
harmonyApp/entry/src/main/ets/pages/Index.ets
View file @
48e80fb4
import { Compose } from '@cpf-kmp-cmp/compose';
import {
ArkUIViewController,
Compose } from '@cpf-kmp-cmp/compose';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import nativeApi from 'libentry.so';
import nativeApi from 'libentry.so';
import { MainArkUIViewController, testArkTsToKotin } from 'libentry.so';
import { testArkTsToArkTs } from './TestJumpClass';
import { testArkTsToArkTs } from './TestJumpClass';
import { MyFunction } from './MyFunction';
import { MyFunction } from './MyFunction';
import { promptAction } from '@kit.ArkUI'; // 未使用的依赖
import { promptAction } from '@kit.ArkUI'; // 未使用的依赖
...
@@ -13,58 +12,84 @@ const DOMAIN = 0x0000;
...
@@ -13,58 +12,84 @@ const DOMAIN = 0x0000;
@Entry
@Entry
@Component
@Component
struct Index {
struct Index {
private controller = MainArkUIViewController();
private controller: ArkUIViewController | undefined = undefined;
@State errorMessage: string = 'Native module not ready';
aboutToAppear() {
aboutToAppear() {
hilog.info(DOMAIN, 'Compose', 'aboutToAppear');
hilog.info(DOMAIN, 'Compose', 'aboutToAppear');
//ArkTs生命周期断点处
if (nativeApi === undefined) {
hilog.error(DOMAIN, 'Compose', 'nativeApi is undefined, cannot create controller');
this.errorMessage = 'nativeApi is undefined';
return;
}
let unusedInt: number = 0;//未使用的变量
let unusedInt: number = 0;//未使用的变量
//ArkTs到Kotlin的单向跳转
//ArkTs到Kotlin的单向跳转
nativeApi.testArkTsToKotin();
nativeApi.testArkTsToKotin();
//原生内部跳转
//原生内部跳转
testArkTsToArkTs();
testArkTsToArkTs();
try {
this.controller = nativeApi.MainArkUIViewController();
const state = this.controller ? 'created' : 'not_created';
hilog.info(DOMAIN, 'Compose', 'controller init state: %{public}s', state);
if (!this.controller) {
this.errorMessage = 'Controller creation failed (returned null)';
}
} catch (e) {
hilog.error(DOMAIN, 'Compose', 'Exception creating controller: %{public}s', JSON.stringify(e));
this.errorMessage = 'Exception creating controller: ' + JSON.stringify(e);
}
}
}
// 模拟耗时操作
// 模拟耗时操作
private loadData() {// 未使用的方法
private loadData() {// 未使用的方法
for (let i = 0; i < 10000; i++) {
for (let i = 0; i < 10000; i++) {
// 模拟数据处理
// 模拟数据处理
let temp = i * i;
let temp = i * i;
}
}
}
}
build() {
build() {
Column() {
Column() {
Compose({
if (this.controller) {
controller: this.controller,
Compose({
libraryName: 'entry',
controller: this.controller,
onBackPressed: () => false
libraryName: 'entry',
// onBackPressed: () => this.controller.onBackPress() 不能使用这个 会出现无限循环
onBackPressed: () => false
})
// onBackPressed: () => this.controller!.onBackPress() 不能使用这个 会出现无限循环
.width('100%')
})
.height('100%')
} else {
Text(this.errorMessage)
}
}
}
.width('100%')
.width('100%')
.height('100%')
.height('100%')
}
}
onPageShow() {
onPageShow() {
this.controller.onPageShow();
if (this.controller) {
this.controller.onPageShow();
}
}
}
onPageHide() {
onPageHide() {
this.controller.onPageHide();
if (this.controller) {
this.controller.onPageHide();
}
}
}
onBackPress(): boolean {
onBackPress(): boolean {
return this.controller
.onBackPress()
;
return this.controller
? this.controller.onBackPress() : false
;
}
}
//测试-自定义鸿蒙原生函数
//测试-自定义鸿蒙原生函数
}
}
...
@@ -115,5 +140,3 @@ export function testFindUsages(){
...
@@ -115,5 +140,3 @@ export function testFindUsages(){
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment