From 085bb35898cd71a2398065193764beca9d7504a3 Mon Sep 17 00:00:00 2001 From: pengzhiwen Date: Thu, 20 Mar 2025 21:21:56 +0800 Subject: [PATCH] =?UTF-8?q?uicontext=E6=94=AF=E6=8C=81inspector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pengzhiwen --- .../arkui/src/generated/arkts/index.ts | 3 ++- .../generated/arkts/ohos.arkui.inspector.ts | 22 +++++++++++++++++++ arkoala-arkts/arkui/src/generated/ts/index.ts | 1 + .../src/generated/ts/ohos.arkui.inspector.ts | 6 +++++ .../arkui/src/ohos.arkui.UIContext.ts | 19 +++++++++++++++- arkoala-arkts/arkui/types/index-full.d.ts | 7 ++++++ 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 arkoala-arkts/arkui/src/generated/arkts/ohos.arkui.inspector.ts create mode 100644 arkoala-arkts/arkui/src/generated/ts/ohos.arkui.inspector.ts diff --git a/arkoala-arkts/arkui/src/generated/arkts/index.ts b/arkoala-arkts/arkui/src/generated/arkts/index.ts index 69e843017a..0120a72b11 100644 --- a/arkoala-arkts/arkui/src/generated/arkts/index.ts +++ b/arkoala-arkts/arkui/src/generated/arkts/index.ts @@ -1,4 +1,5 @@ export * from "./type_check" export * from "./ArkUINativeModule" export * from "./ArkUIGeneratedNativeModule" -export * from "./TestNativeModule" \ No newline at end of file +export * from "./TestNativeModule" +export * from "./ohos.arkui.inspector" \ No newline at end of file diff --git a/arkoala-arkts/arkui/src/generated/arkts/ohos.arkui.inspector.ts b/arkoala-arkts/arkui/src/generated/arkts/ohos.arkui.inspector.ts new file mode 100644 index 0000000000..f053d1e062 --- /dev/null +++ b/arkoala-arkts/arkui/src/generated/arkts/ohos.arkui.inspector.ts @@ -0,0 +1,22 @@ +import { loadNativeModuleLibrary } from "@koalaui/interop" + +export class ComponentObserver { + private nativeComponentObserver: long = 0; + + constructor(nativeAddr: long) { + if (this.nativeComponentObserver == 0) { + this.nativeComponentObserver = nativeAddr; + } + } + + public native on(type: string, callback: ()=>void) : void; + + public native off(type: string, callback?: ()=>void) : void; +} + +export class Inspector { + static { + loadNativeModuleLibrary("inspector_ani"); + } + native static createComponentObserver(id: string): ComponentObserver; +} \ No newline at end of file diff --git a/arkoala-arkts/arkui/src/generated/ts/index.ts b/arkoala-arkts/arkui/src/generated/ts/index.ts index 4aedac5705..0120a72b11 100644 --- a/arkoala-arkts/arkui/src/generated/ts/index.ts +++ b/arkoala-arkts/arkui/src/generated/ts/index.ts @@ -2,3 +2,4 @@ export * from "./type_check" export * from "./ArkUINativeModule" export * from "./ArkUIGeneratedNativeModule" export * from "./TestNativeModule" +export * from "./ohos.arkui.inspector" \ No newline at end of file diff --git a/arkoala-arkts/arkui/src/generated/ts/ohos.arkui.inspector.ts b/arkoala-arkts/arkui/src/generated/ts/ohos.arkui.inspector.ts new file mode 100644 index 0000000000..842a645147 --- /dev/null +++ b/arkoala-arkts/arkui/src/generated/ts/ohos.arkui.inspector.ts @@ -0,0 +1,6 @@ +export const Inspector: any = undefined + +export interface ComponentObserver { + on(type: string, callback: ()=>void) : void; + off(type: string, callback?: ()=>void) : void; +} \ No newline at end of file diff --git a/arkoala-arkts/arkui/src/ohos.arkui.UIContext.ts b/arkoala-arkts/arkui/src/ohos.arkui.UIContext.ts index 83db5d1ce8..1560ed2563 100644 --- a/arkoala-arkts/arkui/src/ohos.arkui.UIContext.ts +++ b/arkoala-arkts/arkui/src/ohos.arkui.UIContext.ts @@ -21,7 +21,7 @@ import { GlobalScope_ohos_font } from "./generated/ArkGlobalScopeOhosFontMateria import { GlobalScope_ohos_measure_utils } from "./generated/ArkGlobalScopeOhosMeasureUtilsMaterialized" import { FontOptions, FontInfo, MeasureOptions } from "./generated/ArkArkuiExternalInterfaces" import { SizeOptions } from "./generated/ArkUnitsInterfaces" -import { ArkUIGeneratedNativeModule } from "#components" +import { ArkUIGeneratedNativeModule, Inspector, ComponentObserver } from "#components" import { int32 } from "@koalaui/common" import { nullptr } from "@koalaui/interop" @@ -69,6 +69,19 @@ export class MeasureUtils { } } +export class UIInspector { + instanceId_: int32 = 100000; + constructor(instanceId: int32) { + this.instanceId_ = instanceId; + } + public createComponentObserver(id: string): ComponentObserver { + ArkUIGeneratedNativeModule._SystemOps_syncInstanceId(this.instanceId_); + let componentObserver = Inspector.createComponentObserver(id); + ArkUIGeneratedNativeModule._SystemOps_restoreInstanceId(); + return componentObserver; + } +} + export class UIContext { instanceId_: int32 = 100000; constructor(instanceId: int32) { @@ -95,6 +108,10 @@ export class UIContext { ArkUIGeneratedNativeModule._SystemOps_restoreInstanceId(); return null; } + public getUIInspector(): UIInspector { + let uiInspector = new UIInspector(this.instanceId_); + return uiInspector; + } } export abstract class FrameCallback { abstract onFrame(frameTimeInNano: number): void; diff --git a/arkoala-arkts/arkui/types/index-full.d.ts b/arkoala-arkts/arkui/types/index-full.d.ts index 4de299b586..d47f745251 100644 --- a/arkoala-arkts/arkui/types/index-full.d.ts +++ b/arkoala-arkts/arkui/types/index-full.d.ts @@ -2466,6 +2466,13 @@ declare interface RouterPageInfo { declare interface UIContext { _UIContextStub: string; } +declare interface ComponentObserver { + on(type: string, callback: ()=>void) : void; + off(type: string, callback?: ()=>void) : void; +} +declare interface UIInspector { + createComponentObserver(id: string): ComponentObserver; +} declare interface DrawContext { _DrawContextStub: string; } -- Gitee