Foreword
this project API>= 13
after writing so many articles, I always feel that there is something missing. I think about it carefully. It turns out that I have not applied the relevant knowledge to actual combat. For those of us who have developed projects and have project experience, the project development is a little bit. However, for developers who have just come into contact with Hongmeng, it really needs a project from 0 to 1 to be tempered. It is better to teach people to fish than to fish, just do what you say, then in the next period of time, I will interspersed with actual project articles from time to time, and of course other technical articles will be updated continuously.
Regarding the actual combat of the project, I chose to choose and finally chose an Information Project. Although it is simple, it basically contains most of the learned knowledge points, such as the use of various UI components, network requests, data storage, list loading, the use of pictures, videos, web components, etc. It can be said that the project is small but rich in functions.
My plan is to share from 0 to 1 step by step, including Api knowledge points, Encapsulated knowledge points, and of course, function realization knowledge points. Data interface, simulated with real requests, here, I will build a simple local server, during which I will also open up the source code to facilitate everyone to learn and use, and the final finished product App will move today's headlines to realize, of course, it is impossible to realize 100% of the functions, and try to extract the core functions to realize them. I will also integrate the articles on the actual combat of the project at the bottom of the article for everyone to view.
Since it is the first chapter of the project, as the saying goes, sharpening the knife does not miss the firewood cutter, we will first sort out the overall structure and the basic libraries included, and try our best to realize it in combination with the actual headline project today.
Overall Project Architecture
Information projects are relatively simple. We can unify the codes into the main module for implementation. There is no problem in doing so. However, in order to combine the market orientation and future technological development, we still use componentization for development here. As for how Hongmeng terminal realizes componentization, we have shared many articles one after another before. We will not repeat them here. Why adopt componentization? Here is a simple statement: the biggest reason is decoupling, making its functional modules independent of each other, which not only facilitates subsequent functional reuse, but also enables team collaboration to detail their respective task development and reduce certain conflicts. In addition, there is one of the most prominent capabilities, that is, to reduce compilation time and improve operational testing efficiency.
To put it bluntly, for example, Project A has A video module, and then we developed Project B, which also has A video Module. If it is A component-based project, we can directly copy it from Project A for use. Compared with those who integrate all the codes into one module, its development efficiency is definitely A qualitative improvement.
Code Architecture
for the architecture in the code, our information project adopts the mainstream MVVM architecture mode, because ArkUI's UI development mode itself belongs to MVVM mode, which is simpler for us to implement.
In ArkUI, the state variable plays the role of ViewModel in MVVM mode. The UI is refreshed upward and the data is updated downward. The overall framework is as follows:
layering Description
MVVM architecture, M is the model layer, is the original data provider of the application, is responsible for storing and managing the application data and business logic, and does not directly interact with the user interface; The view layer is our page component, business component and common component. What UI draws is our view layer, such as login page, list page, edit page, etc. in the page component, the data required for each page may be completely different, or multiple pages may require the same set of data. It is mainly responsible for displaying data in the user interface and interacting with users, without any business logic. The viewModel layer is actually the link between the view and the model layer. It is responsible for managing UI status and interaction logic. Usually, a View corresponds to a ViewModel. The ViewModel monitors changes in Model data, notifies the View to update the UI, and processes user interaction events and converts them into data operations.
Many developers are not clear about the distinction between viewModel layer data and model layer data. Here, let's make a brief distinction. First, model layer data organizes data according to the entire project and project to form a complete APP business data system. The viewModel layer data provides data used on a certain page, which may be part of the business data of the entire APP. In addition, the ViewModel layer can also add auxiliary Page display data corresponding to Page. This part of data may have nothing to do with the business of this APP, but only auxiliary data that provides convenience for Page display.
Basic Component Development
with the project architecture and code architecture, the next step is to write code. We can implement it natively according to the API provided by the system. However, for future project development, we will simply make a layer of encapsulation for this information project, such as Carousel diagram, such as list, such as network request. The purpose of encapsulation is to simplify the code and improve our development efficiency.
At present, there are known basic components that need to be packaged. The first is the network library. This is for sure and is needed from the beginning. After all, any module needs such capability. The second is to refresh the library, an information item, pull-down refresh and pull-up loading, which are definitely required. The third is tab library, whether it is the main tab at the bottom, it is still the tab instruction of the news page, and there are still many places to use. The fourth is the routing library, where we use Navigation to encapsulate. Of course, not only the above, but also data storage, web loading and so on are needed. This is encountered in the actual development, and we are encapsulating it.
Related Summary
since it is the first article before the project development, we did not focus on directly starting code writing, but determined the project's architecture model, the code's architecture model, and the selection and development of basic components. Only by clarifying these can the next project development become comfortable.
In the next article, we will focus on outlining the framework of the project, so stay tuned!
This article label: Hongmeng News Information Application
Top comments (0)