divkit.dsl.core.Arrays.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-json-builder Show documentation
Show all versions of kotlin-json-builder Show documentation
DivKit is an open source Server-Driven UI (SDUI) framework. SDUI is a an emerging technique that leverage the server to build the user interfaces of their mobile app.
package divkit.dsl.core
import divkit.dsl.Color
/**
* Denotes an element of an arbitrary DivKit array.
*/
sealed interface ArrayElement
/**
* [ArrayElement] that resolves as a literal value.
*/
class LiteralArrayElement internal constructor(
val value: T,
) : ArrayElement
/**
* [ArrayElement] that resolves as an expression.
*/
class ExpressionArrayElement internal constructor(
val expression: String,
) : ArrayElement
/**
* [ArrayElement] that resolves as a literal value.
*/
fun valueArrayElement(value: T): ArrayElement = LiteralArrayElement(value)
/**
* [ArrayElement] that resolves as an expression.
*/
fun expressionArrayElement(expression: String): ArrayElement = ExpressionArrayElement(expression)
internal fun ArrayElement.serialize(): Any {
return when (this) {
is LiteralArrayElement -> value
is ExpressionArrayElement -> expression
}
}
/**
* Creates [ArrayElement] around [Color] hex.
*/
fun colorArrayElement(argb: String): ArrayElement =
LiteralArrayElement(Color(argb))