Skip to content

如何自定义一个动态高度和宽度的 react 节点? #6495

Answered by Rey-Wang
Rey-Wang asked this question in Q&A
Discussion options

You must be logged in to vote

所以代码比较少的版本是利用 onUpdate钩子,但是 onUpdate 在每次节点操作都会被执行,放在这里更新 size 就不是很合理了,是否有某个 API 可以 update size,这样就可以在 onCreate 时候被调用,而且不被 onUpdate 覆盖?

export class CustomReactNode extends ReactNode {
  private getReactNodeSize(): Size | undefined {
    const { fixedHeight, fixedWidth } = this.attributes as unknown as OwlReactNodeStyleProps;
    const originalSize = this.getSize(this.attributes);
    if (this.getShape('key')) {
      const childNode = this.getDomElement().children[0] as HTMLElement;
      if (childNode) {
        this.getSize;
        const expectedWidth = fixedWidth ? originalSize[0] : childNode.offsetWidth;
        const expectedHeight = fixedHeight ? originalSize[1] : childNode.offsetH…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Rey-Wang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant