This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removes heavy logic * unfinished * seems to be working for basic cases * ParentName + Computed * fixes * fixes * undoes unnecessary modifications * fixes tests and other validations * undoes unnecessary modifications * upgrades nimbus-core from alpha5 to alpha6 * fixes extra recompositions * fix for detekt
- Loading branch information
1 parent
370130f
commit d9bc063
Showing
6 changed files
with
110 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 22 additions & 3 deletions
25
compose-sample/src/main/java/br/com/zup/nimbus/compose/sample/components/NimbusContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
package br.com.zup.nimbus.compose.sample.components | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import br.zup.com.nimbus.compose.ComponentData | ||
import br.zup.com.nimbus.compose.NimbusTheme | ||
import com.zup.nimbus.core.deserialization.ComponentDeserializer | ||
|
||
private fun getColor(colorString: String): Color { | ||
return Color(android.graphics.Color.parseColor(colorString)) | ||
} | ||
|
||
@Composable | ||
fun NimbusContainer(children: @Composable () -> Unit) { | ||
Column { | ||
children() | ||
fun NimbusContainer(it: ComponentData) { | ||
val logger = NimbusTheme.nimbus.logger | ||
val deserializer = ComponentDeserializer(logger, it.node) | ||
deserializer.start() | ||
val background = deserializer.asStringOrNull("backgroundColor") | ||
val padding = deserializer.asDoubleOrNull("padding") | ||
var modifier = Modifier.padding((padding ?: 0.0).dp) | ||
if (background != null) modifier = modifier.background(color = getColor(background)) | ||
Column(modifier = modifier) { | ||
it.children() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 13 additions & 1 deletion
14
compose/src/main/java/br/zup/com/nimbus/compose/ComponentData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
package br.zup.com.nimbus.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import com.zup.nimbus.core.tree.ServerDrivenNode | ||
|
||
@Immutable | ||
class ComponentData( | ||
val node: ServerDrivenNode, | ||
val parent: ServerDrivenNode?, | ||
val children: @Composable () -> Unit, | ||
) | ||
) { | ||
private val hash: Int = node.properties?.hashCode() ?: 0 | ||
|
||
override fun hashCode(): Int { | ||
return hash | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
return if (other is ComponentData) other.hashCode() == hash else false | ||
} | ||
} |