public class LithoViewRule extends Object
LithoView
, ComponentTree
, width, and height specs.
@RunWith(LithoTestRunner.class)
public class LithoSampleTest {
public final @Rule LithoViewRule mLithoViewRule = new LithoViewRule();
@Test
public void test() {
final ComponentContext c = mLithoViewRule.getContext();
final Component component = MyComponent.create(c).build();
mLithoViewRule.setRoot(component)
.attachToWindow()
.setRoot(component)
.measure()
.layout();
LithoView lithoView = mLithoViewRule.getLithoView();
// Test your assertions on the litho view.
}
}
}
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_HEIGHT_SPEC |
static int |
DEFAULT_WIDTH_SPEC |
Constructor and Description |
---|
LithoViewRule() |
Modifier and Type | Method and Description |
---|---|
Statement |
apply(Statement base,
Description description) |
LithoViewRule |
attachToWindow()
Explicitly attaches current root
LithoView |
LithoViewRule |
detachFromWindow()
Explicitly detaches current root
LithoView |
View |
findViewWithTag(Object tag)
Finds the first
View with the specified tag in the rendered hierarchy. |
protected LayoutState |
getCommittedLayoutState() |
ComponentTree |
getComponentTree()
Gets the current
ComponentTree ; creates a new instance if null . |
ComponentContext |
getContext()
Gets the current
ComponentContext . |
protected InternalNode |
getCurrentRootNode() |
int |
getHeightSpec()
Gets the current height spec
|
LithoView |
getLithoView()
Gets the current
LithoView ; creates a new instance if null . |
int |
getWidthSpec()
Gets the current width spec
|
LithoViewRule |
layout()
Explicitly calls layout on the current root
LithoView |
LithoViewRule |
measure()
Explicitly calls measure on the current root
LithoView |
LithoViewRule |
release()
Explicitly releases current root
LithoView |
LithoViewRule |
setRoot(Component.Builder builder)
Sets the new root
Component.Builder to render. |
LithoViewRule |
setRoot(Component component)
Sets the new root
Component to render. |
LithoViewRule |
setRootAndSizeSpec(Component component,
int widthSpec,
int heightSpec)
Sets the new root
Component with new size spec to render. |
LithoViewRule |
setRootAsync(Component.Builder builder)
Sets the new root
Component.Builder to render asynchronously. |
LithoViewRule |
setRootAsync(Component component)
Sets the new root
Component to render asynchronously. |
LithoViewRule |
setSizePx(int widthPx,
int heightPx)
Sets a new width and height which should be used to render.
|
LithoViewRule |
setSizeSpecs(int widthSpec,
int heightSpec)
Sets a new width spec and height spec which should be used to render.
|
LithoViewRule |
setTreeProp(Class<?> klass,
Object instance)
Sets a new
TreeProp for the next layout pass. |
LithoViewRule |
useComponentTree(ComponentTree componentTree)
Sets a new
ComponentTree which should be used to render. |
LithoViewRule |
useLithoView(LithoView lithoView)
Sets a new
LithoView which should be used to render. |
public static final int DEFAULT_WIDTH_SPEC
public static final int DEFAULT_HEIGHT_SPEC
public Statement apply(Statement base, Description description)
public ComponentContext getContext()
ComponentContext
.public LithoView getLithoView()
LithoView
; creates a new instance if null
.public LithoViewRule useLithoView(LithoView lithoView)
LithoView
which should be used to render.public ComponentTree getComponentTree()
ComponentTree
; creates a new instance if null
.public LithoViewRule useComponentTree(ComponentTree componentTree)
ComponentTree
which should be used to render.public LithoViewRule setRoot(Component component)
Component
to render.public LithoViewRule setRoot(Component.Builder builder)
Component.Builder
to render.public LithoViewRule setRootAsync(Component component)
Component
to render asynchronously.public LithoViewRule setRootAsync(Component.Builder builder)
Component.Builder
to render asynchronously.public LithoViewRule setRootAndSizeSpec(Component component, int widthSpec, int heightSpec)
Component
with new size spec to render.public LithoViewRule setSizePx(int widthPx, int heightPx)
public LithoViewRule setSizeSpecs(int widthSpec, int heightSpec)
public LithoViewRule setTreeProp(Class<?> klass, Object instance)
TreeProp
for the next layout pass.public LithoViewRule measure()
LithoView
public LithoViewRule layout()
LithoView
public LithoViewRule attachToWindow()
LithoView
public LithoViewRule detachFromWindow()
LithoView
public LithoViewRule release()
LithoView
public int getWidthSpec()
public int getHeightSpec()
public View findViewWithTag(Object tag)
View
with the specified tag in the rendered hierarchy.protected LayoutState getCommittedLayoutState()
protected InternalNode getCurrentRootNode()