Utils
Methods
clickableEvents()
A composable modifier for handling click events with support for onClick, onLongClick, and onDoubleClick.
@Composable
fun Modifier.clickableEvents(
interactionSource: MutableInteractionSource,
indication: Indication?,
onClick: (() -> Unit)?,
onLongClick: (() -> Unit)?,
onDoubleClick: (() -> Unit)?
): Modifier
Parameters
- interactionSource: The MutableInteractionSource for managing interactions.
- indication: The visual indication for interactions.
- onClick: The callback for click events.
- onLongClick: The callback for long-click events.
- onDoubleClick: The callback for double-click events.
Returns
A Modifier that handles click events.
blockProvideEvent(blockProps:action:eventType:)
Provides an event handler for a specific event type if the block supports it.
fun blockProvideEvent(
blockProps: BlockProps,
action: List<NativeActionModel>,
eventType: String
): (() -> Unit)?
Parameters
- blockProps: The properties of the block, including its event handling logic.
- action: A list of NativeActionModel instances representing the actions associated with the block.
- eventType: The type of event to check and provide a handler for.
Returns
A closure representing the event handler if the event type is supported; otherwise, null.
blockProvideSlot(blockProps:slots:slotType:)
Provides the NativeBlockSlotModel for the specified slot type if the block supports it.
fun blockProvideSlot(
blockProps: BlockProps,
slots: Map<String, NativeBlockSlotModel>,
slotType: String
): NativeBlockSlotModel?
Parameters
- blockProps: The properties of the block, including its sub-blocks.
- slots: A map of slot identifiers to their corresponding NativeBlockSlotModel instances.
- slotType: The type of slot to check and provide.
Returns
The NativeBlockSlotModel for the specified slot type if the block supports it; otherwise, null.
findWindowSizeClass(prop:)
Determines the window size class based on the screen width.
@Composable
fun findWindowSizeClass(prop: NativeBlockPropertyModel?): String?
Parameters
- prop: The NativeBlockPropertyModel containing values for mobile, tablet, and desktop.
Returns
The value corresponding to the device's size class (mobile, tablet, or desktop), or null if no value is found.
blockHasSlot(blocks:slot:)
Checks if any block in the given map contains the specified slot.
fun blockHasSlot(
blocks: Map<String, NativeBlockModel>,
slot: String
): Boolean
Parameters
- blocks: A map of block identifiers to their corresponding NativeBlockModel instances.
- slot: The slot identifier to check for in the blocks.
Returns
true if the slot is found in any block; otherwise, false.
blockHasEvent(action:eventType:)
Checks if a block supports a specific event type.
fun blockHasEvent(
action: List<NativeActionModel>,
eventType: String
): Boolean
Parameters
- action: A list of NativeActionModel instances representing the actions associated with the block.
- eventType: The type of event to check for.
Returns
true if the event type is supported; otherwise, false.
blockHandleEvent(blockProps:action:eventType:)
Handles an event for a block by invoking the appropriate action handler.
fun blockHandleEvent(
blockProps: BlockProps,
action: List<NativeActionModel>,
eventType: String
)
Parameters
- blockProps: The properties of the block, including its event handling logic.
- action: A list of NativeActionModel instances representing the actions associated with the block.
- eventType: The type of event to handle.
blockHandleVariableValue(blockProps:variable:)
Processes a variable value by resolving placeholders using block properties.
fun blockHandleVariableValue(
blockProps: BlockProps,
variable: NativeVariableModel?
): String?
Parameters
- blockProps: The properties containing available variables and hierarchy context.
- variable: The variable model containing the raw value to process.
Returns
The processed string with resolved values, or null if the variable is null.
Features
- JsonPath support ($json$[phoneNumbers][{index}])
- Localization support ({local:key})
- Variable resolution ({var:name})
blockHandleVariableValue(blockProps:value:)
Processes a variable value by resolving placeholders using block properties.
fun blockHandleVariableValue(
blockProps: BlockProps,
value: String?
): String?
Parameters
- blockProps: The properties containing available variables and hierarchy context.
- value: The variable value containing the raw value to process.
Returns
The processed string with resolved values, or null if the value is null.
actionHandleVariableValue(actionProps:variable:)
Processes a variable value by resolving placeholders using action properties.
fun actionHandleVariableValue(
actionProps: ActionProps,
variable: NativeVariableModel?
): String?
Parameters
- actionProps: The properties containing available variables.
- variable: The variable model containing the raw value to process.
Returns
The processed string with resolved values, or null if the variable is null.
actionHandleVariableValue(actionProps:value:)
Processes a variable value by resolving placeholders using action properties.
fun actionHandleVariableValue(
actionProps: ActionProps,
value: String?
): String?
Parameters
- actionProps: The properties containing available variables.
- value: The variable value containing the raw value to process.
Returns
The processed string with resolved values, or null if the value is null.
Extensions on String
getVariableValue(key:value:)
Replaces a placeholder in the string with a specific value.
fun String.getVariableValue(key: String, value: String): String
Example Usage:
val template = "Hello, \{name\}!"
val result = template.getVariableValue("name", "John")
println(result) // Output: Hello, John!
Parameters
- key: The key to look for within the string (e.g., {key}).
- value: The value to replace the key with.
Returns
A new string with the placeholder replaced by the provided value.
hasOperator()
Checks if the string contains any mathematical operators.
fun String.hasOperator(): Boolean
Example Usage:
val expression = "3 + 5"
val result = expression.hasOperator()
println(result) // Output: true
Returns
true if the string contains +, -, *****, or /; otherwise, false.
evaluateString()
Evaluates the string as a JavaScript expression and returns the result.
fun String.evaluateString(): String?
Example Usage:
val expression = "3 + 5"
val result = expression.evaluateString()
println(result) // Output: 8
Returns
The evaluated result as a string, or null if an error occurs during evaluation.
evaluateMixConditionOperator(type:)
Evaluates a string that may contain mixed conditions and operators based on a specified type.
fun String.evaluateMixConditionOperator(type: String): String
Example Usage:
val expression1 = "(4 / 2 != 0) && (true == true)"
val result1 = expression1.evaluateMixConditionOperator("BOOLEAN")
println(result1) // Output: true
val expression2 = "3 + 1"
val result2 = expression2.evaluateMixConditionOperator("INT")
println(result2) // Output: 4
Parameters
- type: The desired type for the evaluation result (e.g., "BOOLEAN", "INT").
Returns
The evaluated result as a string based on the specified type.
extractKeyVariables()
Extracts key-value pairs from a string containing placeholders.
fun String.extractKeyVariables(): List<Pair<String, String?>>
Returns
A list of pairs where the first element is the key and the second element is the value (or null if absent).
Format
- {key} -> (key, null)
- {key:value} -> (key, value)