HarmonyOS NodeRender

import { RenderNode, FrameNode, NodeController } from "@ohos.ArkUI.node";

const renderNode = new RenderNode();
renderNode.frame = { x: 0, y: 0, width: 100, height: 100 };
renderNode.backgroundColor = 0xffff0000;

class MyNodeController extends NodeController {
  private rootNode: FrameNode | null = null;

  makeNode(uiContext: UIContext): FrameNode | null {
    this.rootNode = new FrameNode(uiContext);

    const rootRenderNode = this.rootNode.getRenderNode();
    if (rootRenderNode !== null) {
      rootRenderNode.appendChild(renderNode);
    }

    return this.rootNode;
  }
}

@Entry
@Component
struct Index {
  private myNodeController: MyNodeController = new MyNodeController();

  build() {
    Row() {
      NodeContainer(this.myNodeController)
    }
  }
}

想要这个render占满父组件的宽、高要怎么做

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

可以参考此demo:

import { UIContext } from '@ohos.ArkUI.UIContext';
import { NodeController, BuilderNode, FrameNode } from "@ohos.ArkUI.node"

class Params {
  text: string = ""
  constructor(text: string) {
    this.text = text;
  }
}

@Builder
function buildText(params: Params) {
  Column() {
    Text(params.text)
      .fontSize(50)
      .fontWeight(FontWeight.Bold)
      .margin({ bottom: 36 })
      .width('100%')
      .height('100%')
      .backgroundColor(Color.Green)
  }
}

class TextNodeController extends NodeController {
  private rootNode: FrameNode | null = null;
  private textNode: BuilderNode<[Params]> | null = null;
  private message: string = "";

  constructor(message: string) {
    super()
    this.message = message
  }

  makeNode(context: UIContext): FrameNode | null {
    this.textNode = new BuilderNode(context);
    this.textNode.build(wrapBuilder<[Params]>(buildText), new Params(this.message))
    return this.textNode.getFrameNode();
  }
}

@Entry
@Component
struct Index {
  @State message: string = "hello"
  private textNodeController: TextNodeController = new TextNodeController(this.message);
  build() {
    Row() {
      Column() {
        NodeContainer(this.textNodeController)
          .width('60%')
          .height('30%')
          .backgroundColor('#ffe54949')
      }
      .width('100%')
      .height('100%')
    }
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS jsbridge HarmonyOS版本
90浏览 • 1回复 待解决
HarmonyOS HarmonyOS社区组件问题
325浏览 • 1回复 待解决
HarmonyOS 关于HarmonyOS应用的备案
37浏览 • 1回复 待解决
HarmonyOS flutter接入HarmonyOS原生视图
74浏览 • 1回复 待解决
HarmonyOS
57浏览 • 1回复 待解决
HarmonyOS JsBridge的HarmonyOS版本sdk
80浏览 • 1回复 待解决
HarmonyOS h5和HarmonyOS怎么通信?
161浏览 • 1回复 待解决
HarmonyOS RotateOptions
16浏览 • 1回复 待解决
HarmonyOS floatingActionButton
15浏览 • 1回复 待解决
HarmonyOS Tabs
30浏览 • 1回复 待解决
HarmonyOS LazyForEach
342浏览 • 1回复 待解决
HarmonyOS encodeURIComponent
23浏览 • 1回复 待解决
HarmonyOS HarmonyOS的视频流和操作流
38浏览 • 1回复 待解决
HarmonyOS responseRegion
227浏览 • 1回复 待解决
HarmonyOS Websocket?
146浏览 • 0回复 待解决
HarmonyOS DatePicker
21浏览 • 1回复 待解决
HarmonyOS TabContent
482浏览 • 1回复 待解决
HarmonyOS HarmonyOS应用开发是否支持c++20
100浏览 • 1回复 待解决