如何自动运行Litho动画? [英] How to run a Litho animation automatically?
问题描述
首次显示活动"时,启动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.
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:
- 加载渲染线程示例并确认动画没有开始
- 在
onVisible()
方法中设置断点
- Loading the Render Thread example and confirmed the animation didn't start
- 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屋!