How to run a Litho animation automatically?

112 Views Asked by At

What's the proper way to start a Litho animation when an Activity is first displayed. All of the Litho animation examples are initiated by a user action, but I want to run one automatically.

I tried to extend a Litho animation example RTAnimationComponentSpec to fire the animation for the @OnEvent(VisibleEvent.class) instead of just @OnEvent(ClickEvent.class). But it didn't fire though.

Existing click event handler:

  @OnEvent(ClickEvent.class)
  static void onClick(ComponentContext c) {
    RTAnimationComponent.updateStateSync(c);
  }

Additional event handler that I added:

  @OnEvent(VisibleEvent.class)
  static void onVisible(ComponentContext c) {
    RTAnimationComponent.updateStateSync(c);
  }

I confirmed the VisibleEvent didn't fire by:

  1. Loading the Render Thread example and confirmed the animation didn't start
  2. Setting a breakpoint in the onVisible() method

How can I run a Litho animation automatically?

1

There are 1 best solutions below

0
Michael Osofsky On

One solution I found works is to make use of the @OnCreateInitialState

@OnCreateInitialState
static void createInitialState(
        ComponentContext c,
        StateValue<Boolean> state) {
    state.set(true);
}

This runs the animation, but I'm not sure if it's the preferred way.