⌘K

NativeChangeVariable

A class responsible for changing the variable within the Nativeblocks system.

@NativeAction(
    keyType = "NATIVE_CHANGE_VARIABLE",
    name = "Native Change Variable",
    description = "Native Change Variable",
    version = 1
)
class NativeChangeVariable

The NativeChangeVariable class enables the modification of a value dynamically. It supports variable substitution, conditional evaluation, and arithmetic operations for property values.

The evaluateMixConditionOperator function evaluates a value that may contain mixed conditions and operators based on the variable type specified by variableKey. If the string contains conditions, it evaluates them and converts the result to a boolean string if the variable type is "BOOLEAN". If the string contains operators, it evaluates the expression and converts the result to the specified numeric type.

Supported types: "BOOLEAN", "INT", "DOUBLE", "LONG", "FLOAT", "STRING".

The evaluated variable value is returned as a string, or the original value if no conditions or operators are found.

Parameter

  • actionProps The properties of the action, including data and variables associated with the action.
  • variableKey The key that specifies which variable to change.
  • variableValue The value to assign to the variable. This value can contain expressions or conditions that need to be evaluated based on the variable type. The evaluated result will be assigned to the variable.
  • onNext A callback function that is invoked with the updated value of the variable after the action completes.
@NativeActionParameter
data class Parameter(
    val actionProps: ActionProps,
    @NativeActionData(description = "key of the variable")
    val variableKey: String,
    @NativeActionProp(
        description = "value of the variable",
        valuePicker = NativeActionValuePicker.TEXT_AREA_INPUT
    )
    val variableValue: String,
    @NativeActionEvent(then = Then.NEXT, dataBinding = ["variableKey"])
    val onNext: (String) -> Unit
)

Examples

Example 1 (for BOOLEAN type):

  • variableValue: "(4 / 2 != 0) && (true == true)"

  • Evaluated value: "true" (evaluates the condition and returns boolean as string)

Example 2 (for INT type):

  • variableValue: "(3+1)/2"

  • Evaluated value: "2" (evaluates the arithmetic expression and returns the result as an integer)

Example 3 (for STRING type):

  • variableValue: ""test" == "test""

  • Evaluated value: "true" (evaluates string equality and returns the result as string)

Example 4 (for FLOAT type):

  • variableValue: "2 * 2.5"

  • Evaluated value: "5.0" (evaluates multiplication and returns the result as float)

Example 5 (for Variable Substitution):

  • variableKey: "myVar"

  • variableValue: "Hello, {myVar}!"

  • If myVar is "World", the evaluated value will be "Hello, World!".