Java Code Examples for com.facebook.litho.LithoView#measure()
The following examples show how to use
com.facebook.litho.LithoView#measure() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentTestHelper.java From litho with Apache License 2.0 | 5 votes |
/** * Mount a component tree into a component view. * * @param lithoView The view to mount the component tree into * @param componentTree The component tree to mount * @param widthSpec The width spec used to measure the resulting view * @param heightSpec The height spec used to measure the resulting view * @return A LithoView with the component tree mounted in it. */ public static LithoView mountComponent( LithoView lithoView, ComponentTree componentTree, int widthSpec, int heightSpec) { final boolean addParent = lithoView.getParent() == null; final ViewGroup parent = new ViewGroup(lithoView.getContext()) { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) {} }; if (addParent) { parent.addView(lithoView); } lithoView.setComponentTree(componentTree); try { Whitebox.invokeMethod(lithoView, "onAttach"); } catch (Exception e) { throw new RuntimeException(e); } lithoView.measure(widthSpec, heightSpec); if (addParent) { parent.layout(0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight()); } lithoView.layout(0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight()); return lithoView; }
Example 2
Source File: AnimationTest.java From litho with Apache License 2.0 | 5 votes |
@Test public void animationTransitionsExtension_reUsingLithoViewWithDifferentComponentTrees_shouldNotCrash() { final boolean useExtensionsWithMountDelegate = ComponentsConfiguration.useExtensionsWithMountDelegate; ComponentsConfiguration.useExtensionsWithMountDelegate = true; ComponentContext componentContext = new ComponentContext(RuntimeEnvironment.application); mLithoViewRule.setRoot(getNonAnimatingComponent()); // We measure and layout this non animating component to initialize the transition extension. mLithoViewRule.measure().layout(); // We need an other litho view where we are going to measure and layout an other similar tree // (the real difference here is that the root components are not animating) LithoView lithoView = new LithoView(componentContext); ComponentTree nonAnimatingComponentTree = ComponentTree.create(componentContext).build(); nonAnimatingComponentTree.setRoot(getNonAnimatingComponent()); lithoView.setComponentTree(nonAnimatingComponentTree); lithoView.measure(LithoViewRule.DEFAULT_WIDTH_SPEC, LithoViewRule.DEFAULT_HEIGHT_SPEC); lithoView.layout(0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight()); // Now we need a new component tree that will hold a component tree that holds an animating root // component. ComponentTree animatingComponentTree = ComponentTree.create(componentContext).build(); animatingComponentTree.setRoot(getAnimatingXPropertyComponent()); mLithoViewRule.useComponentTree(animatingComponentTree); // We measure this component tree so we initialize the mRootTransition in the extension, but we // end up not running a layout here. mLithoViewRule.measure(); // Finally we set a new animating component tree to the initial litho view and run measure and // layout. mLithoViewRule.useComponentTree(nonAnimatingComponentTree); mLithoViewRule.measure().layout(); // Should not crash. ComponentsConfiguration.useExtensionsWithMountDelegate = useExtensionsWithMountDelegate; }
Example 3
Source File: TreePropTest.java From litho with Apache License 2.0 | 5 votes |
/** * Tests that a TreeProp is propagated down a Component Tree, is scoped correctly, and can be * overwritten. */ @Test public void testTreePropsPropagated() { final TreePropTestResult propALeaf1 = new TreePropTestResult(); final TreePropTestResult propBLeaf1 = new TreePropTestResult(); final TreePropTestResult probBLeaf2 = new TreePropTestResult(); final TreePropTestResult propAMount = new TreePropTestResult(); final TreePropNumberType treePropA = new TreePropNumberType(9); final TreePropStringType treePropB = new TreePropStringType("propB"); final TreePropStringType treePropBChanged = new TreePropStringType("propB_changed"); Component component = TreePropTestParent.create(mContext) .propA(treePropA) .propB(treePropB) .resultPropALeaf1(propALeaf1) .resultPropBLeaf1(propBLeaf1) .resultPropBLeaf2(probBLeaf2) .resultPropAMount(propAMount) .build(); LithoView lithoView = new LithoView(mContext); lithoView.setComponent(component); lithoView.measure(makeMeasureSpec(1000, EXACTLY), makeMeasureSpec(0, UNSPECIFIED)); assertThat(propALeaf1.mProp).isEqualTo(treePropA); // TreePropTestMiddleSpec modifies "propB". assertThat(propBLeaf1.mProp).isEqualTo(treePropBChanged); // The second LeafSpec does not see the modification to "propB" // because its not a descendant of MiddleSpec. assertThat(probBLeaf2.mProp).isEqualTo(treePropB); assertThat(propAMount.mProp).isEqualTo(treePropA); }
Example 4
Source File: ProgressSpecTest.java From litho with Apache License 2.0 | 5 votes |
@Test public void testUnsetSize() { LithoView view = getMountedView(); view.measure( View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); assertThat(view.getMeasuredWidth()).isEqualTo(ProgressSpec.DEFAULT_SIZE); assertThat(view.getMeasuredHeight()).isEqualTo(ProgressSpec.DEFAULT_SIZE); }