Skip to content

Commit

Permalink
fix/836 Update English version of ios custom-action.md (#853)
Browse files Browse the repository at this point in the history
* Update step 2 "create a custom action"

- add warning block just after code example

Signed-off-by: Adriano Vieira <adriano.vieira@zup.com.br>

* Update English version of custom-action.md

- Update it simular to its Portuguese version

Signed-off-by: Adriano Vieira <adriano.vieira@zup.com.br>

* Update content/en/ios/customization/custom-actions/custom-action.md

Co-authored-by: Hector Custódio <hector.custodio@zup.com.br>

* Update content/en/ios/customization/custom-actions/custom-action.md

Co-authored-by: Hector Custódio <hector.custodio@zup.com.br>

Co-authored-by: Hector Custódio <hector.custodio@zup.com.br>
  • Loading branch information
adrianovieira and hectorcustodiozup committed Mar 4, 2022
1 parent a08aa5b commit fbab128
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions content/en/ios/customization/custom-actions/custom-action.md
Expand Up @@ -67,44 +67,36 @@ struct CustomAction: Action {
}
}
```
{{% alert color="warning" %}}
Use the `@AutoCodable` annotation for `Action` or `ServerDrivenComponent` properties type (whether they are lists or optional) if your action receives either a component or action, so that swift can synthesize the `init(from decoder: Decoder)` initializer.

In technical terms, the `AutoCodable` is a property wrapper that implements the polymorphic serialization and deserialization logic of Beagle's generic types, so we don't need to implement the `init(from decoder: Decoder)`, as Swift can synthesize it, considering that all the properties of our widget comply to Codable.
{{% /alert %}}

### **Step 3: How to Register an Action.**

It is mandatory to register actions on Beagle. Inside the beagle config file use dependencies to register.
Finally, we need to register our custom action on Beagle.

Therefore, to **register it on Beagle**, just call the `register` function from `Coder` (a Beagle's public dependency) into the Beagle environment configuration process.

{{% alert color="info" %}} To learn more about dependencies. [Beagle Dependencies]({{< ref path="" lang="en" >}}). {{% /alert %}}
{{% alert color="info" %}} To learn more about dependencies: [Beagle Dependencies]({{< ref path="" lang="en" >}}). {{% /alert %}}

The register method has two constructors; the first receives just the `action` param and the second receives the `action` and `named` params.
The `register` method is overloaded by two different arguments (`action` and `named`). You can call it to receives just the `action` param or to receives the `action` and `named` params.

**action:** Pass the struct of the action.
**action:** Action type.

**named:** Parameter to set the action name. It is not mandatory to inform it, however, you might need it when the action name is registered differently than what you created in the backend. In this case, the parameter will be used in deserializations to find your action.
**named:** Parameter to set the action name. It is not mandatory to inform it, however, you might need it when the component name is registered differently than what you created in the backend. In this case, the parameter will be used in deserializations to find your action.

Ways to Register

1º The first way to register.
```swift
dependencies.decoder.register(action: CustomAction.self)
coder.register(action: CustomAction.self)
```

2º The second way to register.
```swift
dependencies.decoder.register(action: CustomAction.self, named: "CustomAction")
coder.register(action: CustomAction.self, named: "CustomAction")
```

After registering your customization component, you can use it via server-driven.

### **Step 3: How to use an action**

To use the Beagle's actions, the component you are going to use just needs a parameter of the type `Action`.

Below is an example of how to use it on a button that performs the custom action on the click event:

```swift
Button(
text: "do request",
onPress: [
CustomAction( mensagem: "I am an Alet")
]
)
```

0 comments on commit fbab128

Please sign in to comment.