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

Commit

Permalink
feat: add support to bind in the display to the backend (#1087)
Browse files Browse the repository at this point in the history
* add support to bind in backend

* adjust code

* remove bind attribute

* adjust bind in android
  • Loading branch information
uziasferreirazup committed Oct 27, 2020
1 parent fbd8460 commit bd809a9
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import br.com.zup.beagle.android.context.tokenizer.ExpressionToken
import br.com.zup.beagle.android.context.tokenizer.TokenParser
import br.com.zup.beagle.android.utils.BeagleRegex
import br.com.zup.beagle.android.utils.getExpressions
import br.com.zup.beagle.core.BindAttribute
import java.lang.reflect.Type

sealed class Bind<T> : BindAttribute<T> {
sealed class Bind<T> {
abstract val type: Type
abstract val value: Any

data class Expression<T>(
val expressions: List<ExpressionToken>,
override val value: String,
override val type: Type
override val type: Type,
) : Bind<T>() {
constructor(
expressions: List<ExpressionToken>,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import br.com.zup.beagle.android.components.page.PageView
import br.com.zup.beagle.android.context.Bind
import br.com.zup.beagle.android.context.ContextData
import br.com.zup.beagle.android.context.valueOf
import br.com.zup.beagle.android.data.serializer.adapter.generic.BeagleGenericAdapterFactory
import br.com.zup.beagle.android.mockdata.ComponentBinding
import br.com.zup.beagle.android.mockdata.CustomAndroidAction
import br.com.zup.beagle.android.mockdata.CustomInputWidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ object NavigationBarScreenBuilder {

private fun createBeagleText(text: Bind<String>) = Container(
children = listOf(
Text(text = text, styleId = TEXT_FONT_MAX, textColor =expressionOf("@{global.textColor}")),
Text(text = text, styleId = TEXT_FONT_MAX, textColor = expressionOf("@{global.textColor}")),
Button(
text = "Update Global Context",
onPress = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package br.com.zup.beagle.serialization.jackson

import br.com.zup.beagle.core.BindAttribute
import br.com.zup.beagle.widget.context.Bind
import br.com.zup.beagle.widget.layout.ComposeComponent
import br.com.zup.beagle.widget.layout.ScreenBuilder
import com.fasterxml.jackson.databind.module.SimpleModule
Expand All @@ -36,7 +36,7 @@ class BeagleModule(
ScreenBuilderMixin::class.java
)
this.setMixInAnnotation(
getClass(BindAttribute::class, this.classLoader),
getClass(Bind::class, this.classLoader),
BindMixin::class.java
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

package br.com.zup.beagle.serialization.jackson

import br.com.zup.beagle.core.BindAttribute
import com.fasterxml.jackson.annotation.JsonValue

internal object BindMixin : BindAttribute<Any> {
internal object BindMixin {
@get:JsonValue
override val value: Any = this
val value: Any = this
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package br.com.zup.beagle.serialization.jackson

import br.com.zup.beagle.core.BindAttribute
import br.com.zup.beagle.widget.context.Bind
import br.com.zup.beagle.widget.layout.ComposeComponent
import br.com.zup.beagle.widget.layout.ScreenBuilder
import org.junit.jupiter.api.Test
Expand All @@ -35,7 +35,7 @@ internal class BeagleModuleTest {

assertEquals(ComposeComponentMixin::class.java, mixins[ComposeComponent::class.java])
assertEquals(ScreenBuilderMixin::class.java, mixins[ScreenBuilder::class.java])
assertEquals(BindMixin::class.java, mixins[BindAttribute::class.java])
assertEquals(BindMixin::class.java, mixins[Bind::class.java])
}

private fun KClass<BeagleModule>.property(name: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import br.com.zup.beagle.builder.BeagleBuilder
import br.com.zup.beagle.builder.widget.EdgeValueBuilder
import br.com.zup.beagle.builder.widget.FlexBuilder
import br.com.zup.beagle.builder.widget.SizeBuilder
import br.com.zup.beagle.widget.context.Bind
import br.com.zup.beagle.core.CornerRadius
import br.com.zup.beagle.core.Display
import br.com.zup.beagle.core.PositionType
Expand All @@ -31,7 +32,7 @@ import br.com.zup.beagle.widget.core.Size
fun style(block: StyleBuilder.() -> Unit) = StyleBuilder()
.apply(block).build()

class StyleBuilder: BeagleBuilder<Style> {
class StyleBuilder : BeagleBuilder<Style> {
var backgroundColor: String? = null
var cornerRadius: CornerRadius? = null
var size: Size? = null
Expand All @@ -40,7 +41,7 @@ class StyleBuilder: BeagleBuilder<Style> {
var position: EdgeValue? = null
var flex: Flex? = null
var positionType: PositionType? = null
var display: Display? = null
var display: Bind<Display>? = null
var borderColor: String? = null
var borderWidth: Double? = null

Expand All @@ -52,7 +53,7 @@ class StyleBuilder: BeagleBuilder<Style> {
fun position(position: EdgeValue?) = this.apply { this.position = position }
fun flex(flex: Flex?) = this.apply { this.flex = flex }
fun positionType(positionType: PositionType?) = this.apply { this.positionType = positionType }
fun display(display: Display?) = this.apply { this.display = display }
fun display(display: Bind<Display>?) = this.apply { this.display = display }
fun borderColor(borderColor: String?) = this.apply { this.borderColor = borderColor }
fun borderWidth(borderWidth: Double?) = this.apply { this.borderWidth = borderWidth }

Expand Down Expand Up @@ -88,15 +89,15 @@ class StyleBuilder: BeagleBuilder<Style> {
positionType(block.invoke())
}

fun display(block: () -> Display?) {
fun display(block: () -> Bind<Display>?) {
display(block.invoke())
}

fun borderColor(block: () -> String?){
fun borderColor(block: () -> String?) {
borderColor(block.invoke())
}

fun borderWidth(block: () -> Double?){
fun borderWidth(block: () -> Double?) {
borderWidth(block.invoke())
}

Expand All @@ -117,7 +118,7 @@ class StyleBuilder: BeagleBuilder<Style> {

fun cornerRadius(block: CornerRadiusBuilder.() -> Unit) = CornerRadiusBuilder().apply(block).build()

class CornerRadiusBuilder: BeagleBuilder<CornerRadius> {
class CornerRadiusBuilder : BeagleBuilder<CornerRadius> {
var radius: Double = 0.0

fun radius(radius: Double) = this.apply { this.radius = radius }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.com.zup.beagle.core

import br.com.zup.beagle.widget.context.Bind
import br.com.zup.beagle.widget.core.EdgeValue
import br.com.zup.beagle.widget.core.Flex
import br.com.zup.beagle.widget.core.Size
Expand Down Expand Up @@ -59,7 +60,7 @@ data class Style (
val position: EdgeValue? = null,
val flex: Flex? = null,
val positionType: PositionType? = null,
val display: Display? = null
val display: Bind<Display>? = null
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

package br.com.zup.beagle.widget.context

import br.com.zup.beagle.core.BindAttribute
import br.com.zup.beagle.widget.expression.ExpressionHelper
import java.io.Serializable

sealed class Bind<T> : BindAttribute<T>, Serializable {
data class Expression<T>(override val value: String) : Bind<T>() {
sealed class Bind<T> : Serializable {
data class Expression<T>(val value: String) : Bind<T>() {
constructor(expression: ExpressionHelper<T>) : this(expression.representation)
}

data class Value<T : Any>(override val value: T) : Bind<T>()
data class Value<T : Any>(val value: T) : Bind<T>()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package br.com.zup.beagle.widget.expression


sealed class ExpressionHelper<T>(private val intermediate: String) {
companion object {
private const val START = "@{"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object ListViewDslScreenBuilder : ScreenBuilder {
children{

+text {
text{valueOf("Dynamic $listDirection ListView")}
text{ valueOf("Dynamic $listDirection ListView") }
}.style {
margin {
bottom = 10.unitReal()
Expand Down

0 comments on commit bd809a9

Please sign in to comment.