Skip to content

Commit 3097a92

Browse files
Andrew Wangfacebook-github-bot
authored andcommitted
Back out "Remove nullable context"
Summary: Original commit changeset: cc559c085a1b Original Phabricator Diff: D61470736 Differential Revision: D62000179 fbshipit-source-id: e89a61694864b461a91778017df90fb88f39601f
1 parent a964eca commit 3097a92

File tree

11 files changed

+59
-96
lines changed

11 files changed

+59
-96
lines changed

litho-core/src/main/java/com/facebook/litho/LithoNodeUtils.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ object LithoNodeUtils {
126126
id = id,
127127
component = hostComponent,
128128
commonDynamicProps = commonDynamicProps,
129-
context = context,
129+
context =
130+
if (context.lithoConfiguration.componentsConfig.enableNonNullableContext) {
131+
context
132+
} else {
133+
null
134+
},
130135
node = node,
131136
importantForAccessibility = node.importantForAccessibility,
132137
updateState = MountSpecLithoRenderUnit.STATE_UNKNOWN,
@@ -164,7 +169,6 @@ object LithoNodeUtils {
164169
id = MountState.ROOT_HOST_ID, // The root host (LithoView) always has ID 0
165170
component = hostComponent,
166171
commonDynamicProps = commonDynamicProps,
167-
context = context,
168172
node = node,
169173
importantForAccessibility = node.importantForAccessibility,
170174
updateState =
@@ -284,7 +288,12 @@ object LithoNodeUtils {
284288
id = id,
285289
component = component,
286290
commonDynamicProps = null, /* Drawables don't bind dynamic props */
287-
context = context,
291+
context =
292+
if (context.lithoConfiguration.componentsConfig.enableNonNullableContext) {
293+
context
294+
} else {
295+
null
296+
},
288297
node = node,
289298
importantForAccessibility = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO,
290299
updateState =
@@ -307,7 +316,7 @@ object LithoNodeUtils {
307316
id: Long,
308317
component: Component,
309318
commonDynamicProps: SparseArray<DynamicValue<*>>? = null,
310-
context: ComponentContext,
319+
context: ComponentContext? = null,
311320
node: LithoNode,
312321
importantForAccessibility: Int,
313322
@UpdateState updateState: Int,

litho-core/src/main/java/com/facebook/litho/LithoReducer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ internal object LithoReducer {
200200
id = MountState.ROOT_HOST_ID,
201201
component = HostComponent.create(context),
202202
commonDynamicProps = null,
203-
context = context,
203+
context = null,
204204
nodeInfo = null,
205205
flags = 0,
206206
importantForAccessibility = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO,

litho-core/src/main/java/com/facebook/litho/LithoRenderUnit.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ protected constructor(
3232
val flags: Int,
3333
importantForAccessibility: Int,
3434
renderType: RenderType,
35-
@field:JvmField val componentContext: ComponentContext,
35+
@field:JvmField val componentContext: ComponentContext?,
3636
private val _debugKey: String?
3737
) : RenderUnit<Any>(renderType), TransitionRenderUnit {
3838

3939
override val debugKey: String
40-
get() = _debugKey ?: componentContext.globalKey
40+
get() = _debugKey ?: componentContext?.globalKey ?: id.toString()
4141

4242
// the A11Y prop for descendants has been corrected
4343
val importantForAccessibility: Int =
@@ -73,15 +73,15 @@ protected constructor(
7373
const val LAYOUT_FLAG_HAS_TOUCH_EVENT_HANDLERS = 1 shl 5
7474

7575
@JvmStatic
76-
fun getComponentContext(item: MountItem): ComponentContext =
76+
fun getComponentContext(item: MountItem): ComponentContext? =
7777
(item.renderTreeNode.renderUnit as LithoRenderUnit).componentContext
7878

7979
@JvmStatic
80-
fun getComponentContext(node: RenderTreeNode): ComponentContext =
80+
fun getComponentContext(node: RenderTreeNode): ComponentContext? =
8181
(node.renderUnit as LithoRenderUnit).componentContext
8282

8383
@JvmStatic
84-
fun getComponentContext(unit: LithoRenderUnit): ComponentContext = unit.componentContext
84+
fun getComponentContext(unit: LithoRenderUnit): ComponentContext? = unit.componentContext
8585

8686
@JvmStatic
8787
fun getRenderUnit(item: MountItem): LithoRenderUnit = getRenderUnit(item.renderTreeNode)

litho-core/src/main/java/com/facebook/litho/MountSpecLithoRenderUnit.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private constructor(
4343
flags: Int,
4444
importantForAccessibility: Int,
4545
@UpdateState val updateState: Int,
46-
context: ComponentContext,
46+
context: ComponentContext?,
4747
debugKey: String?
4848
) :
4949
LithoRenderUnit(
@@ -220,7 +220,7 @@ private constructor(
220220
id: Long,
221221
component: Component,
222222
commonDynamicProps: SparseArray<DynamicValue<Any?>>?,
223-
context: ComponentContext,
223+
context: ComponentContext?,
224224
nodeInfo: NodeInfo?,
225225
flags: Int,
226226
importantForAccessibility: Int,

litho-core/src/main/java/com/facebook/litho/PrimitiveLithoRenderUnit.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package com.facebook.litho
1817

1918
import android.content.Context
@@ -34,7 +33,7 @@ private constructor(
3433
flags: Int,
3534
importantForAccessibility: Int,
3635
val primitiveRenderUnit: PrimitiveRenderUnit<Any>,
37-
context: ComponentContext,
36+
context: ComponentContext?,
3837
debugKey: String?
3938
) :
4039
LithoRenderUnit(
@@ -147,7 +146,7 @@ private constructor(
147146
fun create(
148147
component: Component,
149148
commonDynamicProps: SparseArray<DynamicValue<Any?>>?,
150-
context: ComponentContext,
149+
context: ComponentContext?,
151150
nodeInfo: NodeInfo?,
152151
flags: Int,
153152
importantForAccessibility: Int,

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ internal constructor(
158158
@JvmField val enableHostWillNotDraw: Boolean = false,
159159
/** This will enable logging for render in-flight */
160160
@JvmField val enableLoggingForRenderInFlight: Boolean = false,
161+
/** This will make sure context is not nullable for host render unit and drawable render unit */
162+
@JvmField val enableNonNullableContext: Boolean = false,
161163
/**
162164
* This will unset TPs from the CT's context, and use the one present in the CT directly as the
163165
* ultimate source of truth.
@@ -358,6 +360,7 @@ internal constructor(
358360
private var enableResolveWithoutSizeSpec = baseConfig.enableResolveWithoutSizeSpec
359361
private var enableHostWillNotDraw = baseConfig.enableHostWillNotDraw
360362
private var enableLoggingForRenderInFlight = baseConfig.enableLoggingForRenderInFlight
363+
private var enableNonNullableContext = baseConfig.enableNonNullableContext
361364

362365
fun shouldAddHostViewForRootComponent(enabled: Boolean): Builder = also {
363366
shouldAddHostViewForRootComponent = enabled
@@ -458,6 +461,10 @@ internal constructor(
458461
enableLoggingForRenderInFlight = enabled
459462
}
460463

464+
fun enableNonNullableContext(enabled: Boolean): Builder = also {
465+
enableNonNullableContext = enabled
466+
}
467+
461468
fun build(): ComponentsConfiguration {
462469
return baseConfig.copy(
463470
shouldAddHostViewForRootComponent = shouldAddHostViewForRootComponent,
@@ -492,7 +499,7 @@ internal constructor(
492499
enableResolveWithoutSizeSpec = enableResolveWithoutSizeSpec,
493500
enableHostWillNotDraw = enableHostWillNotDraw,
494501
enableLoggingForRenderInFlight = enableLoggingForRenderInFlight,
495-
)
502+
enableNonNullableContext = enableNonNullableContext)
496503
}
497504
}
498505
}

litho-it/src/main/java/com/facebook/litho/MountItemTestHelper.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,14 @@ object MountItemTestHelper {
2525
fun create(
2626
component: Component,
2727
content: Any,
28-
context: ComponentContext,
2928
info: NodeInfo?,
3029
bounds: Rect?,
3130
flags: Int,
3231
importantForAccessibility: Int
3332
): MountItem {
3433
val unit: LithoRenderUnit =
3534
MountSpecLithoRenderUnit.create(
36-
0,
37-
component,
38-
null,
39-
context,
40-
info,
41-
flags,
42-
importantForAccessibility,
43-
STATE_UNKNOWN,
44-
null)
35+
0, component, null, null, info, flags, importantForAccessibility, STATE_UNKNOWN, null)
4536
val width = bounds?.width() ?: 0
4637
val height = bounds?.height() ?: 0
4738
val node =

litho-it/src/test/java/com/facebook/litho/ComponentHostTest.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,6 @@ class ComponentHostTest {
648648
MountItemTestHelper.create(
649649
if (content is Drawable) drawableComponent else viewComponent,
650650
content,
651-
context,
652651
nodeInfo,
653652
if (content is Drawable) content.bounds else null,
654653
flags,
@@ -661,13 +660,7 @@ class ComponentHostTest {
661660
val nodeInfo = NodeInfo()
662661
val mountItem =
663662
MountItemTestHelper.create(
664-
viewComponent,
665-
view,
666-
context,
667-
nodeInfo,
668-
null,
669-
flags,
670-
View.IMPORTANT_FOR_ACCESSIBILITY_AUTO)
663+
viewComponent, view, nodeInfo, null, flags, View.IMPORTANT_FOR_ACCESSIBILITY_AUTO)
671664
host.unmount(index, mountItem)
672665
return mountItem
673666
}
@@ -677,7 +670,6 @@ class ComponentHostTest {
677670
MountItemTestHelper.create(
678671
viewComponent,
679672
content,
680-
context,
681673
null,
682674
Rect(1, 1, 1, 1),
683675
0,

litho-it/src/test/java/com/facebook/litho/MountItemTest.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,7 @@ class MountItemTest {
8787

8888
private fun create(content: Any): MountItem =
8989
MountItemTestHelper.create(
90-
component,
91-
content,
92-
context,
93-
nodeInfo,
94-
null,
95-
flags,
96-
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES)
90+
component, content, nodeInfo, null, flags, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES)
9791

9892
@Test
9993
fun testIsBound() {
@@ -210,7 +204,6 @@ class MountItemTest {
210204
TestDrawableComponent.create(context, true, true, true /* implementsAccessibility */)
211205
.build(),
212206
content,
213-
context,
214207
nodeInfo,
215208
null,
216209
flags,
@@ -225,7 +218,6 @@ class MountItemTest {
225218
TestDrawableComponent.create(context, true, true, true /* implementsAccessibility */)
226219
.build(),
227220
content,
228-
context,
229221
nodeInfo,
230222
null,
231223
flags,
@@ -240,7 +232,6 @@ class MountItemTest {
240232
TestDrawableComponent.create(context, true, true, true /* implementsAccessibility */)
241233
.build(),
242234
content,
243-
context,
244235
nodeInfo,
245236
null,
246237
flags,

litho-it/src/test/java/com/facebook/litho/TransitionTest.kt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
package com.facebook.litho
1818

19-
import android.content.Context
2019
import android.graphics.Rect
21-
import androidx.test.core.app.ApplicationProvider
2220
import com.facebook.litho.Transition.RootBoundsTransition
2321
import com.facebook.litho.animation.AnimatedProperties
2422
import com.facebook.litho.animation.DimensionValue
@@ -27,7 +25,6 @@ import com.facebook.litho.testing.testrunner.LithoTestRunner
2725
import com.facebook.litho.widget.SimpleMountSpecTester
2826
import com.facebook.rendercore.transitions.TransitionUtils
2927
import org.assertj.core.api.Assertions.assertThat
30-
import org.junit.Before
3128
import org.junit.Test
3229
import org.junit.runner.RunWith
3330
import org.mockito.kotlin.mock
@@ -36,13 +33,6 @@ import org.mockito.kotlin.whenever
3633
@RunWith(LithoTestRunner::class)
3734
class TransitionTest {
3835

39-
private lateinit var context: ComponentContext
40-
41-
@Before
42-
fun setup() {
43-
context = ComponentContext(ApplicationProvider.getApplicationContext<Context>())
44-
}
45-
4636
@Test
4737
fun testCollectRootBoundsTransitions() {
4838
val transition =
@@ -116,15 +106,7 @@ class TransitionTest {
116106
}
117107
val rootUnit: LithoRenderUnit =
118108
MountSpecLithoRenderUnit.create(
119-
0,
120-
component,
121-
null,
122-
context = context,
123-
null,
124-
0,
125-
0,
126-
MountSpecLithoRenderUnit.STATE_UNKNOWN,
127-
null)
109+
0, component, null, null, null, 0, 0, MountSpecLithoRenderUnit.STATE_UNKNOWN, null)
128110
whenever(layoutState.getMountableOutputAt(0))
129111
.thenReturn(create(rootUnit, Rect(0, 0, 300, 100), null, null))
130112
val animateFrom =

0 commit comments

Comments
 (0)