Search code examples
androidlitho

How can I replace existing text with Litho?


I'm trying to change the text. On Example in onActivityResult (), but I can not find a solution

@LayoutSpec
public class LaytourSpec {

    @OnCreateLayout
    static Component onCreateLayout(
            final ComponentContext c, @Prop(optional = true) String title) {
        return Text.create(c)
                .text("bla bla")
                .textSizeSp(18).build();
}

Solution

  • You need to create a new component and assign it into your LithoView through setComponent(), then you should see text changed.

    @Override
    void onCreate(Bundle savedInstanceState) {
      mLithoView = findViewById(...);
    }
    
    @Override
    void onActivityResult(int requestCode, int resultCode, Intent data) {
       // Create a new component according to the result data.
       final Laytour laytour = Laytour.create(mComponentContext)...
       mLithoView.setComponent(laytour);
    }