feat: entry中使用XComponent指定模块,绘制
This commit is contained in:
parent
fc56622ccb
commit
b9967dad48
|
@ -93,4 +93,13 @@ void PluginRender::RegisterCallback(OH_NativeXComponent *nativeXComponent) {
|
||||||
|
|
||||||
// 将 callback 注册给 NativeXComponent
|
// 将 callback 注册给 NativeXComponent
|
||||||
OH_NativeXComponent_RegisterCallback(nativeXComponent, this->renderCallback_);
|
OH_NativeXComponent_RegisterCallback(nativeXComponent, this->renderCallback_);
|
||||||
|
|
||||||
|
|
||||||
|
// // has bug
|
||||||
|
// renderCallback_1.DispatchTouchEvent = DispatchTouchEventCB;
|
||||||
|
// renderCallback_1.OnSurfaceChanged = OnSurfaceChangedCB;
|
||||||
|
// renderCallback_1.OnSurfaceCreated = OnSurfaceCreatedCB;
|
||||||
|
// renderCallback_1.OnSurfaceDestroyed = OnSurfaceDestroyedCB;
|
||||||
|
//
|
||||||
|
// OH_NativeXComponent_RegisterCallback(nativeXComponent, &renderCallback_1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OH_NativeXComponent_Callback *renderCallback_;
|
OH_NativeXComponent_Callback *renderCallback_;
|
||||||
|
OH_NativeXComponent_Callback renderCallback_1;
|
||||||
|
|
||||||
static std::unordered_map<std::string, PluginRender *> instance_;
|
static std::unordered_map<std::string, PluginRender *> instance_;
|
||||||
};
|
};
|
||||||
|
|
4
entry/src/main/ets/interface/XComponentContext.ets
Normal file
4
entry/src/main/ets/interface/XComponentContext.ets
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export interface XComponentContext {
|
||||||
|
add: (a: number, b: number) => number;
|
||||||
|
drawPattern: () => void;
|
||||||
|
}
|
|
@ -1,16 +1,44 @@
|
||||||
import hilog from '@ohos.hilog';
|
import hilog from '@ohos.hilog';
|
||||||
import testNapi from 'libentry.so';
|
import { XComponentContext } from '../interface/XComponentContext';
|
||||||
import { DrawingDemo } from 'drawing'
|
|
||||||
|
|
||||||
|
const TAG = 'DrawingDemo'
|
||||||
const TAG = '[Sample_DrawingAPI]'
|
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct Index {
|
export struct Index {
|
||||||
|
private xComponentAttrs: XComponentAttrs = {
|
||||||
|
id: 'xcomponentId',
|
||||||
|
type: XComponentType.SURFACE,
|
||||||
|
libraryname: 'drawing'
|
||||||
|
}
|
||||||
|
@State xComponentContext: XComponentContext | undefined = undefined;
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Column() {
|
Column({ space: 10 }) {
|
||||||
DrawingDemo()
|
Row() {
|
||||||
|
XComponent(this.xComponentAttrs)// .focusable(true)// 可响应键盘事件
|
||||||
|
.onLoad((xComponentContext: XComponentContext) => {
|
||||||
|
this.xComponentContext = xComponentContext
|
||||||
|
const res = xComponentContext.add(2, 3)
|
||||||
|
hilog.info(0xffff, TAG, `xComponentContext.add: 2 + 3 = ${res}`)
|
||||||
|
})
|
||||||
|
.onDestroy(() => {
|
||||||
|
console.log("onDestroy");
|
||||||
|
})
|
||||||
|
.width('100%')
|
||||||
|
.height('80%')
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
.justifyContent(FlexAlign.Center)
|
||||||
|
|
||||||
|
Row() {
|
||||||
|
Button('draw')
|
||||||
|
.onClick(() => {
|
||||||
|
this.xComponentContext?.drawPattern()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
.justifyContent(FlexAlign.Center)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user