canUpdateLazily
Declares that this state can be updated lazily and that will not trigger a new layout calculations. After a lazy state update the component will continue to host the older value until the next layout calculation is preformed. This is useful for updating internal Component information and persisting it between re-layouts when an immediate layout calculation is not needed or when this state is not involved into layout calculation at all.
Note: Such state can still participate in normal state update via methods, but for lazy state updates an additional lazyUpdate*StateName*
method will be generated.
Warning: For now, lazily updated values will be available only in OnEvent methods (or after a normal state update). If you need support of other lifecycle methods, feel free to file an issue.
Using State:
@LayoutSpec
public class MyComponentSpec {
@OnCreateLayout
static Component onCreateLayout(ComponentContext c) {
return Column.create(c)
.child(
Text.create(c)
.backgroundRes(R.drawable.button_background)
.textSizeSp(20)
.text("Submit")
.clickHandler(MyComponent.onClick(c)))
.build();
}
@OnEvent(ClickEvent.class)
static void onClick(ComponentContext c, @State(canUpdateLazily = true) boolean wasAlreadyClicked) {
if (!wasAlreadyClicked) {
logFirstButtonClick();
}
MyComponent.lazyUpdateWasAlreadyClicked(c, true);
}
}
Return
true
if this state can be updated lazily.