Skip to content

Commit

Permalink
Fixes content pooling for Litho on RenderCore
Browse files Browse the repository at this point in the history
Summary:
This diff fixes content pooling for RenderCore.

The pools should be keyed with `RenderUnit#getRenderContentType()` but were being keyed with `RenderUnit#getClass()`.

Reviewed By: mihaelao

Differential Revision: D23215571

fbshipit-source-id: f751f1c19473018abf10d03d2b22844345028f5c
  • Loading branch information
adityasharat authored and facebook-github-bot committed Aug 20, 2020
1 parent 7c37756 commit ed9aa28
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public long getId() {
return output.getId();
}

@Override
public Object getRenderContentType() {
return output.getComponent().getClass();
}

private boolean hasDefaultViewAttributeFlags() {
return mDefaultViewAttributeFlags != -1;
}
Expand Down
81 changes: 81 additions & 0 deletions litho-it/src/test/java/com/facebook/litho/MountStateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import static org.assertj.core.api.Java6Assertions.assertThat;

import android.graphics.Color;
import android.view.View;
import com.facebook.litho.config.ComponentsConfiguration;
import com.facebook.litho.testing.LithoViewRule;
import com.facebook.litho.testing.testrunner.LithoTestRunner;
import com.facebook.litho.widget.DynamicPropsComponentTester;
import com.facebook.litho.widget.Progress;
import com.facebook.litho.widget.SolidColor;
import com.facebook.litho.widget.TextInput;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -123,4 +126,82 @@ public void onSetRootWithNoOutputsWithRenderCore_shouldSuccessfullyCompleteMount
ComponentsConfiguration.useExtensionsWithMountDelegate = useExtensions;
ComponentsConfiguration.useIncrementalMountExtension = incrementalMountExtension;
}

@Test
public void onSetRootWithSimilarComponent_MountContentShouldUsePools() {
final boolean delegateToRenderCoreMount = ComponentsConfiguration.delegateToRenderCoreMount;
final boolean useExtensions = ComponentsConfiguration.useExtensionsWithMountDelegate;
final boolean incrementalMountExtension = ComponentsConfiguration.useIncrementalMountExtension;

ComponentsConfiguration.delegateToRenderCoreMount = true;
ComponentsConfiguration.useExtensionsWithMountDelegate = true;
ComponentsConfiguration.useIncrementalMountExtension = true;

final Component root =
Column.create(mContext)
.child(TextInput.create(mContext).widthDip(100).heightDip(100))
.build();

mLithoViewRule
.setRoot(root)
.attachToWindow()
.setSizeSpecs(makeSizeSpec(1000, EXACTLY), makeSizeSpec(1000, EXACTLY))
.measure()
.layout();

View view = mLithoViewRule.getLithoView().getChildAt(0);

final Component newRoot =
Row.create(mContext)
.child(TextInput.create(mContext).initialText("testing").widthDip(120).heightDip(120))
.build();

mLithoViewRule
.setRoot(newRoot)
.setSizeSpecs(makeSizeSpec(1000, EXACTLY), makeSizeSpec(1000, EXACTLY));

View newView = mLithoViewRule.getLithoView().getChildAt(0);

assertThat(newView).isSameAs(view);

ComponentsConfiguration.delegateToRenderCoreMount = delegateToRenderCoreMount;
ComponentsConfiguration.useExtensionsWithMountDelegate = useExtensions;
ComponentsConfiguration.useIncrementalMountExtension = incrementalMountExtension;
}

@Test
public void onSetRootWithDifferentComponent_MountContentPoolsShouldNoCollide() {
final boolean delegateToRenderCoreMount = ComponentsConfiguration.delegateToRenderCoreMount;
final boolean useExtensions = ComponentsConfiguration.useExtensionsWithMountDelegate;
final boolean incrementalMountExtension = ComponentsConfiguration.useIncrementalMountExtension;

ComponentsConfiguration.delegateToRenderCoreMount = true;
ComponentsConfiguration.useExtensionsWithMountDelegate = true;
ComponentsConfiguration.useIncrementalMountExtension = true;

final Component root =
Column.create(mContext)
.child(TextInput.create(mContext).widthDip(100).heightDip(100))
.build();

mLithoViewRule
.setRoot(root)
.attachToWindow()
.setSizeSpecs(makeSizeSpec(1000, EXACTLY), makeSizeSpec(1000, EXACTLY))
.measure()
.layout();

final Component newRoot =
Column.create(mContext)
.child(Progress.create(mContext).widthDip(100).heightDip(100))
.build();

mLithoViewRule
.setRoot(newRoot)
.setSizeSpecs(makeSizeSpec(1000, EXACTLY), makeSizeSpec(1000, EXACTLY));

ComponentsConfiguration.delegateToRenderCoreMount = delegateToRenderCoreMount;
ComponentsConfiguration.useExtensionsWithMountDelegate = useExtensions;
ComponentsConfiguration.useIncrementalMountExtension = incrementalMountExtension;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static Object acquireMountContent(Context context, RenderUnit renderUnit) {
}

static void release(Context context, RenderUnit renderUnit, Object mountContent) {
final Pools.SimplePool pool = getMountContentPool(context, renderUnit.getClass());
final Pools.SimplePool pool = getMountContentPool(context, renderUnit.getRenderContentType());
if (pool != null) {
pool.release(mountContent);
}
Expand All @@ -98,7 +98,7 @@ static void release(Context context, RenderUnit renderUnit, Object mountContent)
Pools.SimplePool pool = poolsMap.get(lifecycle);
if (pool == null) {
pool = new Pools.SimplePool(DEFAULT_POOL_SIZE);
poolsMap.put(lifecycle.getClass(), pool);
poolsMap.put(lifecycle, pool);
}

return pool;
Expand Down

0 comments on commit ed9aa28

Please sign in to comment.