I ll learn with you the references to the HarmonyOS 8 function

Mondo Entertainment Updated on 2024-02-20

Dear partners, Happy Chinese New Year. We continue to learn the HarmonyOS development language ARKts. In this section, we're going to talk about @builderparam decorators: referencing @builder functions. To put it simply, a function can be transferred by declaring it with a @builder and then defining the variables of the function with @builderparam in other classes. Similar to the Android interface passing, iOS block passing. Without further ado, let's go directly to the official website for example.

Use the custom build function of the custom component or the global custom build function to initialize the @builderparam locally

This is an example of how to use the transfer of a function in the same class.

A method to initialize child component @builderparam decoration with a parent component custom constructor.

The function of the parent class is passed to the child class by reference, and the output is passed through the child class, and we can take a look at the result.

I'm going to give you an example of an iOS block value.

In this SecondViewConroller class, define the block function to determine the value transfer type.

This is where the function can be implemented to facilitate the SendViewController class.

In Android, the interface is usually used to go to **, which is equivalent to a reference to a function. Interface function, which is very common in Android development.

interface.

Business class implementation interfaces.

The business class implements interface functions.

Data processing interface.

All in all, HarmonyOS here when a developer creates a custom component and wants to add a specific feature to the component, such as adding a click to jump action in the custom component. Embedding an event method directly into a component will result in the addition of this feature everywhere the custom component is introduced, so the function reference function is hereby added. iOS and Android are similar, and there is a need to pass a reference to the function.

This section focuses on:

1. @builderparam used to decorate variables that point to @builder methods.

2. Methods @builderparam decoration can only be initialized by custom constructors (@builder methods of decoration).

3. The method of @builderparam decoration can be in two forms: parametric and paraparameter, which needs to match the type of @builder method pointed to. The method type of @builderparam decoration needs to be the same as the type of @builder method.

Related Pages