Skip to content

Commit abd466c

Browse files
adityasharatfacebook-github-bot
authored andcommitted
Enables split layout by default
Summary: Enables split layout by default Reviewed By: pentiumao Differential Revision: D43099403 fbshipit-source-id: 9b411e90ac55aff916e35ed7cfcfb2c1c169938b
1 parent 1519baa commit abd466c

File tree

11 files changed

+58
-57
lines changed

11 files changed

+58
-57
lines changed

litho-core-kotlin/src/test/kotlin/com/facebook/litho/KCachedTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ import org.assertj.core.api.Assertions.assertThat
2727
import org.junit.Before
2828
import org.junit.Test
2929
import org.junit.runner.RunWith
30+
import org.robolectric.annotation.LooperMode
3031

3132
/** Unit tests for [useCached]. */
3233
@Suppress("MagicNumber")
3334
@RunWith(LithoTestRunner::class)
35+
@LooperMode(LooperMode.Mode.LEGACY)
3436
class KCachedTest {
3537

3638
private lateinit var context: ComponentContext

litho-core/src/main/java/com/facebook/litho/BUCK

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ load(
1010
"LITHO_ANDROIDSUPPORT_TARGET",
1111
"LITHO_ANNOTATIONS_TARGET",
1212
"LITHO_CONFIG_TARGET",
13-
"LITHO_DEBUG_UTILS",
1413
"LITHO_INFERANNOTATIONS_TARGET",
1514
"LITHO_JSR_TARGET",
1615
"LITHO_PERFBOOST_TARGET",
@@ -67,7 +66,6 @@ litho_android_library(
6766
LITHO_STATS_TARGET,
6867
LITHO_VIEWCOMPAT_TARGET,
6968
LITHO_YOGA_FACTORY_TARGET,
70-
LITHO_DEBUG_UTILS,
7169
],
7270
exported_deps = [
7371
LITHO_ANNOTATIONS_TARGET,

litho-core/src/main/java/com/facebook/litho/ComponentTree.java

+32-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
import static com.facebook.litho.ThreadUtils.assertMainThread;
3838
import static com.facebook.litho.ThreadUtils.isMainThread;
3939
import static com.facebook.litho.config.ComponentsConfiguration.DEFAULT_BACKGROUND_THREAD_PRIORITY;
40-
import static com.facebook.litho.debugutils.LayoutCalculationDebugUtilsKt.flash;
4140
import static com.facebook.rendercore.instrumentation.HandlerInstrumenter.instrumentHandler;
4241

4342
import android.content.Context;
43+
import android.graphics.Color;
44+
import android.graphics.drawable.Drawable;
45+
import android.graphics.drawable.PaintDrawable;
4446
import android.os.Handler;
4547
import android.os.HandlerThread;
4648
import android.os.Looper;
@@ -1125,7 +1127,7 @@ public boolean isReconciliationEnabled() {
11251127
return mLithoConfiguration.isReconciliationEnabled;
11261128
}
11271129

1128-
synchronized @Nullable Component getRoot() {
1130+
public synchronized @Nullable Component getRoot() {
11291131
return mRoot;
11301132
}
11311133

@@ -1180,6 +1182,19 @@ private void preAllocateMountContent(boolean shouldPreallocatePerMountSpec) {
11801182
}
11811183
}
11821184

1185+
public void setRootSync(@Nullable Component root) {
1186+
setRootAndSizeSpecAndWrapper(
1187+
root,
1188+
SIZE_UNINITIALIZED,
1189+
SIZE_UNINITIALIZED,
1190+
false /* isAsync */,
1191+
null /* output */,
1192+
CalculateLayoutSource.SET_ROOT_SYNC,
1193+
INVALID_LAYOUT_VERSION,
1194+
null,
1195+
null);
1196+
}
1197+
11831198
public void setRootAsync(@Nullable Component root) {
11841199
setRootAndSizeSpecAndWrapper(
11851200
root,
@@ -2980,6 +2995,21 @@ EventHandlersController getEventHandlersController() {
29802995
return mTreeState.getEventHandlersController();
29812996
}
29822997

2998+
private static void flash(View view) {
2999+
Drawable d = new PaintDrawable(Color.RED);
3000+
d.setAlpha(128);
3001+
view.post(
3002+
() -> {
3003+
d.setBounds(0, 0, view.getWidth(), view.getHeight());
3004+
view.getOverlay().add(d);
3005+
view.postDelayed(
3006+
() -> {
3007+
view.getOverlay().remove(d);
3008+
},
3009+
500);
3010+
});
3011+
}
3012+
29833013
class LayoutStateFuture extends TreeFuture<LayoutState> {
29843014
private final Object loggerMutex = new Object();
29853015
private final ComponentContext context;

litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public static boolean isRenderInfoDebuggingEnabled() {
219219
* LithoResolutionResult, which will allow subsequent layouts to reuse that result to produce a
220220
* LayoutState.
221221
*/
222-
public static boolean isResolveAndLayoutFuturesSplitEnabled = false;
222+
public static boolean isResolveAndLayoutFuturesSplitEnabled = true;
223223

224224
/**
225225
* When enabled, and coupled with isResolveAndLayoutFuturesSplitEnabled being enabled, split
@@ -241,7 +241,7 @@ public static boolean isSplitResolveAndLayoutWithSplitHandlers() {
241241
return isResolveAndLayoutFuturesSplitEnabled && useSeparateThreadHandlersForResolveAndLayout;
242242
}
243243

244-
public static boolean reuseLastMeasuredNodeInComponentMeasure = false;
244+
public static boolean reuseLastMeasuredNodeInComponentMeasure = true;
245245

246246
public static boolean shouldCompareCommonPropsInIsEquivalentTo = false;
247247

litho-core/src/main/java/com/facebook/litho/debugutils/BUCK

-10
This file was deleted.

litho-core/src/main/java/com/facebook/litho/debugutils/LayoutCalculationDebugUtils.kt

-31
This file was deleted.

litho-it/src/test/java/com/facebook/litho/SplitFuturesTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,11 @@ public void testSyncRenderContinuesAsyncOnMainThread() {
804804
return;
805805
}
806806

807+
// This isn't written to run without early interruption
808+
if (!ComponentsConfiguration.isInterruptEarlyWithSplitFuturesEnabled) {
809+
return;
810+
}
811+
807812
final ComponentContext c = mLegacyLithoViewRule.context;
808813

809814
final RenderAndMeasureCounter counter = new RenderAndMeasureCounter();

litho-testing/src/main/java/com/facebook/litho/testing/api/LithoRule.kt

+13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import com.facebook.litho.Component
2424
import com.facebook.litho.ComponentContext
2525
import com.facebook.litho.ComponentTree
2626
import com.facebook.litho.LithoView
27+
import com.facebook.litho.config.ComponentsConfiguration
2728
import com.facebook.litho.testing.BaseThreadLooperController
29+
import com.facebook.litho.testing.ResolveAndLayoutThreadLooperController
2830
import com.facebook.litho.testing.ThreadLooperController
2931
import org.junit.rules.TestRule
3032
import org.junit.runner.Description
@@ -41,6 +43,7 @@ class LithoRule : TestRule, TestNodeSelectionProvider {
4143
override fun apply(statement: Statement, description: Description): Statement =
4244
object : Statement() {
4345
override fun evaluate() {
46+
ensureThreadLooperType()
4447
try {
4548
componentContext = ComponentContext(getApplicationContext<Context>())
4649
threadLooperController.init()
@@ -95,6 +98,16 @@ class LithoRule : TestRule, TestNodeSelectionProvider {
9598
shadowOf(Looper.getMainLooper()).idle()
9699
}
97100

101+
private fun ensureThreadLooperType() {
102+
if (ComponentsConfiguration.isSplitResolveAndLayoutWithSplitHandlers() &&
103+
threadLooperController is ThreadLooperController) {
104+
threadLooperController = ResolveAndLayoutThreadLooperController()
105+
} else if (!ComponentsConfiguration.isSplitResolveAndLayoutWithSplitHandlers() &&
106+
threadLooperController is ResolveAndLayoutThreadLooperController) {
107+
threadLooperController = ThreadLooperController()
108+
}
109+
}
110+
98111
companion object {
99112
private val DEFAULT_WIDTH_SPEC: Int =
100113
View.MeasureSpec.makeMeasureSpec(1080, View.MeasureSpec.EXACTLY)

litho-testing/src/main/java/com/facebook/litho/testing/testrunner/SplitBuildAndLayoutTestRunConfiguration.java

-10
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,17 @@
2121

2222
public class SplitBuildAndLayoutTestRunConfiguration implements LithoTestRunConfiguration {
2323

24-
private final boolean defaultReuseLastMeasuredNodeInComponentMeasure =
25-
ComponentsConfiguration.reuseLastMeasuredNodeInComponentMeasure;
26-
private final boolean defaultIsSplitFuturesEnabled =
27-
ComponentsConfiguration.isResolveAndLayoutFuturesSplitEnabled;
2824
private final boolean defaultIsInterruptEarlyEnabled =
2925
ComponentsConfiguration.isInterruptEarlyWithSplitFuturesEnabled;
3026

3127
@Override
3228
public void beforeTest(FrameworkMethod method) {
33-
ComponentsConfiguration.reuseLastMeasuredNodeInComponentMeasure =
34-
!defaultReuseLastMeasuredNodeInComponentMeasure;
35-
ComponentsConfiguration.isResolveAndLayoutFuturesSplitEnabled = !defaultIsSplitFuturesEnabled;
3629
ComponentsConfiguration.isInterruptEarlyWithSplitFuturesEnabled =
3730
!defaultIsInterruptEarlyEnabled;
3831
}
3932

4033
@Override
4134
public void afterTest(FrameworkMethod method) {
42-
ComponentsConfiguration.reuseLastMeasuredNodeInComponentMeasure =
43-
defaultReuseLastMeasuredNodeInComponentMeasure;
44-
ComponentsConfiguration.isResolveAndLayoutFuturesSplitEnabled = defaultIsSplitFuturesEnabled;
4535
ComponentsConfiguration.isInterruptEarlyWithSplitFuturesEnabled =
4636
defaultIsInterruptEarlyEnabled;
4737
}

litho-testing/src/test/java/com/facebook/litho/testing/api/DebugLogTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ import org.assertj.core.api.Assertions
3535
import org.junit.Rule
3636
import org.junit.Test
3737
import org.junit.runner.RunWith
38+
import org.robolectric.annotation.LooperMode
3839

3940
@RunWith(LithoTestRunner::class)
41+
@LooperMode(LooperMode.Mode.LEGACY)
4042
class DebugLogTest : RunWithDebugInfoTest() {
4143

4244
@get:Rule val rule: LithoRule = LithoRule()

litho-testing/src/test/java/com/facebook/litho/testing/api/NodeResolutionWithAssertionsTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ import com.facebook.litho.widget.collection.LazyList
3333
import org.junit.Rule
3434
import org.junit.Test
3535
import org.junit.runner.RunWith
36+
import org.robolectric.annotation.LooperMode
3637

3738
/**
3839
* The goal of this set of tests is just to be a health check that basic scenarios of the nodes
3940
* resolution and verification are working.
4041
*/
4142
@RunWith(LithoTestRunner::class)
43+
@LooperMode(LooperMode.Mode.LEGACY)
4244
class NodeResolutionWithAssertionsTest : RunWithDebugInfoTest() {
4345

4446
@get:Rule val rule: LithoRule = LithoRule()

0 commit comments

Comments
 (0)