#鸿蒙通关秘籍#绘制TextInput组件时如何更新同层元素的位置?

HarmonyOS
5天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
墨海星辰UI

在使用同层渲染功能绘制TextInput组件时,当元素的位置变化时(例如滚动、缩放),需要更新其位置信息。以下代码展示了如何实现这一点:

typescript @Component struct TextInputComponent { @Prop params: Params build() { Column() { TextInput({ text: ${this.params.textOne} }) .height(50) .width(200) .onTouch((event) => console.log('input touch event', event)) } .width(this.params.width) .height(this.params.height) } }

@Entry @Component struct Page { private nodeControllerMap: Map<string, MyNodeController> = new Map(); @State componentIdArr: Array<string> = []; @State edges: Edges = {};

build() { Row() { Column() { Web({ src: $rawfile('test.html'), controller: this.browserTabController}) .enableNativeEmbedMode(true) .registerNativeEmbedRule("object", "application/view") .onNativeEmbedLifecycleChange((embed) => { const componentId = embed.info?.id?.toString() as string; this.edges = {left: ${embed.info?.position?.x}px, top: ${embed.info?.position?.y}px} let nodeController = new MyNodeController() nodeController.setRenderOption(...) nodeController.rebuild() this.nodeControllerMap.set(componentId, nodeController) this.componentIdArr.push(componentId) }) } } } }

分享
微博
QQ
微信
回复
5天前
相关问题
webview是否支持渲染
1844浏览 • 1回复 待解决