⌘K

Action

Actions let you do things in your app when something happens—like when a user presses a button or the system sends an event. They are a way for your app to react and do work.

An action is a piece of code you write using the INativeAction interface. When something happens, Nativeblocks finds the right action and runs it for you.


What happens when an Action runs?

Here's what usually happens:

  1. Something happens in your app (like a button is clicked).
  2. Nativeblocks checks which action should run by looking in the NativeActionProvider.
  3. It calls the handle(actionProps:) method in your action, passing data about the event.

INativeAction

This is just an interface that says every action must have a handle function.

interface INativeAction

Method

handle

This is the function Nativeblocks will call to run your code for the action.

fun handle(actionProps: ActionProps)
  • actionProps: All information about what happened, so your action can react properly.

INativeActionContractor

If your action needs a bit of UI (like a dialog or custom screen), use this interface.

interface INativeActionContractor

Method

ActionContractor

This is a composable function. Just put the UI you want to show here.

@Composable
fun ActionContractor()

ActionProps

Think of this as a box of data the framework gives you when an action happens. You use this data to do the right thing.

data class ActionProps

Here’s what ActionProps includes:

  • listItemIndex: The position in a list, if the event happened in a list.
  • coroutineScope: Lets you run asynchronous tasks (like network requests).
  • variables: A map of variables you can read or change.
  • onVariableChange: Use this callback when you want to update a variable.
  • blocks: All blocks related to this action.
  • onChangeBlock: Use this callback when you want to change a block.
  • trigger: Information about why the action was fired and what should happen next.
  • onHandleNextTrigger: Call this if you want the next trigger to run.
  • onHandleSuccessNextTrigger: Call this to run the next trigger only if your action was successful.
  • onHandleFailureNextTrigger: Use this if something goes wrong and you want to handle failure.

NativeActionModel

This is just some information about an action: who it is, how it runs, and what steps it should do.

data class NativeActionModel

What’s inside?

  • id: The unique id for this action.
  • key: The key or type for this action.
  • event: What event starts this action.
  • triggers: All the steps that should happen for this action.

NativeActionTriggerModel

A "trigger" is one step or branch in your action, with its own details.

data class NativeActionTriggerModel

What’s inside?

  • id: Unique id of the trigger step.
  • parentId: If this trigger belongs to another, this is its parent.
  • keyType: What kind of action this step is.
  • then: What should happen after this step finishes (see below).
  • properties: Any settings for this trigger.
  • data: Any data you want to use here.
  • subTriggers: Steps inside this step, if any.

NativeActionTriggerThen

This helps you decide what to do after a trigger runs.

enum class NativeActionTriggerThen(val then: String)

Choices are:

  • SUCCESS: If trigger worked, do this step.
  • FAILURE: If something failed, do this step.
  • NEXT: Just go to the next step.
  • END: Don’t do any more triggers.

If you give a string the enum doesn’t know, it returns END.


NativeActionTriggerPropertyModel

This describes a single setting or property for a trigger.

data class NativeActionTriggerPropertyModel
  • key: The name of the property.
  • value: The value you want to set.
  • type: The kind of value (could be "string", "boolean", etc).

NativeActionTriggerDataModel

This is just like the property model, but for data (not settings).

data class NativeActionTriggerDataModel
  • key: The name of the data.
  • value: The value you want to use.
  • type: The kind of value (like "string", "integer", etc).