diff --git a/litho-core/src/main/java/com/facebook/litho/BaseMountingView.java b/litho-core/src/main/java/com/facebook/litho/BaseMountingView.java index fafd271ab26..07dfde0897b 100644 --- a/litho-core/src/main/java/com/facebook/litho/BaseMountingView.java +++ b/litho-core/src/main/java/com/facebook/litho/BaseMountingView.java @@ -644,7 +644,7 @@ public void notifyVisibleBoundsChanged() { @Override public void onRegisterForPremount(@Nullable Long frameTime) { final @Nullable ComponentsConfiguration config = getConfiguration(); - if (config != null && config.useIncrementalMountGapWorker()) { + if (config != null && config.useIncrementalMountGapWorker) { final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection("BaseMountingView::onRegisterForPremount"); @@ -660,7 +660,7 @@ public void onRegisterForPremount(@Nullable Long frameTime) { @Override public void onUnregisterForPremount() { final @Nullable ComponentsConfiguration config = getConfiguration(); - if (config != null && config.useIncrementalMountGapWorker()) { + if (config != null && config.useIncrementalMountGapWorker) { final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection("BaseMountingView::onUnregisterForPremount"); @@ -816,7 +816,7 @@ protected void setupMountExtensions() { if (hasTree()) { if (isIncrementalMountEnabled()) { final @Nullable ComponentsConfiguration config = getConfiguration(); - boolean useGapWorker = config != null && config.useIncrementalMountGapWorker(); + boolean useGapWorker = config != null && config.useIncrementalMountGapWorker; mLithoHostListenerCoordinator.enableIncrementalMount(useGapWorker); } else { mLithoHostListenerCoordinator.disableIncrementalMount(); diff --git a/litho-core/src/main/java/com/facebook/litho/ComponentContext.java b/litho-core/src/main/java/com/facebook/litho/ComponentContext.java index dbeb88b51ae..3f71f0bf79b 100644 --- a/litho-core/src/main/java/com/facebook/litho/ComponentContext.java +++ b/litho-core/src/main/java/com/facebook/litho/ComponentContext.java @@ -767,11 +767,12 @@ public ScopedComponentInfo getScopedComponentInfo() { } boolean shouldCacheLayouts() { - return isReconciliationEnabled() && mLithoConfiguration.componentsConfig.shouldCacheLayouts(); + return isReconciliationEnabled() + && mLithoConfiguration.componentsConfig.getShouldCacheLayouts(); } public final boolean shouldUseNonRebindingEventHandlers() { - return mLithoConfiguration.componentsConfig.useNonRebindingEventHandlers(); + return mLithoConfiguration.componentsConfig.getUseNonRebindingEventHandlers(); } boolean isNestedTreeContext() { diff --git a/litho-core/src/main/java/com/facebook/litho/ComponentContextUtils.java b/litho-core/src/main/java/com/facebook/litho/ComponentContextUtils.java index a6b1419c37b..3d4a2896535 100644 --- a/litho-core/src/main/java/com/facebook/litho/ComponentContextUtils.java +++ b/litho-core/src/main/java/com/facebook/litho/ComponentContextUtils.java @@ -97,7 +97,7 @@ public static LithoConfiguration buildDefaultLithoConfiguration( @Nullable ComponentsLogger logger, int treeID) { ComponentsLogger loggerToUse = - logger != null ? logger : ComponentsConfiguration.sComponentsLogger; + logger != null ? logger : ComponentsConfiguration.componentsLogger; String logTagToUse = logTag; if (logTag == null && logger == null && loggerToUse != null) { @@ -105,7 +105,7 @@ public static LithoConfiguration buildDefaultLithoConfiguration( } return new LithoConfiguration( - ComponentsConfiguration.getDefaultComponentsConfiguration(), + ComponentsConfiguration.defaultInstance, AnimationsDebug.areTransitionsEnabled(context), ComponentsConfiguration.overrideReconciliation != null ? ComponentsConfiguration.overrideReconciliation diff --git a/litho-core/src/main/java/com/facebook/litho/ComponentTree.java b/litho-core/src/main/java/com/facebook/litho/ComponentTree.java index 68d48e701dc..3f867a35f42 100644 --- a/litho-core/src/main/java/com/facebook/litho/ComponentTree.java +++ b/litho-core/src/main/java/com/facebook/litho/ComponentTree.java @@ -2196,7 +2196,7 @@ private void doResolve( final boolean isInterruptible = !LayoutState.isFromSyncLayout(source) && (mContext.mLithoConfiguration.componentsConfig.getUseInterruptibleResolution() - || mContext.mLithoConfiguration.componentsConfig.getUseCancelableLayoutFutures()); + || mContext.mLithoConfiguration.componentsConfig.getUseCancellableLayoutFutures()); ResolveTreeFuture treeFuture = new ResolveTreeFuture( @@ -2230,7 +2230,7 @@ private void doResolve( if (resolveResult == null) { if (!isReleased() && isFromSyncLayout(source) - && !mContext.mLithoConfiguration.componentsConfig.getUseCancelableLayoutFutures()) { + && !mContext.mLithoConfiguration.componentsConfig.getUseCancellableLayoutFutures()) { final String errorMessage = "ResolveResult is null, but only async operations can return a null ResolveResult. Source: " + layoutSourceToString(source) @@ -2427,7 +2427,7 @@ private void doLayout( if (layoutState == null) { if (!isReleased() && isSync - && !mContext.mLithoConfiguration.componentsConfig.getUseCancelableLayoutFutures()) { + && !mContext.mLithoConfiguration.componentsConfig.getUseCancellableLayoutFutures()) { final String errorMessage = "LayoutState is null, but only async operations can return a null LayoutState. Source: " + layoutSourceToString(source) @@ -2834,7 +2834,7 @@ public void onErrorComponent(Component component) { * after that because it's in an incomplete state, so it needs to be released. */ public void cancelLayoutAndReleaseTree() { - if (!mContext.mLithoConfiguration.componentsConfig.getUseCancelableLayoutFutures()) { + if (!mContext.mLithoConfiguration.componentsConfig.getUseCancellableLayoutFutures()) { ComponentsReporter.emitMessage( ComponentsReporter.LogLevel.ERROR, TAG, diff --git a/litho-core/src/main/java/com/facebook/litho/LithoNode.kt b/litho-core/src/main/java/com/facebook/litho/LithoNode.kt index d37f032885b..af16d000207 100644 --- a/litho-core/src/main/java/com/facebook/litho/LithoNode.kt +++ b/litho-core/src/main/java/com/facebook/litho/LithoNode.kt @@ -1368,7 +1368,7 @@ open class LithoNode : Node, Cloneable { private fun hasSelectedStateWhenDisablingDrawableOutputs(node: LithoNode): Boolean = ComponentContext.getComponentsConfig(node.headComponentContext) - .isShouldAddHostViewForRootComponent && + .shouldAddHostViewForRootComponent && !node.willMountView && node.nodeInfo != null && node.nodeInfo?.selectedState != NodeInfo.SELECTED_UNSET @@ -1434,7 +1434,7 @@ open class LithoNode : Node, Cloneable { // tree is mounted. Click handling is also considered accessibility content but // this is already covered separately i.e. click handler is not null. val hasBackgroundOrForeground = - ComponentContext.getComponentsConfig(c).shouldAddRootHostViewOrDisableBgFgOutputs() && + ComponentContext.getComponentsConfig(c).shouldAddRootHostViewOrDisableBgFgOutputs && (node.background != null || node.foreground != null) val hasAccessibilityContent = (context?.isAccessibilityEnabled == true) && diff --git a/litho-core/src/main/java/com/facebook/litho/LithoNodeUtils.kt b/litho-core/src/main/java/com/facebook/litho/LithoNodeUtils.kt index 0bcdf4c376a..6d973b633af 100644 --- a/litho-core/src/main/java/com/facebook/litho/LithoNodeUtils.kt +++ b/litho-core/src/main/java/com/facebook/litho/LithoNodeUtils.kt @@ -324,7 +324,7 @@ object LithoNodeUtils { flags = flags or LithoRenderUnit.LAYOUT_FLAG_MATCH_HOST_BOUNDS } if (ComponentContext.getComponentsConfig(node.headComponentContext) - .shouldAddRootHostViewOrDisableBgFgOutputs()) { + .shouldAddRootHostViewOrDisableBgFgOutputs) { flags = flags or LithoRenderUnit.LAYOUT_FLAG_DRAWABLE_OUTPUTS_DISABLED } if (nodeInfo?.hasTouchEventHandlers() == true) { diff --git a/litho-core/src/main/java/com/facebook/litho/LithoReducer.kt b/litho-core/src/main/java/com/facebook/litho/LithoReducer.kt index dfefb3f9849..60cee96b434 100644 --- a/litho-core/src/main/java/com/facebook/litho/LithoReducer.kt +++ b/litho-core/src/main/java/com/facebook/litho/LithoReducer.kt @@ -91,7 +91,7 @@ object LithoReducer { var parent: RenderTreeNode? = null var hierarchy: DebugHierarchy.Node? = null - if (c.mLithoConfiguration.componentsConfig.isShouldAddHostViewForRootComponent) { + if (c.mLithoConfiguration.componentsConfig.shouldAddHostViewForRootComponent) { hierarchy = if (root is LithoLayoutResult) root.node.getDebugHierarchy() else null addRootHostRenderTreeNode(layoutState, root, hierarchy) parent = layoutState.mMountableOutputs[0] @@ -518,7 +518,7 @@ object LithoReducer { } // 2. Add background if defined. - if (!context.mLithoConfiguration.componentsConfig.shouldAddRootHostViewOrDisableBgFgOutputs()) { + if (!context.mLithoConfiguration.componentsConfig.shouldAddRootHostViewOrDisableBgFgOutputs) { result.backgroundRenderUnit?.let { backgroundRenderUnit -> val backgroundRenderTreeNode = addDrawableRenderTreeNode( @@ -607,7 +607,7 @@ object LithoReducer { } // 6. Add foreground if defined. - if (!context.mLithoConfiguration.componentsConfig.shouldAddRootHostViewOrDisableBgFgOutputs()) { + if (!context.mLithoConfiguration.componentsConfig.shouldAddRootHostViewOrDisableBgFgOutputs) { result.foregroundRenderUnit?.let { foregroundRenderUnit -> val foregroundRenderTreeNode: RenderTreeNode = addDrawableRenderTreeNode( @@ -923,7 +923,7 @@ object LithoReducer { type, unit.importantForAccessibility, layoutState.resolveResult.context.lithoConfiguration.componentsConfig - .shouldAddRootHostViewOrDisableBgFgOutputs()) + .shouldAddRootHostViewOrDisableBgFgOutputs) if (attrs != null) { layoutState.mRenderUnitsWithViewAttributes[id] = attrs diff --git a/litho-core/src/main/java/com/facebook/litho/config/BUCK b/litho-core/src/main/java/com/facebook/litho/config/BUCK index 1cc1de09710..3c91a8e3e12 100644 --- a/litho-core/src/main/java/com/facebook/litho/config/BUCK +++ b/litho-core/src/main/java/com/facebook/litho/config/BUCK @@ -34,6 +34,5 @@ litho_android_library( visibility = ["PUBLIC"], deps = [ "//fbandroid/libraries/rendercore/rendercore-incremental-mount:rendercore-incremental-mount", - "//fbandroid/third-party/java/infer-annotations:infer-annotations", ], ) diff --git a/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.java b/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.java deleted file mode 100644 index 6fedb8d5d65..00000000000 --- a/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.config; - -import static android.os.Build.VERSION.SDK_INT; -import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; -import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1; - -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.litho.BuildConfig; -import com.facebook.litho.ComponentsLogger; -import com.facebook.litho.perfboost.LithoPerfBoosterFactory; -import com.facebook.rendercore.incrementalmount.IncrementalMountExtensionConfigs; -import java.util.Set; - -/** - * Hi there, traveller! This configuration class is not meant to be used by end-users of Litho. It - * contains mainly flags for features that are either under active development and not ready for - * public consumption, or for use in experiments. - * - *

These values are safe defaults and should not require manual changes. - * - *

This class hosts all the config parameters that the ComponentTree configures it self .... - * enable and disable features ... A Component tree uses the {@link #defaultComponentsConfiguration} - * by default but a {@link Builder} can be used to create new instances of the config to override - * the default parameters ... The default config values can also be overridden by manually setting - * their values in {@link #defaultBuilder} - */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public class ComponentsConfiguration { - - /** - * Indicates whether this is an internal build. Note that the implementation of BuildConfig - * that this class is compiled against may not be the one that is included in the APK. - * See: android_build_config. - */ - public static final boolean IS_INTERNAL_BUILD = BuildConfig.IS_INTERNAL_BUILD; - - /** Indicates that the incremental mount helper is required for this build. */ - public static final boolean USE_INCREMENTAL_MOUNT_HELPER = - BuildConfig.USE_INCREMENTAL_MOUNT_HELPER; - - /** Whether we can access properties in Settings.Global for animations. */ - public static final boolean CAN_CHECK_GLOBAL_ANIMATOR_SETTINGS = (SDK_INT >= JELLY_BEAN_MR1); - - /** Whether we need to account for lack of synchronization while accessing Themes. */ - public static final boolean NEEDS_THEME_SYNCHRONIZATION = (SDK_INT <= LOLLIPOP_MR1); - - /** The default priority for threads that perform background layout calculations. */ - public static int DEFAULT_BACKGROUND_THREAD_PRIORITY = 5; - - /** The default priority for threads that perform background sections change set calculations. */ - public static final int DEFAULT_CHANGE_SET_THREAD_PRIORITY = 0; - - /** - * Option to enabled debug mode. This will save extra data associated with each node and allow - * more info about the hierarchy to be retrieved. Used to enable stetho integration. It is highly - * discouraged to enable this in production builds. Due to how the Litho releases are distributed - * in open source IS_INTERNAL_BUILD will always be false. It is therefore required to override - * this value using your own application build configs. Recommended place for this is in a - * Application subclass onCreate() method. - */ - public static boolean isDebugModeEnabled = IS_INTERNAL_BUILD; - - /** Lightweight tracking of component class hierarchy of MountItems. */ - public static boolean isDebugHierarchyEnabled = false; - - /** - * Populates additional metadata to find mounted components at runtime. Defaults to the presence - * of an - * - *

IS_TESTING
- * - * system property at startup but can be overridden at runtime. - */ - public static boolean isEndToEndTestRun = System.getProperty("IS_TESTING") != null; - - public static boolean isAnimationDisabled = - "true".equals(System.getProperty("litho.animation.disabled")); - - /** - * By default end-to-end tests will disable transitions and this flag lets to explicitly enable - * transitions to test animation related behavior. - */ - public static boolean forceEnableTransitionsForInstrumentationTests = false; - - /** - * If non-null, a thread pool will be used for async layouts instead of a single layout thread. - */ - public static @Nullable LayoutThreadPoolConfiguration threadPoolConfiguration = null; - - public static boolean enableThreadTracingStacktrace = false; - - /** Sets if is reconciliation is enabled */ - public static boolean isReconciliationEnabled = true; - - /** - * The LazyList is having a default of {@code false} for the reconciliation being enabled. - * Ideally, it would default to whatever value is used in its ComponentContext. By enabling this - * setting, the default will be retrieve via the ComponentContext. - */ - public static boolean isLazyListUsingComponentContextReconciliationConfig = true; - - public static @Nullable Boolean overrideReconciliation = null; - - public static @Nullable Boolean overrideLayoutDiffing = null; - - /** - * Sets if layout diffing is enabled. This should be used in conjugation with - * {@link#isReconciliationEnabled}. - */ - public static boolean isLayoutDiffingEnabled = true; - - public static boolean runLooperPrepareForLayoutThreadFactory = true; - - public static boolean enableDrawablePreAllocation = false; - - /** - * field.getAnnotation() has bugs which is causing java crashes in the App, in addition to this we - * suspect this might be a reason for few other native crashes as well. Adding this flag to verify - * if this is the root cause. - */ - public static boolean disableGetAnnotationUsage; - - public static boolean isRenderInfoDebuggingEnabled() { - return isDebugModeEnabled; - } - - public static @Nullable LithoPerfBoosterFactory perfBoosterFactory = null; - - /** - * If true, the {@link #perfBoosterFactory} will be used to indicate that LayoutStateFuture thread - * can use the perf boost - */ - public static boolean boostPerfLayoutStateFuture; - - /** - * Start parallel layout of visible range just before serial synchronous layouts in RecyclerBinder - */ - public static boolean computeRangeOnSyncLayout = false; - - /** - * When true, IM will not stop when the LithoView's visible rect is empty, and will proceed to - * unmount everything. - */ - public static boolean shouldContinueIncrementalMountWhenVisibileRectIsEmpty = false; - - /** When {@code true}, disables incremental mount globally. */ - public static boolean isIncrementalMountGloballyDisabled = false; - - /** Keeps the litho layout result tree in the LayoutState. This will increase memory use. */ - public static boolean keepLayoutResults = false; - - /** - * Used by LithoViews to determine whether or not to self-manage the view-port changes, rather - * than rely on calls to notifyVisibleBoundsChanged. - */ - public static boolean lithoViewSelfManageViewPortChanges = false; - - public static boolean emitMessageForZeroSizedTexture = false; - - public static int textureSizeWarningLimit = Integer.MAX_VALUE; - - public static int overlappingRenderingViewSizeLimit = Integer.MAX_VALUE; - - public static int partialAlphaWarningSizeThresold = Integer.MAX_VALUE; - - public static @Nullable Set componentPreallocationBlocklist = null; - - /** Initialize sticky header during layout when its component tree is null */ - public static boolean initStickyHeaderInLayoutWhenComponentTreeIsNull = false; - - public static boolean unsafeHostComponentRecyclingIsEnabled = false; - - /** Whether a {@link ComponentHost} can be pre-allocated */ - public static boolean isHostComponentPreallocationEnabled = false; - - public static int hostComponentPoolSize = 30; - - /** When {@code true} ComponentTree records state change snapshots */ - public static boolean isTimelineEnabled = isDebugModeEnabled; - - public static @Nullable String timelineDocsLink = null; - - public static boolean enableIsBoringLayoutCheckTimeout = false; - - /** Skip checking for root component and tree-props while layout */ - public static boolean isSkipRootCheckingEnabled = false; - - public static boolean enableComputeLayoutAsyncAfterInsertion = true; - - public static boolean shouldCompareCommonPropsInIsEquivalentTo = false; - - public static boolean shouldCompareRootCommonPropsInSingleComponentSection = false; - - public static boolean shouldDelegateContentDescriptionChangeEvent = false; - - public static boolean forceDelegateViewBinder = false; - - /** This toggles whether {@Link #LayoutThreadPoolExecutor} should timeout core threads or not */ - public static boolean shouldAllowCoreThreadTimeout = false; - - public static long layoutThreadKeepAliveTimeMs = 1000; - - public static boolean crashIfExceedingStateUpdateThreshold = false; - - public static boolean enableRecyclerBinderStableId = true; - - public static int recyclerBinderStrategy = 0; - - public static boolean enableMountableRecycler = false; - - public static boolean enableMountableTwoBindersRecycler = false; - public static boolean enableSeparateAnimatorBinder = false; - - public static boolean enableMountableRecyclerInGroups = false; - public static boolean hostComponentAlwaysShouldUpdate = true; - - public static boolean shouldOverrideHasTransientState = false; - - public static boolean enableFixForNestedComponentTree = false; - private static boolean sReduceMemorySpikeUserSession = false; - private static boolean sReduceMemorySpikeDataDiffSection = false; - private static boolean sReduceMemorySpikeGetUri = false; - - public static boolean bindOnSameComponentTree = true; - - public static void setReduceMemorySpikeUserSession() { - sReduceMemorySpikeUserSession = true; - } - - public static boolean reduceMemorySpikeUserSession() { - return sReduceMemorySpikeUserSession; - } - - public static void setReduceMemorySpikeDataDiffSection() { - sReduceMemorySpikeDataDiffSection = true; - } - - public static boolean reduceMemorySpikeDataDiffSection() { - return sReduceMemorySpikeDataDiffSection; - } - - public static void setReduceMemorySpikeGetUri() { - sReduceMemorySpikeGetUri = true; - } - - public static boolean reduceMemorySpikeGetUri() { - return sReduceMemorySpikeGetUri; - } - - public static boolean enableStateUpdatesBatching = true; - - @Nullable public static ComponentsLogger sComponentsLogger; - - /** Debug option to highlight interactive areas in mounted components. */ - public static boolean debugHighlightInteractiveBounds = false; - - /** Debug option to highlight mount bounds of mounted components. */ - public static boolean debugHighlightMountBounds = false; - - public static boolean isEventHandlerRebindLoggingEnabled = false; - - public static int eventHandlerRebindLoggingSamplingRate = 0; - - private static ComponentsConfiguration.Builder defaultBuilder = new Builder(); - - private static ComponentsConfiguration defaultComponentsConfiguration = defaultBuilder.build(); - - public static void setDefaultComponentsConfigurationBuilder(Builder builder) { - defaultBuilder = builder; - defaultComponentsConfiguration = defaultBuilder.build(); - } - - public static ComponentsConfiguration getDefaultComponentsConfiguration() { - return defaultComponentsConfiguration; - } - - public static ComponentsConfiguration.Builder getDefaultComponentsConfigurationBuilder() { - return defaultBuilder; - } - - private final boolean mUseCancelableLayoutFutures; - - private final boolean mUseInterruptibleResolution; - - private final boolean mShouldCacheLayouts; - - private final boolean mShouldAddHostViewForRootComponent; - - protected final boolean mShouldDisableBgFgOutputs; - - private final boolean mUseIncrementalMountGapWorker; - - private final boolean mNestedPreallocationEnabled; - - private boolean mUseNonRebindingEventHandlers = false; - - public boolean isNestedPreallocationEnabled() { - return mNestedPreallocationEnabled; - } - - public boolean getUseCancelableLayoutFutures() { - return mUseCancelableLayoutFutures; - } - - public boolean getUseInterruptibleResolution() { - return mUseInterruptibleResolution; - } - - public boolean isShouldAddHostViewForRootComponent() { - return mShouldAddHostViewForRootComponent; - } - - public boolean shouldAddRootHostViewOrDisableBgFgOutputs() { - return mShouldAddHostViewForRootComponent || mShouldDisableBgFgOutputs; - } - - public boolean useIncrementalMountGapWorker() { - return mUseIncrementalMountGapWorker; - } - - public boolean useNonRebindingEventHandlers() { - return mUseNonRebindingEventHandlers; - } - - private ComponentsConfiguration(ComponentsConfiguration.Builder builder) { - mUseCancelableLayoutFutures = builder.mUseCancelableLayoutFutures; - mUseInterruptibleResolution = builder.mUseInterruptibleResolution; - mShouldCacheLayouts = builder.mShouldCacheLayouts; - mShouldAddHostViewForRootComponent = builder.mShouldAddHostViewForRootComponent; - mShouldDisableBgFgOutputs = builder.mShouldDisableBgFgOutputs; - mUseIncrementalMountGapWorker = builder.mUseIncrementalMountGapWorker; - mNestedPreallocationEnabled = builder.mNestedPreallocationEnabled; - mUseNonRebindingEventHandlers = builder.mUseNonRebindingEventHandlers; - } - - public static ComponentsConfiguration.Builder create() { - return create(defaultComponentsConfiguration); - } - - public static ComponentsConfiguration.Builder create(ComponentsConfiguration config) { - return new Builder() - .useCancelableLayoutFutures(config.getUseCancelableLayoutFutures()) - .useInterruptibleResolution(config.getUseInterruptibleResolution()) - .shouldCacheLayouts(config.shouldCacheLayouts()) - .shouldAddHostViewForRootComponent(config.isShouldAddHostViewForRootComponent()) - .shouldDisableBgFgOutputs(config.mShouldDisableBgFgOutputs) - .useIncrementalMountGapWorker(config.useIncrementalMountGapWorker()) - .nestedPreallocationEnabled(config.isNestedPreallocationEnabled()) - .useNonRebindingEventHandlers(config.useNonRebindingEventHandlers()); - } - - public boolean shouldCacheLayouts() { - return mShouldCacheLayouts; - } - - public static class Builder { - - boolean mUseCancelableLayoutFutures = true; - boolean mUseInterruptibleResolution = true; - boolean mShouldCacheLayouts = true; - boolean mShouldAddHostViewForRootComponent = false; - boolean mShouldDisableBgFgOutputs = false; - boolean mUseIncrementalMountGapWorker = IncrementalMountExtensionConfigs.useGapWorker; - boolean mNestedPreallocationEnabled = false; - - boolean mUseNonRebindingEventHandlers = false; - - protected Builder() {} - - public Builder useCancelableLayoutFutures(boolean enable) { - mUseCancelableLayoutFutures = enable; - return this; - } - - public Builder useInterruptibleResolution(boolean enable) { - mUseInterruptibleResolution = enable; - return this; - } - - public Builder shouldAddHostViewForRootComponent(boolean enabled) { - mShouldAddHostViewForRootComponent = enabled; - return this; - } - - public Builder shouldDisableBgFgOutputs(boolean enabled) { - mShouldDisableBgFgOutputs = enabled; - return this; - } - - public Builder shouldCacheLayouts(boolean enabled) { - mShouldCacheLayouts = enabled; - return this; - } - - public Builder useIncrementalMountGapWorker(boolean enabled) { - mUseIncrementalMountGapWorker = enabled; - return this; - } - - /** - * If true, uses the root ComponentTree's mount content allows the usage of the preallocation - * handler to perform preallocation for nested trees. - */ - public Builder nestedPreallocationEnabled(boolean enabled) { - mNestedPreallocationEnabled = enabled; - return this; - } - - public Builder useNonRebindingEventHandlers(boolean enabled) { - mUseNonRebindingEventHandlers = enabled; - return this; - } - - public ComponentsConfiguration build() { - return new ComponentsConfiguration(this); - } - } -} diff --git a/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.kt b/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.kt new file mode 100644 index 00000000000..953e25e7993 --- /dev/null +++ b/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.kt @@ -0,0 +1,277 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.facebook.litho.config + +import android.os.Build +import com.facebook.kotlin.compilerplugins.dataclassgenerate.annotation.DataClassGenerate +import com.facebook.kotlin.compilerplugins.dataclassgenerate.annotation.Mode +import com.facebook.litho.BuildConfig +import com.facebook.litho.ComponentsLogger +import com.facebook.litho.perfboost.LithoPerfBoosterFactory +import com.facebook.rendercore.incrementalmount.IncrementalMountExtensionConfigs + +/** + * Hi there, traveller! This configuration class is not meant to be used by end-users of Litho. It + * contains mainly flags for features that are either under active development and not ready for + * public consumption, or for use in experiments. + * + * These values are safe defaults and should not require manual changes. + * + * This class hosts all the config parameters that the ComponentTree configures it self .... enable + * and disable features ... A Component tree uses the [.defaultComponentsConfiguration] by default + * but a [Builder] can be used to create new instances of the config to override the default + * parameters ... The default config values can also be overridden by manually setting their values + * in [.defaultBuilder] + */ +@DataClassGenerate(toString = Mode.OMIT, equalsHashCode = Mode.KEEP) +data class ComponentsConfiguration +internal constructor( + val useCancellableLayoutFutures: Boolean = true, + val useInterruptibleResolution: Boolean = true, + val shouldCacheLayouts: Boolean = true, + val shouldAddHostViewForRootComponent: Boolean = false, + @JvmField + val useIncrementalMountGapWorker: Boolean = IncrementalMountExtensionConfigs.useGapWorker, + @JvmField val nestedPreallocationEnabled: Boolean = false, + val useNonRebindingEventHandlers: Boolean = false, + internal val shouldDisableBgFgOutputs: Boolean = false, +) { + + val shouldAddRootHostViewOrDisableBgFgOutputs: Boolean = + shouldAddHostViewForRootComponent || shouldDisableBgFgOutputs + + companion object { + + @JvmField var defaultInstance: ComponentsConfiguration = ComponentsConfiguration() + + /** + * Indicates whether this is an internal build. Note that the implementation of `BuildConfig ` * + * that this class is compiled against may not be the one that is included in the APK. See: + * [android_build_config](http://facebook.github.io/buck/rule/android_build_config.html). + */ + @JvmField val IS_INTERNAL_BUILD: Boolean = BuildConfig.IS_INTERNAL_BUILD + + /** Indicates that the incremental mount helper is required for this build. */ + @JvmField val USE_INCREMENTAL_MOUNT_HELPER: Boolean = BuildConfig.USE_INCREMENTAL_MOUNT_HELPER + + /** Whether we can access properties in Settings.Global for animations. */ + val CAN_CHECK_GLOBAL_ANIMATOR_SETTINGS: Boolean = + Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 + + /** Whether we need to account for lack of synchronization while accessing Themes. */ + @JvmField + val NEEDS_THEME_SYNCHRONIZATION: Boolean = + Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1 + + /** The default priority for threads that perform background layout calculations. */ + @JvmField var DEFAULT_BACKGROUND_THREAD_PRIORITY: Int = 5 + + /** + * The default priority for threads that perform background sections change set calculations. + */ + const val DEFAULT_CHANGE_SET_THREAD_PRIORITY: Int = 0 + + @JvmField var isDebugModeEnabled: Boolean = IS_INTERNAL_BUILD + + /** + * Option to enabled debug mode. This will save extra data associated with each node and allow + * more info about the hierarchy to be retrieved. Used to enable stetho integration. It is + * highly discouraged to enable this in production builds. Due to how the Litho releases are + * distributed in open source IS_INTERNAL_BUILD will always be false. It is therefore required + * to override this value using your own application build configs. Recommended place for this + * is in a Application subclass onCreate() method. + */ + @JvmField var isRenderInfoDebuggingEnabled: Boolean = isDebugModeEnabled + + /** Lightweight tracking of component class hierarchy of MountItems. */ + @JvmField var isDebugHierarchyEnabled: Boolean = false + + /** + * Populates additional metadata to find mounted components at runtime. Defaults to the presence + * of an + * + * ``` + * IS_TESTING + * ``` + * + * system property at startup but can be overridden at runtime. + */ + @JvmField var isEndToEndTestRun = System.getProperty("IS_TESTING") != null + @JvmField var isAnimationDisabled = "true" == System.getProperty("litho.animation.disabled") + + /** + * By default end-to-end tests will disable transitions and this flag lets to explicitly enable + * transitions to test animation related behavior. + */ + @JvmField var forceEnableTransitionsForInstrumentationTests: Boolean = false + + /** + * If non-null, a thread pool will be used for async layouts instead of a single layout thread. + */ + @JvmField var threadPoolConfiguration: LayoutThreadPoolConfiguration? = null + @JvmField var enableThreadTracingStacktrace: Boolean = false + + /** Sets if is reconciliation is enabled */ + @JvmField var isReconciliationEnabled: Boolean = true + + /** + * The LazyList is having a default of `false` for the reconciliation being enabled. Ideally, it + * would default to whatever value is used in its ComponentContext. By enabling this setting, + * the default will be retrieve via the ComponentContext. + */ + @JvmField var isLazyListUsingComponentContextReconciliationConfig: Boolean = true + @JvmField var overrideReconciliation: Boolean? = null + @JvmField var overrideLayoutDiffing: Boolean? = null + + /** + * Sets if layout diffing is enabled. This should be used in conjugation with + * {@link#isReconciliationEnabled}. + */ + @JvmField var isLayoutDiffingEnabled: Boolean = true + @JvmField var runLooperPrepareForLayoutThreadFactory: Boolean = true + @JvmField var enableDrawablePreAllocation: Boolean = false + + /** + * field.getAnnotation() has bugs which is causing java crashes in the App, in addition to this + * we suspect this might be a reason for few other native crashes as well. Adding this flag to + * verify if this is the root cause. + */ + @JvmField var disableGetAnnotationUsage: Boolean = false + @JvmField var perfBoosterFactory: LithoPerfBoosterFactory? = null + + /** + * If true, the [.perfBoosterFactory] will be used to indicate that LayoutStateFuture thread can + * use the perf boost + */ + @JvmField var boostPerfLayoutStateFuture: Boolean = false + + /** + * Start parallel layout of visible range just before serial synchronous layouts in + * RecyclerBinder + */ + @JvmField var computeRangeOnSyncLayout: Boolean = false + + /** + * When true, IM will not stop when the LithoView's visible rect is empty, and will proceed to + * unmount everything. + */ + @JvmField var shouldContinueIncrementalMountWhenVisibileRectIsEmpty: Boolean = false + + /** When `true`, disables incremental mount globally. */ + @JvmField var isIncrementalMountGloballyDisabled: Boolean = false + + /** Keeps the litho layout result tree in the LayoutState. This will increase memory use. */ + @JvmField var keepLayoutResults: Boolean = false + + /** + * Used by LithoViews to determine whether or not to self-manage the view-port changes, rather + * than rely on calls to notifyVisibleBoundsChanged. + */ + @JvmField var lithoViewSelfManageViewPortChanges: Boolean = false + @JvmField var emitMessageForZeroSizedTexture: Boolean = false + @JvmField var textureSizeWarningLimit: Int = Int.MAX_VALUE + @JvmField var overlappingRenderingViewSizeLimit: Int = Int.MAX_VALUE + @JvmField var partialAlphaWarningSizeThresold: Int = Int.MAX_VALUE + @JvmField var componentPreallocationBlocklist: Set? = null + + /** Initialize sticky header during layout when its component tree is null */ + @JvmField var initStickyHeaderInLayoutWhenComponentTreeIsNull: Boolean = false + @JvmField var unsafeHostComponentRecyclingIsEnabled: Boolean = false + + /** Whether a [ComponentHost] can be pre-allocated */ + @JvmField var isHostComponentPreallocationEnabled: Boolean = false + @JvmField var hostComponentPoolSize: Int = 30 + + /** When `true` ComponentTree records state change snapshots */ + @JvmField var isTimelineEnabled: Boolean = isRenderInfoDebuggingEnabled + @JvmField var timelineDocsLink: String? = null + @JvmField var enableIsBoringLayoutCheckTimeout: Boolean = false + + /** Skip checking for root component and tree-props while layout */ + @JvmField var isSkipRootCheckingEnabled: Boolean = false + @JvmField var enableComputeLayoutAsyncAfterInsertion: Boolean = true + @JvmField var shouldCompareCommonPropsInIsEquivalentTo: Boolean = false + @JvmField var shouldCompareRootCommonPropsInSingleComponentSection: Boolean = false + @JvmField var shouldDelegateContentDescriptionChangeEvent: Boolean = false + @JvmField var forceDelegateViewBinder: Boolean = false + + /** This toggles whether {@Link #LayoutThreadPoolExecutor} should timeout core threads or not */ + @JvmField var shouldAllowCoreThreadTimeout: Boolean = false + @JvmField var layoutThreadKeepAliveTimeMs: Long = 1_000 + @JvmField var crashIfExceedingStateUpdateThreshold: Boolean = false + @JvmField var enableRecyclerBinderStableId: Boolean = false + @JvmField var recyclerBinderStrategy: Int = 0 + @JvmField var enableMountableRecycler: Boolean = false + @JvmField var enableMountableTwoBindersRecycler: Boolean = false + @JvmField var enableSeparateAnimatorBinder: Boolean = false + @JvmField var enableMountableRecyclerInGroups: Boolean = false + @JvmField var hostComponentAlwaysShouldUpdate: Boolean = true + @JvmField var shouldOverrideHasTransientState: Boolean = false + @JvmField var enableFixForNestedComponentTree: Boolean = false + @JvmField var reduceMemorySpikeUserSession: Boolean = false + @JvmField var reduceMemorySpikeDataDiffSection: Boolean = false + @JvmField var reduceMemorySpikeGetUri: Boolean = false + @JvmField var bindOnSameComponentTree: Boolean = true + @JvmField var enableStateUpdatesBatching = true + @JvmField var componentsLogger: ComponentsLogger? = null + + /** Debug option to highlight interactive areas in mounted components. */ + @JvmField var debugHighlightInteractiveBounds: Boolean = false + + /** Debug option to highlight mount bounds of mounted components. */ + @JvmField var debugHighlightMountBounds: Boolean = false + @JvmField var isEventHandlerRebindLoggingEnabled: Boolean = false + @JvmField var eventHandlerRebindLoggingSamplingRate: Int = 0 + + /** + * This method is only used so that Java clients can have a builder like approach to override a + * configuration. + */ + @JvmStatic fun create(): Builder = create(defaultInstance) + + @JvmStatic + fun create(configuration: ComponentsConfiguration): Builder = Builder(configuration.copy()) + } + + /** + * This is a builder that only exists so that Java clients can have an easier time creating and + * overriding specific configurations. For Kotlin one can use directly the named parameters on the + * [ComponentsConfiguration] constructor. + */ + class Builder internal constructor(private var baseConfig: ComponentsConfiguration) { + + fun useCancellableLayoutFutures(enabled: Boolean) = also { + baseConfig = baseConfig.copy(useCancellableLayoutFutures = enabled) + } + + fun shouldAddHostViewForRootComponent(enabled: Boolean) = also { + baseConfig = baseConfig.copy(shouldAddHostViewForRootComponent = enabled) + } + + fun nestedPreallocationEnabled(enabled: Boolean) = also { + baseConfig = baseConfig.copy(nestedPreallocationEnabled = enabled) + } + + fun shouldCacheLayouts(enabled: Boolean) = also { + baseConfig = baseConfig.copy(shouldCacheLayouts = enabled) + } + + fun build(): ComponentsConfiguration { + return baseConfig + } + } +} diff --git a/litho-it/src/test/java/com/facebook/litho/ApplyStylesTest.kt b/litho-it/src/test/java/com/facebook/litho/ApplyStylesTest.kt index 7a19a903e0a..c3b1c2afb18 100644 --- a/litho-it/src/test/java/com/facebook/litho/ApplyStylesTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/ApplyStylesTest.kt @@ -40,7 +40,7 @@ class ApplyStylesTest { @Rule var legacyLithoViewRule: LegacyLithoViewRule = LegacyLithoViewRule( - ComponentsConfiguration.create().shouldAddHostViewForRootComponent(true).build()) + ComponentsConfiguration.defaultInstance.copy(shouldAddHostViewForRootComponent = true)) @Test fun styles_withWidthHeightStyle_appliesWidthHeight() { diff --git a/litho-it/src/test/java/com/facebook/litho/ComponentsConfigurationTest.kt b/litho-it/src/test/java/com/facebook/litho/ComponentsConfigurationTest.kt index 968da37528c..ceb829c1de6 100644 --- a/litho-it/src/test/java/com/facebook/litho/ComponentsConfigurationTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/ComponentsConfigurationTest.kt @@ -42,29 +42,29 @@ class ComponentsConfigurationTest { private val componentContext = ComponentContext(ApplicationProvider.getApplicationContext()) - private val defaultBuilder = ComponentsConfiguration.getDefaultComponentsConfigurationBuilder() + private val defaultConfiguration = ComponentsConfiguration.defaultInstance @Test fun testSetFlagThroughComponentConfigToComponentTree() { - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder( - ComponentsConfiguration.create().useCancelableLayoutFutures(true)) + ComponentsConfiguration.defaultInstance = + defaultConfiguration.copy(useCancellableLayoutFutures = true) val componentTree = ComponentTree.create(componentContext) - .componentsConfiguration(ComponentsConfiguration.getDefaultComponentsConfiguration()) + .componentsConfiguration(ComponentsConfiguration.defaultInstance) .build() val componentsConfiguration = componentTree.context.mLithoConfiguration.componentsConfig - assertThat(componentsConfiguration.useCancelableLayoutFutures).isTrue - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder(defaultBuilder) + assertThat(componentsConfiguration.useCancellableLayoutFutures).isTrue + ComponentsConfiguration.defaultInstance = defaultConfiguration } @Test fun testSetFlagThroughComponentConfigToComponentTreeWithRecyclerCollectionComponent() { - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder( - ComponentsConfiguration.create().useCancelableLayoutFutures(true)) + ComponentsConfiguration.defaultInstance = + defaultConfiguration.copy(useCancellableLayoutFutures = true) val recyclerBinderConfiguration = RecyclerBinderConfiguration.create() - .componentsConfiguration(ComponentsConfiguration.getDefaultComponentsConfiguration()) + .componentsConfiguration(ComponentsConfiguration.defaultInstance) .build() legacyLithoViewRule .setRoot( @@ -88,22 +88,20 @@ class ComponentsConfigurationTest { assertThat(childView).isNotNull val componentsConfiguration = childView?.componentTree?.context?.mLithoConfiguration?.componentsConfig - assertThat(componentsConfiguration?.useCancelableLayoutFutures).isTrue - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder(defaultBuilder) + assertThat(componentsConfiguration?.useCancellableLayoutFutures).isTrue + ComponentsConfiguration.defaultInstance = defaultConfiguration } @Test fun testOverrideDefaultBuilder() { - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder( - ComponentsConfiguration.create().useCancelableLayoutFutures(true)) - assertThat( - ComponentsConfiguration.getDefaultComponentsConfiguration().useCancelableLayoutFutures) - .isTrue - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder( - ComponentsConfiguration.create().useCancelableLayoutFutures(false)) - assertThat( - ComponentsConfiguration.getDefaultComponentsConfiguration().useCancelableLayoutFutures) - .isFalse - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder(defaultBuilder) + ComponentsConfiguration.defaultInstance = + defaultConfiguration.copy(useCancellableLayoutFutures = true) + assertThat(ComponentsConfiguration.defaultInstance.useCancellableLayoutFutures).isTrue + + ComponentsConfiguration.defaultInstance = + defaultConfiguration.copy(useCancellableLayoutFutures = false) + assertThat(ComponentsConfiguration.defaultInstance.useCancellableLayoutFutures).isFalse + + ComponentsConfiguration.defaultInstance = defaultConfiguration } } diff --git a/litho-it/src/test/java/com/facebook/litho/DuplicateParentChildrenStateTest.kt b/litho-it/src/test/java/com/facebook/litho/DuplicateParentChildrenStateTest.kt index 8bd12f716b9..fe5ff73dbb6 100644 --- a/litho-it/src/test/java/com/facebook/litho/DuplicateParentChildrenStateTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/DuplicateParentChildrenStateTest.kt @@ -37,7 +37,8 @@ class DuplicateParentChildrenStateTest { val lithoViewRule: LithoViewRule = LithoViewRule( componentsConfiguration = - ComponentsConfiguration.create().shouldAddHostViewForRootComponent(true).build()) + ComponentsConfiguration.defaultInstance.copy( + shouldAddHostViewForRootComponent = true)) @Test fun duplicateParentState_avoidedIfRedundant() { diff --git a/litho-it/src/test/java/com/facebook/litho/DynamicPropsTest.kt b/litho-it/src/test/java/com/facebook/litho/DynamicPropsTest.kt index c0f9ea6c0dd..d796bc0857b 100644 --- a/litho-it/src/test/java/com/facebook/litho/DynamicPropsTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/DynamicPropsTest.kt @@ -54,7 +54,8 @@ class DynamicPropsTest { private lateinit var context: ComponentContext - val config = ComponentsConfiguration.create().shouldAddHostViewForRootComponent(true).build() + val config = + ComponentsConfiguration.defaultInstance.copy(shouldAddHostViewForRootComponent = true) @JvmField @Rule val legacyLithoViewRule = LegacyLithoViewRule(config) diff --git a/litho-it/src/test/java/com/facebook/litho/LayoutStateCalculateTest.kt b/litho-it/src/test/java/com/facebook/litho/LayoutStateCalculateTest.kt index f29114b6297..d6786e47dec 100644 --- a/litho-it/src/test/java/com/facebook/litho/LayoutStateCalculateTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/LayoutStateCalculateTest.kt @@ -73,7 +73,8 @@ import org.robolectric.shadows.ShadowAccessibilityManager @RunWith(LithoTestRunner::class) class LayoutStateCalculateTest { - val config = ComponentsConfiguration.create().shouldAddHostViewForRootComponent(true).build() + val config = + ComponentsConfiguration.defaultInstance.copy(shouldAddHostViewForRootComponent = true) @JvmField @Rule val legacyLithoViewRule = LegacyLithoViewRule(config) private lateinit var context: ComponentContext diff --git a/litho-it/src/test/java/com/facebook/litho/LayoutStateCalculationWithoutDrawableOutputsTest.kt b/litho-it/src/test/java/com/facebook/litho/LayoutStateCalculationWithoutDrawableOutputsTest.kt index d45cd8431e8..1a73b7eb74f 100644 --- a/litho-it/src/test/java/com/facebook/litho/LayoutStateCalculationWithoutDrawableOutputsTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/LayoutStateCalculationWithoutDrawableOutputsTest.kt @@ -49,28 +49,29 @@ class LayoutStateCalculationWithoutDrawableOutputsTest { componentTree = ComponentTree.create(context) .componentsConfiguration( - ComponentsConfiguration.create().shouldAddHostViewForRootComponent(false).build()) + ComponentsConfiguration.defaultInstance.copy( + shouldAddHostViewForRootComponent = false)) .build() - lithoView!!.componentTree = componentTree + lithoView.componentTree = componentTree attach() componentTree.setRootSync(RootComponent.create(context).shouldWrapInView(false).build()) val state: LayoutState = requireNotNull(lithoView.componentTree?.mainThreadLayoutState) { "empty layout state" } - assertThat(state?.mountableOutputCount).isEqualTo(7) + assertThat(state.mountableOutputCount).isEqualTo(7) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(0)) // root host view - assertThat(output?.component).isOfAnyClassIn(HostComponent::class.java) + assertThat(output.component).isOfAnyClassIn(HostComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(1)) // background 1 - assertThat(output?.component).isOfAnyClassIn(DrawableComponent::class.java) + assertThat(output.component).isOfAnyClassIn(DrawableComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(2)) // text 1 - assertThat(output?.component).isOfAnyClassIn(Text::class.java) + assertThat(output.component).isOfAnyClassIn(Text::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(3)) // foreground 1 - assertThat(output?.component).isOfAnyClassIn(DrawableComponent::class.java) + assertThat(output.component).isOfAnyClassIn(DrawableComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(4)) // background 2 - assertThat(output?.component).isOfAnyClassIn(DrawableComponent::class.java) + assertThat(output.component).isOfAnyClassIn(DrawableComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(5)) // text 2 - assertThat(output?.component).isOfAnyClassIn(Text::class.java) + assertThat(output.component).isOfAnyClassIn(Text::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(6)) // foreground 2 - assertThat(output?.component).isOfAnyClassIn(DrawableComponent::class.java) + assertThat(output.component).isOfAnyClassIn(DrawableComponent::class.java) } @Test @@ -79,32 +80,33 @@ class LayoutStateCalculationWithoutDrawableOutputsTest { componentTree = ComponentTree.create(context) .componentsConfiguration( - ComponentsConfiguration.create().shouldAddHostViewForRootComponent(false).build()) + ComponentsConfiguration.defaultInstance.copy( + shouldAddHostViewForRootComponent = false)) .build() - lithoView!!.componentTree = componentTree + lithoView.componentTree = componentTree componentTree.setRootSync(RootComponent.create(context).shouldWrapInView(true).build()) attach() val state: LayoutState = requireNotNull(lithoView.componentTree?.mainThreadLayoutState) { "empty layout state" } assertThat(state.mountableOutputCount).isEqualTo(9) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(0)) // root host view - assertThat(output?.component).isOfAnyClassIn(HostComponent::class.java) + assertThat(output.component).isOfAnyClassIn(HostComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(1)) // host view 1 - assertThat(output?.component).isOfAnyClassIn(HostComponent::class.java) + assertThat(output.component).isOfAnyClassIn(HostComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(2)) // background 1 - assertThat(output?.component).isOfAnyClassIn(DrawableComponent::class.java) + assertThat(output.component).isOfAnyClassIn(DrawableComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(3)) // text 1 - assertThat(output?.component).isOfAnyClassIn(Text::class.java) + assertThat(output.component).isOfAnyClassIn(Text::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(4)) // foreground 1 - assertThat(output?.component).isOfAnyClassIn(DrawableComponent::class.java) + assertThat(output.component).isOfAnyClassIn(DrawableComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(5)) // host view 2 - assertThat(output?.component).isOfAnyClassIn(HostComponent::class.java) + assertThat(output.component).isOfAnyClassIn(HostComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(6)) // background 2 - assertThat(output?.component).isOfAnyClassIn(DrawableComponent::class.java) + assertThat(output.component).isOfAnyClassIn(DrawableComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(7)) // text 2 - assertThat(output?.component).isOfAnyClassIn(Text::class.java) + assertThat(output.component).isOfAnyClassIn(Text::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(8)) // foreground 2 - assertThat(output?.component).isOfAnyClassIn(DrawableComponent::class.java) + assertThat(output.component).isOfAnyClassIn(DrawableComponent::class.java) } @Test @@ -114,22 +116,23 @@ class LayoutStateCalculationWithoutDrawableOutputsTest { componentTree = ComponentTree.create(context) .componentsConfiguration( - ComponentsConfiguration.create().shouldAddHostViewForRootComponent(true).build()) + ComponentsConfiguration.defaultInstance.copy( + shouldAddHostViewForRootComponent = true)) .build() - lithoView!!.componentTree = componentTree + lithoView.componentTree = componentTree componentTree.setRootSync(RootComponent.create(context).shouldWrapInView(false).build()) attach() val state: LayoutState = requireNotNull(lithoView.componentTree?.mainThreadLayoutState) { "empty layout state" } assertThat(state.mountableOutputCount).isEqualTo(5) // 2 bg and fg lesser. output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(1)) - assertThat(output?.component).isOfAnyClassIn(HostComponent::class.java) + assertThat(output.component).isOfAnyClassIn(HostComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(2)) - assertThat(output?.component).isOfAnyClassIn(Text::class.java) + assertThat(output.component).isOfAnyClassIn(Text::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(3)) - assertThat(output?.component).isOfAnyClassIn(HostComponent::class.java) + assertThat(output.component).isOfAnyClassIn(HostComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(4)) - assertThat(output?.component).isOfAnyClassIn(Text::class.java) + assertThat(output.component).isOfAnyClassIn(Text::class.java) } @Test @@ -139,22 +142,23 @@ class LayoutStateCalculationWithoutDrawableOutputsTest { componentTree = ComponentTree.create(context) .componentsConfiguration( - ComponentsConfiguration.create().shouldAddHostViewForRootComponent(true).build()) + ComponentsConfiguration.defaultInstance.copy( + shouldAddHostViewForRootComponent = true)) .build() - lithoView!!.componentTree = componentTree + lithoView.componentTree = componentTree componentTree.setRootSync(RootComponent.create(context).shouldWrapInView(true).build()) attach() val state: LayoutState = requireNotNull(lithoView.componentTree?.mainThreadLayoutState) { "empty layout state" } assertThat(state.mountableOutputCount).isEqualTo(5) // 2 bg and fg lesser. output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(1)) - assertThat(output?.component).isOfAnyClassIn(HostComponent::class.java) + assertThat(output.component).isOfAnyClassIn(HostComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(2)) - assertThat(output?.component).isOfAnyClassIn(Text::class.java) + assertThat(output.component).isOfAnyClassIn(Text::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(3)) - assertThat(output?.component).isOfAnyClassIn(HostComponent::class.java) + assertThat(output.component).isOfAnyClassIn(HostComponent::class.java) output = LithoRenderUnit.getRenderUnit(state.getMountableOutputAt(4)) - assertThat(output?.component).isOfAnyClassIn(Text::class.java) + assertThat(output.component).isOfAnyClassIn(Text::class.java) } private fun attach() { diff --git a/litho-it/src/test/java/com/facebook/litho/LayoutStateFutureReleaseTest.kt b/litho-it/src/test/java/com/facebook/litho/LayoutStateFutureReleaseTest.kt index d3728d270fa..2a5c93ebad8 100644 --- a/litho-it/src/test/java/com/facebook/litho/LayoutStateFutureReleaseTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/LayoutStateFutureReleaseTest.kt @@ -45,17 +45,16 @@ class LayoutStateFutureReleaseTest { private var widthSpec = 0 private var heightSpec = 0 private lateinit var context: ComponentContext - private val config = - ComponentsConfiguration.getDefaultComponentsConfiguration().useCancelableLayoutFutures private lateinit var resolveThreadShadowLooper: ShadowLooper private lateinit var layoutThreadShadowLooper: ShadowLooper + private val defaultConfig = ComponentsConfiguration.defaultInstance + @Before fun setup() { context = ComponentContext(ApplicationProvider.getApplicationContext()) - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder( - ComponentsConfiguration.getDefaultComponentsConfigurationBuilder() - .useCancelableLayoutFutures(true)) + ComponentsConfiguration.defaultInstance = defaultConfig.copy(useCancellableLayoutFutures = true) + widthSpec = makeSizeSpec(40, EXACTLY) heightSpec = makeSizeSpec(40, EXACTLY) layoutThreadShadowLooper = @@ -75,9 +74,7 @@ class LayoutStateFutureReleaseTest { @After fun tearDown() { - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder( - ComponentsConfiguration.getDefaultComponentsConfigurationBuilder() - .useCancelableLayoutFutures(config)) + ComponentsConfiguration.defaultInstance = defaultConfig } @Test @@ -170,8 +167,7 @@ class LayoutStateFutureReleaseTest { val handler = ThreadPoolLayoutHandler.getNewInstance(LayoutThreadPoolConfigurationImpl(1, 1, 5)) componentTree = ComponentTree.create(context, column_0) - .componentsConfiguration( - ComponentsConfiguration.create().useCancelableLayoutFutures(true).build()) + .componentsConfiguration(defaultConfig.copy(useCancellableLayoutFutures = true)) .layoutThreadHandler(handler) .build() componentTree.setLithoView(LithoView(context)) diff --git a/litho-it/src/test/java/com/facebook/litho/LithoViewVisibilityProcessingTest.kt b/litho-it/src/test/java/com/facebook/litho/LithoViewVisibilityProcessingTest.kt index d9fa76ee8c1..1448727b8ac 100644 --- a/litho-it/src/test/java/com/facebook/litho/LithoViewVisibilityProcessingTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/LithoViewVisibilityProcessingTest.kt @@ -18,7 +18,6 @@ package com.facebook.litho import android.graphics.Rect import com.facebook.litho.config.ComponentsConfiguration -import com.facebook.litho.config.ComponentsConfiguration.isIncrementalMountGloballyDisabled import com.facebook.litho.core.height import com.facebook.litho.core.width import com.facebook.litho.kotlin.widget.Text @@ -28,6 +27,8 @@ import com.facebook.litho.visibility.onVisible import com.facebook.rendercore.px import java.util.concurrent.atomic.AtomicInteger import org.assertj.core.api.Assertions.assertThat +import org.junit.After +import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -35,13 +36,17 @@ import org.junit.runner.RunWith @RunWith(LithoTestRunner::class) class LithoViewVisibilityProcessingTest { - @get:Rule - val lithoViewRule = - LithoViewRule( - componentsConfiguration = - ComponentsConfiguration.getDefaultComponentsConfiguration().apply { - isIncrementalMountGloballyDisabled = true - }) + @get:Rule val lithoViewRule = LithoViewRule() + + @Before + fun setup() { + ComponentsConfiguration.isIncrementalMountGloballyDisabled = true + } + + @After + fun teardown() { + ComponentsConfiguration.isIncrementalMountGloballyDisabled = false + } @Test fun `should process visibility outputs with the current visible rect when mount state is dirty and incremental mount disabled`() { diff --git a/litho-it/src/test/java/com/facebook/litho/MountStateIncrementalMountTest.kt b/litho-it/src/test/java/com/facebook/litho/MountStateIncrementalMountTest.kt index 5fccc24a06c..115db46f1bc 100644 --- a/litho-it/src/test/java/com/facebook/litho/MountStateIncrementalMountTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/MountStateIncrementalMountTest.kt @@ -85,7 +85,7 @@ class MountStateIncrementalMountTest { @Rule val legacyLithoViewRule = LegacyLithoViewRule( - ComponentsConfiguration.create().shouldAddHostViewForRootComponent(true).build()) + ComponentsConfiguration.defaultInstance.copy(shouldAddHostViewForRootComponent = true)) @Before fun setup() { diff --git a/litho-it/src/test/java/com/facebook/litho/MountStateRemountTest.kt b/litho-it/src/test/java/com/facebook/litho/MountStateRemountTest.kt index 291ad380fdc..cb8acf71e99 100644 --- a/litho-it/src/test/java/com/facebook/litho/MountStateRemountTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/MountStateRemountTest.kt @@ -43,7 +43,8 @@ import org.robolectric.annotation.LooperMode class MountStateRemountTest { private val config = - ComponentsConfiguration.create().shouldAddHostViewForRootComponent(true).build() + ComponentsConfiguration.defaultInstance.copy(shouldAddHostViewForRootComponent = true) + private lateinit var context: ComponentContext @JvmField @Rule val legacyLithoViewRule = LegacyLithoViewRule(config) diff --git a/litho-it/src/test/java/com/facebook/litho/MountStateTest.kt b/litho-it/src/test/java/com/facebook/litho/MountStateTest.kt index f2d2971e4ae..fbee0da35d3 100644 --- a/litho-it/src/test/java/com/facebook/litho/MountStateTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/MountStateTest.kt @@ -187,9 +187,8 @@ class MountStateTest { .useComponentTree( ComponentTree.create(context) .componentsConfiguration( - ComponentsConfiguration.create() - .shouldAddHostViewForRootComponent(true) - .build()) + ComponentsConfiguration.defaultInstance.copy( + shouldAddHostViewForRootComponent = true)) .build()) .attachToWindow() .setRoot(root) diff --git a/litho-it/src/test/java/com/facebook/litho/NestedPreallocationTest.kt b/litho-it/src/test/java/com/facebook/litho/NestedPreallocationTest.kt index e0f5364c840..b3c88053da0 100644 --- a/litho-it/src/test/java/com/facebook/litho/NestedPreallocationTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/NestedPreallocationTest.kt @@ -76,7 +76,7 @@ class NestedPreallocationTest { val componentTree = ComponentTree.create(context, EmptyComponent()) .componentsConfiguration( - ComponentsConfiguration.create().nestedPreallocationEnabled(true).build()) + ComponentsConfiguration.defaultInstance.copy(nestedPreallocationEnabled = true)) .shouldPreallocateMountContentPerMountSpec(preallocationEnabled) .useDefaultHandlerForContentPreallocation() .build() diff --git a/litho-it/src/test/java/com/facebook/litho/TreeDiffingTest.kt b/litho-it/src/test/java/com/facebook/litho/TreeDiffingTest.kt index ab5df7238be..3704be3f969 100644 --- a/litho-it/src/test/java/com/facebook/litho/TreeDiffingTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/TreeDiffingTest.kt @@ -56,7 +56,7 @@ class TreeDiffingTest { @Rule val legacyLithoViewRule = LegacyLithoViewRule( - ComponentsConfiguration.create().shouldAddHostViewForRootComponent(true).build()) + ComponentsConfiguration.defaultInstance.copy(shouldAddHostViewForRootComponent = true)) @Before @Throws(Exception::class) diff --git a/litho-it/src/test/java/com/facebook/litho/widget/ComponentWarmerTest.java b/litho-it/src/test/java/com/facebook/litho/widget/ComponentWarmerTest.java index 6829c93491d..1820667b581 100644 --- a/litho-it/src/test/java/com/facebook/litho/widget/ComponentWarmerTest.java +++ b/litho-it/src/test/java/com/facebook/litho/widget/ComponentWarmerTest.java @@ -150,7 +150,7 @@ public void testCancelDuringPrepareAsync() { final RecyclerBinder binder = new RecyclerBinder.Builder() .componentsConfiguration( - ComponentsConfiguration.create().useCancelableLayoutFutures(true).build()) + ComponentsConfiguration.create().useCancellableLayoutFutures(true).build()) .threadPoolConfig(new LayoutThreadPoolConfigurationImpl(2, 2, 5)) .build(mContext); @@ -220,7 +220,7 @@ public void testCancelDuringPrepare() { final RecyclerBinder binder = new RecyclerBinder.Builder() .componentsConfiguration( - ComponentsConfiguration.create().useCancelableLayoutFutures(true).build()) + ComponentsConfiguration.create().useCancellableLayoutFutures(true).build()) .build(mContext); binder.measure( diff --git a/litho-sections-core/src/main/java/com/facebook/litho/sections/ChangeSet.java b/litho-sections-core/src/main/java/com/facebook/litho/sections/ChangeSet.java index b912b807748..0d0b06ca618 100644 --- a/litho-sections-core/src/main/java/com/facebook/litho/sections/ChangeSet.java +++ b/litho-sections-core/src/main/java/com/facebook/litho/sections/ChangeSet.java @@ -119,7 +119,7 @@ public void insert(int index, RenderInfo renderInfo, @Nullable TreeProps treePro public void insert( int index, RenderInfo renderInfo, @Nullable TreeProps treeProps, @Nullable Object data) { // Null check for tests only. This should never be the case otherwise. - if (mSection != null && ComponentsConfiguration.isRenderInfoDebuggingEnabled()) { + if (mSection != null && ComponentsConfiguration.isRenderInfoDebuggingEnabled) { renderInfo.addDebugInfo(SectionsDebugParams.SECTION_GLOBAL_KEY, mSection.getGlobalKey()); } addChange(Change.insert(index, new TreePropsWrappedRenderInfo(renderInfo, treeProps), data)); @@ -137,7 +137,7 @@ public void insertRange( @Nullable TreeProps treeProps, @Nullable List data) { // Null check for tests only. This should never be the case otherwise. - if (mSection != null && ComponentsConfiguration.isRenderInfoDebuggingEnabled()) { + if (mSection != null && ComponentsConfiguration.isRenderInfoDebuggingEnabled) { for (int i = 0, size = renderInfos.size(); i < size; i++) { renderInfos .get(i) diff --git a/litho-sections-core/src/main/java/com/facebook/litho/sections/common/DataDiffSectionSpec.java b/litho-sections-core/src/main/java/com/facebook/litho/sections/common/DataDiffSectionSpec.java index 83fb0ac23a6..8977d2281b5 100644 --- a/litho-sections-core/src/main/java/com/facebook/litho/sections/common/DataDiffSectionSpec.java +++ b/litho-sections-core/src/main/java/com/facebook/litho/sections/common/DataDiffSectionSpec.java @@ -353,7 +353,7 @@ public RenderInfo render(Object o, int index) { renderInfo = ComponentRenderInfo.createEmpty(); } - if (ComponentsConfiguration.isRenderInfoDebuggingEnabled()) { + if (ComponentsConfiguration.isRenderInfoDebuggingEnabled) { renderInfo.addDebugInfo(SONAR_SECTIONS_DEBUG_INFO_TAG, mSectionContext.getSectionScope()); } @@ -437,7 +437,7 @@ private boolean areItemsTheSame(T previous, T next) { } else { isSameItemEventState = mIsSameItemEventStates.get(); } - if (ComponentsConfiguration.reduceMemorySpikeDataDiffSection() + if (ComponentsConfiguration.reduceMemorySpikeDataDiffSection && hasEventDispatcher != null && isSameItemEventState != null && isSameItemEventState.previousItem == sDummy.previousItem) { diff --git a/litho-sections-core/src/main/java/com/facebook/litho/sections/common/SingleComponentSectionSpec.java b/litho-sections-core/src/main/java/com/facebook/litho/sections/common/SingleComponentSectionSpec.java index f78bec46cdb..5f473472069 100644 --- a/litho-sections-core/src/main/java/com/facebook/litho/sections/common/SingleComponentSectionSpec.java +++ b/litho-sections-core/src/main/java/com/facebook/litho/sections/common/SingleComponentSectionSpec.java @@ -179,7 +179,7 @@ private static ComponentRenderInfo.Builder addCustomAttributes( SectionContext c, Diff component, @Nullable Diff componentsLogger) { - if (ComponentsConfiguration.isRenderInfoDebuggingEnabled()) { + if (ComponentsConfiguration.isRenderInfoDebuggingEnabled) { builder.debugInfo(SONAR_SECTIONS_DEBUG_INFO_TAG, c.getSectionScope()); builder.debugInfo(SONAR_SINGLE_COMPONENT_SECTION_DATA_PREV, component.getPrevious()); builder.debugInfo(SONAR_SINGLE_COMPONENT_SECTION_DATA_NEXT, component.getNext()); diff --git a/litho-testing/src/main/java/com/facebook/litho/BUCK b/litho-testing/src/main/java/com/facebook/litho/BUCK index 189cf541858..cb6576ea805 100644 --- a/litho-testing/src/main/java/com/facebook/litho/BUCK +++ b/litho-testing/src/main/java/com/facebook/litho/BUCK @@ -25,17 +25,17 @@ litho_android_library( srcs = glob( [ "*.java", - "config/*.java", + "config/*.kt", ], # It has its own module exclude = ["BenchmarkTestHelper.java"], ), autoglob = False, - language = "JAVA", provided_deps = [ LITHO_MOCKITO_V2_TARGET, LITHO_ROBOLECTRIC_V4_TARGET, ], + pure_kotlin = False, tests = [ make_dep_path("litho-it/src/test/java/com/facebook/litho/testing:testing"), ], diff --git a/litho-testing/src/main/java/com/facebook/litho/config/TempComponentsConfigurations.java b/litho-testing/src/main/java/com/facebook/litho/config/TempComponentsConfigurations.java deleted file mode 100644 index 28b297351cd..00000000000 --- a/litho-testing/src/main/java/com/facebook/litho/config/TempComponentsConfigurations.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.config; - -import com.facebook.infer.annotation.Nullsafe; - -@Nullsafe(Nullsafe.Mode.LOCAL) -public class TempComponentsConfigurations { - - private static final ComponentsConfiguration.Builder original = - ComponentsConfiguration.getDefaultComponentsConfigurationBuilder(); - - private static final boolean shouldCompareCommonPropsInIsEquivalentTo = - ComponentsConfiguration.shouldCompareCommonPropsInIsEquivalentTo; - - public static void setShouldAddHostViewForRootComponent(boolean value) { - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder( - ComponentsConfiguration.create() - .shouldAddHostViewForRootComponent(value) - .shouldAddHostViewForRootComponent(value)); - } - - public static void restoreShouldAddHostViewForRootComponent() { - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder(original); - } - - public static void setShouldCompareCommonPropsInIsEquivalentTo( - boolean shouldCompareCommonPropsInIsEquivalentTo) { - ComponentsConfiguration.shouldCompareCommonPropsInIsEquivalentTo = - shouldCompareCommonPropsInIsEquivalentTo; - } - - public static void restoreShouldCompareCommonPropsInIsEquivalentTo() { - ComponentsConfiguration.shouldCompareCommonPropsInIsEquivalentTo = - shouldCompareCommonPropsInIsEquivalentTo; - } -} diff --git a/litho-testing/src/main/java/com/facebook/litho/config/TempComponentsConfigurations.kt b/litho-testing/src/main/java/com/facebook/litho/config/TempComponentsConfigurations.kt new file mode 100644 index 00000000000..abd6a915c18 --- /dev/null +++ b/litho-testing/src/main/java/com/facebook/litho/config/TempComponentsConfigurations.kt @@ -0,0 +1,50 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.facebook.litho.config + +object TempComponentsConfigurations { + + private val original: ComponentsConfiguration = ComponentsConfiguration.defaultInstance + + private val shouldCompareCommonPropsInIsEquivalentTo = + ComponentsConfiguration.shouldCompareCommonPropsInIsEquivalentTo + + @JvmStatic + fun setShouldAddHostViewForRootComponent(value: Boolean) { + ComponentsConfiguration.defaultInstance = + ComponentsConfiguration.defaultInstance.copy(shouldAddHostViewForRootComponent = value) + } + + @JvmStatic + fun restoreShouldAddHostViewForRootComponent() { + ComponentsConfiguration.defaultInstance = original + } + + @JvmStatic + fun setShouldCompareCommonPropsInIsEquivalentTo( + shouldCompareCommonPropsInIsEquivalentTo: Boolean + ) { + ComponentsConfiguration.shouldCompareCommonPropsInIsEquivalentTo = + shouldCompareCommonPropsInIsEquivalentTo + } + + @JvmStatic + fun restoreShouldCompareCommonPropsInIsEquivalentTo() { + ComponentsConfiguration.shouldCompareCommonPropsInIsEquivalentTo = + shouldCompareCommonPropsInIsEquivalentTo + } +} diff --git a/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/BUCK b/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/BUCK index 1f0a74ffa8f..7a546f3746e 100644 --- a/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/BUCK +++ b/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/BUCK @@ -12,7 +12,7 @@ load( litho_android_library( name = "testrunner", - language = "JAVA", + pure_kotlin = False, visibility = [ "PUBLIC", ], diff --git a/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/LayoutCachingTestRunConfiguration.java b/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/LayoutCachingTestRunConfiguration.java deleted file mode 100644 index ca0dd2ab5f4..00000000000 --- a/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/LayoutCachingTestRunConfiguration.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.testing.testrunner; - -import com.facebook.litho.config.ComponentsConfiguration; -import org.junit.runners.model.FrameworkMethod; - -public class LayoutCachingTestRunConfiguration implements LithoTestRunConfiguration { - - private final ComponentsConfiguration.Builder mDefaultComponentsConfiguration = - ComponentsConfiguration.getDefaultComponentsConfigurationBuilder(); - - @Override - public void beforeTest(FrameworkMethod method) { - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder( - ComponentsConfiguration.create().shouldCacheLayouts(true)); - } - - @Override - public void afterTest(FrameworkMethod method) { - ComponentsConfiguration.setDefaultComponentsConfigurationBuilder( - mDefaultComponentsConfiguration); - } -} diff --git a/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/LayoutCachingTestRunConfiguration.kt b/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/LayoutCachingTestRunConfiguration.kt new file mode 100644 index 00000000000..5eea66d5211 --- /dev/null +++ b/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/LayoutCachingTestRunConfiguration.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.facebook.litho.testing.testrunner + +import com.facebook.litho.config.ComponentsConfiguration +import org.junit.runners.model.FrameworkMethod + +class LayoutCachingTestRunConfiguration : LithoTestRunConfiguration { + + private val defaultComponentsConfiguration: ComponentsConfiguration = + ComponentsConfiguration.defaultInstance + + override fun beforeTest(method: FrameworkMethod) { + ComponentsConfiguration.defaultInstance = + defaultComponentsConfiguration.copy(shouldCacheLayouts = true) + } + + override fun afterTest(method: FrameworkMethod) { + ComponentsConfiguration.defaultInstance = defaultComponentsConfiguration + } +} diff --git a/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/SkipRootCheckingTestRunConfiguration.java b/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/SkipRootCheckingTestRunConfiguration.java deleted file mode 100644 index aa1a12e2d37..00000000000 --- a/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/SkipRootCheckingTestRunConfiguration.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.testing.testrunner; - -import com.facebook.litho.config.ComponentsConfiguration; -import org.junit.runners.model.FrameworkMethod; - -public class SkipRootCheckingTestRunConfiguration implements LithoTestRunConfiguration { - - private final boolean mIsSkipRootCheckingEnabled = - ComponentsConfiguration.isSkipRootCheckingEnabled; - - @Override - public void beforeTest(FrameworkMethod method) { - ComponentsConfiguration.isSkipRootCheckingEnabled = !mIsSkipRootCheckingEnabled; - } - - @Override - public void afterTest(FrameworkMethod method) { - ComponentsConfiguration.isSkipRootCheckingEnabled = mIsSkipRootCheckingEnabled; - } -} diff --git a/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/SkipRootCheckingTestRunConfiguration.kt b/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/SkipRootCheckingTestRunConfiguration.kt new file mode 100644 index 00000000000..b6d2a52f932 --- /dev/null +++ b/litho-testing/src/main/java/com/facebook/litho/testing/testrunner/SkipRootCheckingTestRunConfiguration.kt @@ -0,0 +1,33 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.facebook.litho.testing.testrunner + +import com.facebook.litho.config.ComponentsConfiguration +import org.junit.runners.model.FrameworkMethod + +class SkipRootCheckingTestRunConfiguration : LithoTestRunConfiguration { + + private val isSkipRootCheckingEnabled = ComponentsConfiguration.isSkipRootCheckingEnabled + + override fun beforeTest(method: FrameworkMethod) { + ComponentsConfiguration.isSkipRootCheckingEnabled = !isSkipRootCheckingEnabled + } + + override fun afterTest(method: FrameworkMethod) { + ComponentsConfiguration.isSkipRootCheckingEnabled = isSkipRootCheckingEnabled + } +} diff --git a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java index b901317d004..bdc75d05f82 100644 --- a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java +++ b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java @@ -822,7 +822,7 @@ public RecyclerBinder build(ComponentContext c) { // off, so always disable it in that case incrementalMount = incrementalMount && ComponentContext.isIncrementalMountEnabled(c); if (preallocateMountContentHandler == null - && componentContext.mLithoConfiguration.componentsConfig.isNestedPreallocationEnabled()) { + && componentContext.mLithoConfiguration.componentsConfig.nestedPreallocationEnabled) { preallocateMountContentHandler = ComponentContext.getMountContentPreallocationHandler(c); } visibilityProcessing = @@ -4021,7 +4021,7 @@ public void onPostDraw() { } } - if (ComponentsConfiguration.isRenderInfoDebuggingEnabled()) { + if (ComponentsConfiguration.isRenderInfoDebuggingEnabled) { RenderInfoDebugInfoRegistry.setRenderInfoToViewMapping( holder.itemView, renderInfo.getDebugInfo(RenderInfoDebugInfoRegistry.SONAR_SECTIONS_DEBUG_INFO_TAG));