All Downloads are FREE. Search and download functionalities are using the official Maven repository.

divkit.dsl.core.Arrays.kt Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 30.19.0
Show newest version
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))




© 2015 - 2024 Weber Informatics LLC | Privacy Policy