⌘K

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 protocol and is executed based on the provided properties and triggers.


Example of an Action Workflow

  1. An event occurs (e.g., button press).
  2. The corresponding action is retrieved from the NativeActionProvider.
  3. 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

Protocol that defines the behavior for a native action. The INativeAction protocol is used for implementing custom actions that can handle specific properties and operations.

public protocol INativeAction 

Requirements

handle(actionProps:​)

Handles the action with the given properties.

func handle(actionProps: ActionProps)
Parameters
  • actionProps: The properties and state information needed to execute the action.

ActionProps

Represents the properties associated with a native action. The ActionProps struct is used to pass all the necessary information required to perform an action, including variables, blocks, triggers, and callbacks.

public struct ActionProps 

Properties

listItemIndex

The index of the item in the list that the action applies to (if applicable).

public var listItemIndex: Int? = nil

variables

A dictionary of variables used in the action.

public var variables: [String: NativeVariableModel]? = nil

onVariableChange

Callback function to handle changes to a variable.

public var onVariableChange: ((NativeVariableModel) -> Void)? = nil

blocks

A dictionary of blocks used in the action.

public var blocks: [String: NativeBlockModel]? = nil

onChangeBlock

Callback function to handle changes to a block.

public var onChangeBlock: ((NativeBlockModel) -> Void)? = nil

trigger

The trigger that is associated with this action.

public var trigger: NativeActionTriggerModel? = nil

onHandleNextTrigger

Callback function to handle the next trigger in the sequence.

public var onHandleNextTrigger: ((NativeActionTriggerModel) -> Void)? = nil

onHandleSuccessNextTrigger

Callback function to handle the success of the current trigger and move to the next trigger.

public var onHandleSuccessNextTrigger: ((NativeActionTriggerModel) -> Void)? = nil

onHandleFailureNextTrigger

Callback function to handle the failure of the current trigger and move to the next trigger.

public var onHandleFailureNextTrigger: ((NativeActionTriggerModel) -> Void)? = nil

NativeActionModel

Represents a model for a native action, which is used to define user interactions or system events.

public struct NativeActionModel: Hashable, Codable 

Inheritance

Codable, Hashable

Properties

id

The unique identifier of the action.

public let id: String?

key

The key associated with the action.

public let key: String?

event

The event that triggers this action.

public let event: String?

triggers

A list of triggers associated with this action.

public let triggers: [NativeActionTriggerModel?]?

NativeActionTriggerModel

Represents a trigger for a native action, defining the conditions and outcomes of an action.

public struct NativeActionTriggerModel: Hashable, Codable 

Inheritance

Codable, Hashable

Properties

id

The unique identifier of the trigger.

public let id: String?

parentId

The identifier of the parent trigger, if any.

public let parentId: String?

keyType

The type of key used for the trigger.

public let keyType: String?

then

The outcome of the trigger when certain conditions are met.

public let then: NativeActionTriggerThen?

properties

A dictionary of properties associated with this trigger.

public let properties: [String: NativeActionTriggerPropertyModel]?

data

A dictionary of data models that belong to this trigger.

public let data: [String: NativeActionTriggerDataModel]?

subTriggers

A list of sub-triggers for hierarchical trigger definitions.

public var subTriggers: [NativeActionTriggerModel?]?

NativeActionTriggerDataModel

Represents data associated with a trigger, including key-value pairs and their types.

public struct NativeActionTriggerDataModel: Hashable, Codable 

Inheritance

Codable, Hashable

Properties

key

The key associated with the data.

public let key: String

value

The value of the data.

public let value: String

type

The type of the data.

public let type: String

NativeActionTriggerPropertyModel

Represents a property model for a trigger, including key-value pairs and their types.

public struct NativeActionTriggerPropertyModel: Hashable, Codable 

Inheritance

Codable, Hashable

Properties

key

The key associated with the property.

public let key: String

value

The value of the property.

public let value: String

type

The type of the property.

public let type: String

NativeActionTriggerThen

Represents the possible outcomes for a trigger action.

public enum NativeActionTriggerThen: String, Hashable, Codable 

Inheritance

Codable, Hashable, String

Enumeration Cases

success

The action will be marked as successful.

case success = "SUCCESS"

failure

The action has failed.

case failure = "FAILURE"

next

Move to the next step in the action sequence.

case next = "NEXT"

end

End the action sequence.

case end = "END"