Action
Actions in Nativeblocks represent operations or interactions triggered by user events or system processes. They are the building blocks for defining dynamic behaviors within the application.
Each action is implemented using the INativeAction interface and is executed based on the provided properties and triggers.
Example of an Action Workflow
- An event occurs (e.g., button press).
- The corresponding action is retrieved from the NativeActionProvider.
- The handle(actionProps:) method is invoked to perform the action logic.
NativeActionProvider
A singleton class responsible for managing and providing actions within the Nativeblocks SDK. The NativeActionProvider class maintains a registry of actions that can be dynamically provided based on the action type.
class NativeActionProvider
INativeAction
Defines the contract for handling native actions within the framework.
interface INativeAction
Methods
handle
Handles the specified action properties.
fun handle(actionProps: ActionProps)
Parameters
- actionProps: The properties of the action to handle.
INativeActionContractor
Defines a contract for composable action contractors in the native framework.
interface INativeActionContractor
Methods
ActionContractor
Composable function to define the UI for an action contractor.
@Composable
fun ActionContractor()
ActionProps
Represents the properties required to handle an action in the native framework.
data class ActionProps
Properties
- listItemIndex: Index of the list item associated with the action.
- coroutineScope: Coroutine scope for executing asynchronous operations.
- variables: Map of variables used in the action, identified by their keys.
- onVariableChange: Callback invoked when a variable changes.
- blocks: Map of blocks associated with the action, identified by their keys.
- onChangeBlock: Callback invoked when a block changes.
- trigger: Trigger model representing the conditions and outcomes of the action.
- onHandleNextTrigger: Callback invoked to handle the next trigger in the sequence.
- onHandleSuccessNextTrigger: Callback invoked to handle the next trigger upon success.
- onHandleFailureNextTrigger: Callback invoked to handle the next trigger upon failure.
NativeActionModel
Represents an action within a native UI framework, including its event triggers and associated metadata.
data class NativeActionModel
Properties
- id: Unique identifier of the action.
- key: Key associated with the action.
- event: Event that triggers the action.
- triggers: List of triggers that define the sequence and conditions for executing the action.
NativeActionTriggerModel
Represents a trigger for an action, including its properties, data, and hierarchical sub-triggers.
data class NativeActionTriggerModel
Properties
- id: Unique identifier of the trigger.
- parentId: Identifier of the parent trigger to establish hierarchy.
- keyType: Type of the key associated with the trigger.
- then: Defines what happens after the trigger is executed.
- properties: Properties associated with the trigger.
- data: Data associated with the trigger.
- subTriggers: List of sub-triggers nested within this trigger.
NativeActionTriggerThen
Defines the possible outcomes of executing a trigger.
enum class NativeActionTriggerThen(val then: String)
Values
- SUCCESS: Trigger executed successfully.
- FAILURE: Trigger execution failed.
- NEXT: Proceed to the next trigger.
- END: End the trigger sequence.
Parameters
- then: The string representation of the trigger outcome.
Returns
The matching enum value or END if no match is found.
NativeActionTriggerPropertyModel
Represents a property associated with an action trigger, including its key, value, and type.
data class NativeActionTriggerPropertyModel
Properties
- key: Key identifying the property.
- value: Value of the property.
- type: Type of the property (e.g., string, boolean).
NativeActionTriggerDataModel
Represents a piece of data associated with an action trigger, including its key, value, and type.
data class NativeActionTriggerDataModel
Properties
- key: Key identifying the data entry.
- value: Value of the data entry.
- type: Type of the data entry (e.g., string, integer).