问题
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:
- Loading the Render Thread example and confirmed the animation didn't start
- 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