How to run a Litho animation automatically?

随声附和 提交于 2019-12-13 03:04:39

问题


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:


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.



来源:https://stackoverflow.com/questions/55975483/how-to-run-a-litho-animation-automatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!