如何自动运行Litho动画? [英] How to run a Litho animation automatically?

查看:112
本文介绍了如何自动运行Litho动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首次显示活动"时,启动Litho动画的正确方法是什么?所有 Litho动画示例是通过用户操作启动的,但是我想自动运行一个.

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.

我试图扩展一个Litho动画示例

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);
  }

我确认VisibleEvent没有通过以下方式触发

I confirmed the VisibleEvent didn't fire by:

  1. 加载渲染线程示例并确认动画没有开始
  2. onVisible()方法中设置断点
  1. Loading the Render Thread example and confirmed the animation didn't start
  2. Setting a breakpoint in the onVisible() method

如何自动运行Litho动画?

How can I run a Litho animation automatically?

推荐答案

我发现一个可行的解决方案是利用

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.

这篇关于如何自动运行Litho动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆