Litho: LithoView.create() does not accept ComponentLayout

Created on 31 Aug 2017  路  4Comments  路  Source: facebook/litho

Version

compile 'com.facebook.litho:litho-core:0.3.1'
compile 'com.facebook.litho:litho-widget:0.3.1'
provided 'com.facebook.litho:litho-annotations:0.3.1'
annotationProcessor 'com.facebook.litho:litho-processor:0.3.1'

Issues and Steps to Reproduce

I want to create a more complexe layout that a simple text to pass on LithoView.create() function. I tried to create a layout by using the Column ComponentLayout but it does not work because the method LithoView.create() accept only Component and not ComponentLayout.

Here is an example:

final RecyclerBinder recyclerBinder = new RecyclerBinder(componentContext,
        new LinearLayoutInfo(this, OrientationHelper.VERTICAL, false)
);

final Component recycler = Recycler.create(componentContext)
        .binder(recyclerBinder)
        .build();

ComponentLayout cl = Column.create(componentContext)
        .child(Button.create(componentContext)
                .text("validate")
                .listener(new ButtonSpec.ButtonClickListener() {
                    @Override
                    public void onClick() {
                        Toast.makeText(componentContext, "click", Toast.LENGTH_SHORT).show();
                    }
                }))
        .child(recycler)
        .build();

setContentView(LithoView.create(this, cl));

How do I set Column or any other LayoutComponentas the root of my LithoView?

Most helpful comment

@Martin-Hogge this is a limitation of the framework that we plan to fix in the future, but for now you'd have to create a new @LayoutSpec-annotated class and use the generated component as the root of your LithoView. Hope that helps!

All 4 comments

@Martin-Hogge this is a limitation of the framework that we plan to fix in the future, but for now you'd have to create a new @LayoutSpec-annotated class and use the generated component as the root of your LithoView. Hope that helps!

Any updates on this? When do you plan to release?

This now works as you hope. Column.create(c) returns a Component, so you can pass that to LithoView.create

I don't think there is a full release with that change in, but if you use a snapshot release then you will get that behaviour.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hussainahmad picture hussainahmad  路  3Comments

passy picture passy  路  3Comments

ersin-ertan picture ersin-ertan  路  7Comments

kosiarska picture kosiarska  路  7Comments

Zeyad-37 picture Zeyad-37  路  8Comments