From 2e783103664995245ba5b5f737233694ce5aad2a Mon Sep 17 00:00:00 2001 From: Michal Zielinski Date: Wed, 26 Jul 2023 07:21:24 -0700 Subject: [PATCH] Make LayoutScope implement BaseResourcesScope Summary: As per title. This will allow using extensions such as `dimenRes(...)`, `toPixels()` etc inside of `LayoutScope.layout()` function. Reviewed By: adityasharat Differential Revision: D47749621 fbshipit-source-id: 1b3962880df0e68bfd8d95a47519124a41151bdf --- .../facebook/rendercore/primitives/LayoutScope.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/litho-rendercore-primitives/src/main/java/com/facebook/rendercore/primitives/LayoutScope.kt b/litho-rendercore-primitives/src/main/java/com/facebook/rendercore/primitives/LayoutScope.kt index 030236e8b23..d06b7cb6759 100644 --- a/litho-rendercore-primitives/src/main/java/com/facebook/rendercore/primitives/LayoutScope.kt +++ b/litho-rendercore-primitives/src/main/java/com/facebook/rendercore/primitives/LayoutScope.kt @@ -17,14 +17,23 @@ package com.facebook.rendercore.primitives import android.content.Context +import com.facebook.rendercore.BaseResourcesScope import com.facebook.rendercore.LayoutContext +import com.facebook.rendercore.ResourceCache +import com.facebook.rendercore.ResourceResolver /** * The scope for the [Primitive] layout method. Provides access to [LayoutContext], the previous * layout data and utility methods that may help to compute the [PrimitiveLayoutResult]. */ class LayoutScope -internal constructor(val layoutContext: LayoutContext, val previousLayoutData: Any?) { - val androidContext: Context +internal constructor(val layoutContext: LayoutContext, val previousLayoutData: Any?) : + BaseResourcesScope { + override val androidContext: Context get() = layoutContext.androidContext + + override val resourceResolver: ResourceResolver + get() = + ResourceResolver( + androidContext, ResourceCache.getLatest(androidContext.resources.configuration)) }