Skip to content

Commit

Permalink
Remove ComponentLifecycle#createLayout
Browse files Browse the repository at this point in the history
Summary: Remove `ComponentLifecycle#createLayout` and replace its usage with `LayoutState.createLayout`

Reviewed By: astreet

Differential Revision: D16802422

fbshipit-source-id: 1e247ff39f6bd483ba939f788a626ae4e59e193d
  • Loading branch information
adityasharat authored and facebook-github-bot committed Aug 14, 2019
1 parent 3b0cb7e commit fb0d287
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,8 @@ InternalNode newLayoutBuilder(
DebugComponent.applyOverrides(this, component);
}

final InternalNode node;
if (ComponentsConfiguration.isRefactoredLayoutCreationEnabled) {
node = LayoutState.createLayout(component.getScopedContext(), component, false);
} else {
node = component.createLayout(component.getScopedContext(), false);
}

final InternalNode node =
LayoutState.createLayout(component.getScopedContext(), component, false);
if (node != NULL_LAYOUT) {
applyStyle(node, defStyleAttr, defStyleRes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,18 +290,6 @@ void unmount(ComponentContext c, Object mountedContent) {
onUnmount(c, mountedContent);
}

/**
* Create a layout from the given component.
*
* @param context ComponentContext associated with the current ComponentTree.
* @param resolveNestedTree if the component's layout tree should be resolved as part of this
* call.
* @return New InternalNode associated with the given component.
*/
InternalNode createLayout(ComponentContext context, boolean resolveNestedTree) {
return LayoutState.createLayout(context, (Component) this, resolveNestedTree);
}

final @Nullable Transition createTransition(ComponentContext c) {
final Transition transition = onCreateTransition(c);
if (transition != null) {
Expand Down Expand Up @@ -401,7 +389,7 @@ protected Component onCreateLayoutWithSizeSpec(

/** Resolves the {@link ComponentLayout} for the given {@link Component}. */
protected ComponentLayout resolve(ComponentContext c) {
return createLayout(c, false);
return LayoutState.createLayout(c, (Component) this, false);
}

protected void onPrepare(ComponentContext c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ public boolean isLayoutDirectionInherit() {

/**
* @return Whether this node is holding a nested tree or not. The decision was made during tree
* creation {@link ComponentLifecycle#createLayout(ComponentContext, boolean)}.
* creation {@link LayoutState#createLayout(ComponentContext, Component, boolean)}.
*/
@Override
public boolean isNestedTreeHolder() {
Expand Down Expand Up @@ -1895,11 +1895,7 @@ private static InternalNode reconcile(
layout = reconcile(c, current, next, keys, ReconciliationMode.RECONCILE);
break;
case ReconciliationMode.RECREATE:
if (ComponentsConfiguration.isRefactoredLayoutCreationEnabled) {
layout = LayoutState.createLayout(next.getScopedContext(), next, false);
} else {
layout = next.createLayout(next.getScopedContext(), false);
}
layout = LayoutState.createLayout(next.getScopedContext(), next, false);
break;
default:
throw new IllegalArgumentException(mode + " is not a valid ReconciliationMode");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ InternalNode fullImpressionHandler(

/**
* @return Whether this node is holding a nested tree or not. The decision was made during tree
* creation {@link ComponentLifecycle#createLayout(ComponentContext, boolean)}.
* creation {@link LayoutState#createLayout(ComponentContext, Component, boolean)}.
*/
boolean isNestedTreeHolder();

Expand Down
6 changes: 1 addition & 5 deletions litho-core/src/main/java/com/facebook/litho/LayoutState.java
Original file line number Diff line number Diff line change
Expand Up @@ -1602,11 +1602,7 @@ static InternalNode createTree(
return current.reconcile(context, component);
}

if (ComponentsConfiguration.isRefactoredLayoutCreationEnabled) {
return createLayout(context, component, true /* resolveNestedTree */);
} else {
return component.createLayout(context, true /* resolveNestedTree */);
}
return createLayout(context, component, true /* resolveNestedTree */);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void after() {
@Test
public void testCreateLayoutWithNullComponentWithLayoutSpecCannotMeasure() {
Component component = setUpSpyLayoutSpecWithNullLayout();
component.createLayout(mContext, false);
LayoutState.createLayout(mContext, component, false);

verify(component).onCreateLayout(mContext);
verify(component, never()).onPrepare(mContext);
Expand All @@ -128,7 +128,7 @@ public void testCreateLayoutWithNullComponentWithLayoutSpecCannotMeasure() {
@Test
public void testCreateLayoutWithNullComponentWithLayoutSpecCanMeasure() {
Component component = setUpSpyLayoutSpecWithNullLayout();
component.createLayout(mContext, false);
LayoutState.createLayout(mContext, component, false);

verify(component).onCreateLayout(mContext);
verify(component, never()).onPrepare(mContext);
Expand All @@ -137,7 +137,7 @@ public void testCreateLayoutWithNullComponentWithLayoutSpecCanMeasure() {
@Test
public void testCreateLayoutWithNullComponentWithMountSpecCannotMeasure() {
Component component = setUpSpyLayoutSpecWithNullLayout();
component.createLayout(mContext, false);
LayoutState.createLayout(mContext, component, false);

verify(component).onCreateLayout(mContext);
verify(component, never()).onPrepare(mContext);
Expand All @@ -146,7 +146,7 @@ public void testCreateLayoutWithNullComponentWithMountSpecCannotMeasure() {
@Test
public void testCreateLayoutWithNullComponentWithMountSpecCanMeasure() {
Component component = setUpSpyLayoutSpecWithNullLayout();
component.createLayout(mContext, false);
LayoutState.createLayout(mContext, component, false);

verify(component).onCreateLayout(mContext);
verify(component, never()).onPrepare(mContext);
Expand All @@ -157,7 +157,7 @@ public void testCreateLayoutAndResolveNestedTreeWithMountSpecCannotMeasure() {
Component component = setUpSpyComponentForCreateLayout(
true /* isMountSpec */,
false /* canMeasure */);
InternalNode node = component.createLayout(mContext, true);
InternalNode node = LayoutState.createLayout(mContext, component, true);

verify(component).onCreateLayout(mContext);
verify(node).appendComponent(component);
Expand All @@ -170,7 +170,7 @@ public void testCreateLayoutAndDontResolveNestedTreeWithMountSpecCannotMeasure()
Component component = setUpSpyComponentForCreateLayout(
true /* isMountSpec */,
false /* canMeasure */);
InternalNode node = component.createLayout(mContext, false);
InternalNode node = LayoutState.createLayout(mContext, component, false);

verify(component).onCreateLayout(mContext);
verify(node).appendComponent(component);
Expand All @@ -183,7 +183,7 @@ public void testCreateLayoutAndResolveNestedTreeWithMountSpecCanMeasure() {
Component component = setUpSpyComponentForCreateLayout(
true /* isMountSpec */,
true /* canMeasure */);
InternalNode node = component.createLayout(mContext, true);
InternalNode node = LayoutState.createLayout(mContext, component, true);

verify(component).onCreateLayout(mContext);
verify(node).appendComponent(component);
Expand All @@ -196,7 +196,7 @@ public void testCreateLayoutAndDontResolveNestedTreeWithMountSpecCanMeasure() {
Component component = setUpSpyComponentForCreateLayout(
true /* isMountSpec */,
true /* canMeasure */);
InternalNode node = component.createLayout(mContext, false);
InternalNode node = LayoutState.createLayout(mContext, component, false);

verify(component).onCreateLayout(mContext);
verify(node).appendComponent(component);
Expand All @@ -209,7 +209,7 @@ public void testCreateLayoutAndResolveNestedTreeWithLayoutSpecCannotMeasure() {
Component component = setUpSpyComponentForCreateLayout(
false /* isMountSpec */,
false /* canMeasure */);
InternalNode node = component.createLayout(mContext, true);
InternalNode node = LayoutState.createLayout(mContext, component, true);

verify(component).onCreateLayout(mContext);
verify(node).appendComponent(component);
Expand All @@ -222,7 +222,7 @@ public void testCreateLayoutAndDontResolveNestedTreeWithLayoutSpecCannotMeasure(
Component component = setUpSpyComponentForCreateLayout(
false /* isMountSpec */,
false /* canMeasure */);
InternalNode node = component.createLayout(mContext, false);
InternalNode node = LayoutState.createLayout(mContext, component, false);

verify(component).onCreateLayout(mContext);
verify(node).appendComponent(component);
Expand All @@ -237,7 +237,7 @@ public void testCreateLayoutAndResolveNestedTreeWithLayoutSpecCanMeasure() {
true /* canMeasure */);
mContext.setWidthSpec(mNestedTreeWidthSpec);
mContext.setHeightSpec(mNestedTreeHeightSpec);
InternalNode node = component.createLayout(mContext, true);
InternalNode node = LayoutState.createLayout(mContext, component, true);

verify(component).onCreateLayoutWithSizeSpec(
mContext,
Expand All @@ -253,7 +253,7 @@ public void testCreateLayoutAndDontResolveNestedTreeWithLayoutSpecCanMeasure() {
Component component = setUpSpyComponentForCreateLayout(
false /* isMountSpec */,
true /* canMeasure */);
InternalNode node = component.createLayout(mContext, false);
InternalNode node = LayoutState.createLayout(mContext, component, false);

verify(component, never()).onCreateLayout(
any(ComponentContext.class));
Expand Down Expand Up @@ -282,7 +282,7 @@ public void testOnShouldCreateLayoutWithNewSizeSpec_FirstCall() {
.isLayoutSpecWithSizeSpecCheck(true)
.build(mContext);

component.createLayout(mContext, true);
LayoutState.createLayout(mContext, component, true);

// onShouldCreateLayoutWithNewSizeSpec should not be called the first time
verify(component, never())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import android.util.SparseArray;
import android.view.accessibility.AccessibilityManager;
import androidx.annotation.Nullable;
import com.facebook.litho.config.ComponentsConfiguration;
import com.facebook.litho.testing.TestComponent;
import com.facebook.litho.testing.TestDrawableComponent;
import com.facebook.litho.testing.TestLayoutComponent;
Expand Down Expand Up @@ -2686,7 +2685,7 @@ public void testCreateLayoutUsesWillRenderResult() {
final InternalNode cachedLayout = component.getLayoutCreatedInWillRenderForTesting();
assertThat(cachedLayout).isNotNull();

InternalNode result = component.createLayout(c, false);
InternalNode result = LayoutState.createLayout(c, component, false);
assertThat(result).isEqualTo(cachedLayout);
assertThat(component.getLayoutCreatedInWillRenderForTesting()).isNull();
}
Expand Down

0 comments on commit fb0d287

Please sign in to comment.