We know that there will be a large number of duplicate interfaces in the development of APP, and if each interface is written, there will inevitably be many of the same, resulting in low maintainability and poor quality of the project. Therefore, custom components are not only common in Android and iOS, but also in HarmonyOS development. The decorator @styles for reuse of common styles has become the first choice for HarmonyOS custom components.
The styles decorator can distill multiple styles into a single method that can be called directly at the location declared by the component. @styles decorator allows you to quickly define and reuse custom styles. Used to quickly define and reuse custom styles.
Styles can be defined in the global or in the component.
Note: 1. The function keyword needs to be added in front of the method globally, and the function keyword does not need to be added when defined in the component.
2. @styles only supports generic attributes and generic events. @styles method does not support parameters.
It is wrong to define the component style in this way.
The above is the usage of HarmonyOS custom component styles. According to my previous chapters, I usually compare Android to iOS. Now let's compare.
There are generally two ways to customize components for Android.
1. Define this component by inheriting the view or layout, and then reference it.
2. By writing a common XML layout, and then go to each layout reference.
Inherit the view definition component.
By defining the header XML, then reference it in other XML.
The method of customizing components for iOS is similar to that of Android, and there are probably two kinds of them.
1. Pure ** inheritance UIview.
2. XIB custom view.
Pure ** inherits UIview
xib custom view
In short, in my experience, there are many similarities in mobile development, as long as you learn to draw inferences from one end and the other end, and migrate, it is easy to understand. Okay, that's all for this section, we'll see you in the next section.