From 3b0cb7efadfceca1eac48fcc8e03660d3c405008 Mon Sep 17 00:00:00 2001 From: Sergey Ryabov Date: Wed, 14 Aug 2019 05:02:39 -0700 Subject: [PATCH] Use positive-driven condition for always negated flag Summary: We always negate the result of `isDisabled` method this makes it a bit hard to reason about "is not disabled" statement Reviewed By: astreet Differential Revision: D16711168 fbshipit-source-id: 59af3814773ef0b25ef614778135372c4992b090 --- .../src/main/java/com/facebook/litho/ComponentContext.java | 4 ++-- .../java/com/facebook/litho/widget/RecyclerBinderTest.java | 4 ++-- .../main/java/com/facebook/litho/widget/RecyclerBinder.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) 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 e439160acb..6a55ac0e7f 100644 --- a/litho-core/src/main/java/com/facebook/litho/ComponentContext.java +++ b/litho-core/src/main/java/com/facebook/litho/ComponentContext.java @@ -502,8 +502,8 @@ public static ComponentContext withComponentScope(ComponentContext context, Comp * you require that incremental mount is enabled (e.g. you use visibility callbacks). This is * static to avoid polluting the ComponentContext API. */ - public static boolean isIncrementalMountDisabled(ComponentContext c) { - return c.mComponentTree != null && !c.mComponentTree.isIncrementalMountEnabled(); + public static boolean isIncrementalMountEnabled(ComponentContext c) { + return c.mComponentTree == null || c.mComponentTree.isIncrementalMountEnabled(); } boolean wasLayoutCanceled() { diff --git a/litho-it/src/test/java/com/facebook/litho/widget/RecyclerBinderTest.java b/litho-it/src/test/java/com/facebook/litho/widget/RecyclerBinderTest.java index 0bc245896d..61a1d9c25d 100644 --- a/litho-it/src/test/java/com/facebook/litho/widget/RecyclerBinderTest.java +++ b/litho-it/src/test/java/com/facebook/litho/widget/RecyclerBinderTest.java @@ -5366,7 +5366,7 @@ public void testIncrementalMountDisabledWhenParentIncrementalMountIsDisabled() { .incrementalMount(false) .build(); - assertThat(ComponentContext.isIncrementalMountDisabled(parent.getContext())).isTrue(); + assertThat(ComponentContext.isIncrementalMountEnabled(parent.getContext())).isFalse(); final RecyclerBinder recyclerBinder = new RecyclerBinder.Builder() @@ -5394,7 +5394,7 @@ public void testIncrementalMountEnabledWhenParentIncrementalMountIsEnabled() { .incrementalMount(true) .build(); - assertThat(ComponentContext.isIncrementalMountDisabled(parent.getContext())).isFalse(); + assertThat(ComponentContext.isIncrementalMountEnabled(parent.getContext())).isTrue(); final RecyclerBinder recyclerBinder = new RecyclerBinder.Builder() 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 0b5c6e1d35..170c4a6606 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 @@ -687,7 +687,7 @@ public RecyclerBinder build(ComponentContext c) { // Incremental mount will not work if this ComponentTree is nested in a parent with it turned // off, so always disable it in that case - incrementalMount = incrementalMount && !ComponentContext.isIncrementalMountDisabled(c); + incrementalMount = incrementalMount && ComponentContext.isIncrementalMountEnabled(c); if (layoutInfo == null) { layoutInfo = new LinearLayoutInfo(c.getAndroidContext(), VERTICAL, false);