Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
✨ Adds parent ServerDrivenNode to the render tree (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
hernandazevedozup authored May 31, 2022
1 parent 0494492 commit 27a4f64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import br.zup.com.nimbus.compose.ComponentHandler
import com.fasterxml.jackson.core.type.TypeReference

val customComponents: Map<String, @Composable ComponentHandler> = mapOf(
"custom:text" to @Composable { element, _ ->
"custom:text" to @Composable { element, _ , _->
CustomText(element.parse(object : TypeReference<NimbusTextModel>() {})) },
"custom:personCard" to @Composable { element, _ ->
"custom:personCard" to @Composable { element, _ , _->
PersonCardComponent(element.parse(object : TypeReference<PersonCardModel>() {})) },
"material:text" to @Composable { element, _ ->
"material:text" to @Composable { element, _ , _->
NimbusText(element.parse(object : TypeReference<NimbusTextModel>() {}))
},
"layout:container" to @Composable { _, children -> NimbusContainer(children) },
"material:button" to @Composable { element, _ ->
"layout:container" to @Composable { _, children, _ -> NimbusContainer(children) },
"material:button" to @Composable { element, _ , _->
// can't use jackson to deserialize this, it has a function.
NimbusButton(
text = element.properties?.get("text") as String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import com.zup.nimbus.core.network.ViewClient
import com.zup.nimbus.core.tree.IdManager
import com.zup.nimbus.core.tree.ServerDrivenNode

typealias ComponentHandler = (element: ServerDrivenNode, children: @Composable () -> Unit) -> Unit
typealias ComponentHandler = (
element: ServerDrivenNode,
children: @Composable () -> Unit,
parentElement: ServerDrivenNode?,
) -> Unit
typealias LoadingHandler = @Composable() () -> Unit
typealias ErrorHandler = @Composable() (throwable: Throwable, retry:() -> Unit) -> Unit
const val PLATFORM_NAME = "android"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.zup.nimbus.core.tree.ServerDrivenNode
@Composable
internal fun NimbusServerDrivenView(
viewTree: ServerDrivenNode,
parentViewTree: ServerDrivenNode? = null
) {

if (!NimbusTheme.nimbusAppState.config.components.containsKey(viewTree.component)) {
Expand All @@ -18,9 +19,9 @@ internal fun NimbusServerDrivenView(
element = viewTree,
children = {
viewTree.children?.forEach {
NimbusServerDrivenView(it)
NimbusServerDrivenView(it, parentViewTree = viewTree)
}
})
}, parentElement = parentViewTree)
}
}

0 comments on commit 27a4f64

Please sign in to comment.