Skip to content

[Feature] Support measureContent(...) for Nitro Views #1199

Description

@mrousavy

Feature Request/Enhancement

Yoga allows us to override this method:

/*
 * Measures the node (and node content, probably recursively) with
 * given constrains and relying on possible layout.
 * Default implementation returns zero size.
 */
virtual Size measureContent(const LayoutContext &layoutContext, const LayoutConstraints &layoutConstraints) const;

This requires you to also override ConcreteViewShadowNode::BaseTraits() and add these two traits:

react::ShadowNodeTraits HybridCameraViewNode::BaseTraits() {
  auto traits = ConcreteViewShadowNode::BaseTraits();
  traits.set(react::ShadowNodeTraits::LeafYogaNode);
  traits.set(react::ShadowNodeTraits::MeasurableYogaNode);
  return traits;
}

We can override this in Nitro, and implement it in a static Swift/Kotlin method that receives the props. Something like this:

class HybridCameraView: HybridCameraViewSpec {
  // ...

  static func measureContent(props: CameraProps,
                             layoutContext: LayoutContext,
                             layoutConstraints: LayoutConstraints) -> Size {
    return Size(width: 100, height: 50)
  }
}

Are there any existing workarounds?

Patching the generated files in Yoga and doing that yourself

Additional information

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions