Skip to content

Provide a builder pattern interface to the construction layout tree #275

@giantpand2000

Description

@giantpand2000

What problem does this solve or what need does it fill?

Provides a more compact, write-friendly, ergonomic interface

What solution would you like?

@LayoutSpec
public class PlaygroundComponentSpec {
  @OnCreateLayout
  static Component onCreateLayout(ComponentContext c) {
    return Row.create(c)
      .child(
        Row.create(c)
          .widthDip(100)
          .heightDip(100))
      .child(
        Row.create(c)
          .widthDip(100)
          .heightDip(100)
          .marginDip(YogaEdge.HORIZONTAL, 20)
          .flexGrow(1))
      .child(
        Row.create(c)
          .widthDip(100)
          .heightDip(100))
      .widthDip(500)
      .heightDip(500)
      .alignItems(YogaAlign.FLEX_START)
      .paddingDip(YogaEdge.ALL, 20)
      .build();
  }
}

What alternative(s) have you considered?

Since many anonymous nodes are used, a method of result feedback is needed, such as having the node save a callback function, or a Trait that provides result feedback

Additional context

The sample code comes from the Yoga home page, a Java package called litho. But it can be translated quite directly to Rust code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersusabilityMake the library more comfortable to use

    Projects

    • Status

      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions