Skip to content

Commit

Permalink
Support NullableTreePropProvider for nullable component
Browse files Browse the repository at this point in the history
Summary:
$title

Also added a new NullableTreePropProvider function overload with TreePropValuePair

Reviewed By: pengj

Differential Revision: D65481918

fbshipit-source-id: 6490ba79178cfd3035921946f4c77b8854cab45c
  • Loading branch information
kingsleyadio authored and facebook-github-bot committed Nov 6, 2024
1 parent 7beffad commit be0fa1d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions litho-core/src/main/java/com/facebook/litho/KTreeProps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ inline fun TreePropProvider(
* case it'll return null itself.
*/
@Suppress("FunctionName")
@Deprecated(
"Please, use the new [NullableTreePropProvider] with [TreePropValuePair] args. You can use " +
"[legacyTreePropOf] for interoperability with old API")
@JvmName("NullableLegacyTreePropProvider") // avoid JVM declaration clash with overload
inline fun NullableTreePropProvider(
vararg props: ClassValuePair<*>,
crossinline component: () -> Component?
Expand All @@ -89,6 +93,19 @@ inline fun NullableTreePropProvider(
return TreePropProviderImpl(classProps = props, child = resolvedComponent)
}

/**
* Same as [TreePropProvider], but accepts a lambda that may return a nullable component, in which
* case it'll return null itself.
*/
@Suppress("FunctionName")
inline fun NullableTreePropProvider(
vararg props: TreePropValuePair<*>,
crossinline component: () -> Component?
): KComponent? {
val resolvedComponent = component() ?: return null
return TreePropProviderImpl(treeProps = props, child = resolvedComponent)
}

/** See [TreePropProvider]. */
@PublishedApi
internal class TreePropProviderImpl(
Expand Down

0 comments on commit be0fa1d

Please sign in to comment.