js-ui-framework.md 4.2 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
# JS UI Framework<a name="EN-US_TOPIC_0000001087318673"></a>

-   [Introduction](#section11660541593)
-   [Directory Structure](#section179173014915)
-   [Usage](#section1711605017917)
-   [Repositories Involved](#section1599816111011)

## Introduction<a name="section11660541593"></a>

The OpenHarmony JS UI framework provides basic, container, and canvas UI components and standard CSS animation capabilities. It supports the web-development-like programming paradigm.

-   **Web-development-like paradigm**

    The JS UI framework supports languages that are similar to those for web development, such as HTML and CSS. You can use them to describe the page layout and style, and use JavaScript \(conforming to the ECMAScript specification\) for page behavior. This paradigm allows you to avoid code for UI state switching. The view configuration information is intuitive.


**Figure  1**  JS UI framework<a name="fig15956152211427"></a>  


![](figures/en-us_image_0000001077953992.png)

The JS UI framework consists of the application, framework, engine, and porting layers.

-   **Application**

    Contains applications with Feature Abilities \(FAs\) developed with the JS UI framework. The FA application in this document refers to the application with FAs developed using JavaScript.

-   **Framework**

    Parses UI pages and provides the Model-View-ViewModel \(MVVM\), page routing, custom components and more for front end development.

-   **Engine**

    Accomplishes animation parsing, Document Object Model \(DOM\) building, layout computing, rendering command–based building and drawing, and event management.

-   **Porting Layer**

    Abstracts the platform layer to provide interfaces for the interconnection with the OS. For example, interconnections of events, rendering pipelines, and lifecycles.


## Directory Structure<a name="section179173014915"></a>

The source code of the framework is stored in  **/foundation/ace**. The following shows the directory structure.

```
/foundation/ace
├── ace_engine                       # JS UI framework
├── ace_engine_lite                  # JS UI framework for the mini system and above
└── napi                             # JS APIs for extending the native development module
```

## Usage<a name="section1711605017917"></a>

-   JavaScript FA development directory

After a project is created, its  **js**  directory is displayed.

**Figure  2**  Development directory<a name="fig343917486112"></a>  
![](figures/development-directory.png "development-directory")

The  **i18n**  directory stores JSON files for various locales. A  **pages**  subfolder contains multiple pages and each consists of  **.hml**,  **.css**, and  **.js**  files.

-   **main \> js \> default \> i18n \> en-US.json**: defines the variables displayed on pages in English. Similarly,  **zh-CN.json**  defines the page content in Chinese.

    ```
    {
      "strings": {
        "hello": "Hello",
        "world": "World"
      }
    }
    ```

-   **main \> js \> default \> pages \> index \> index.hml**: describes the layout of the  **index**  page, components used on the page, and the hierarchy of these components. For example, there is a text component for displaying  **Hello World**.

    ```
    <div class ="container">
      <text class ="title">
        {{ $t('strings.hello') }} {{title}}
      </text>
    </div>
    ```

-   **main \> js \> default \> pages \> index \> index.css**: defines the style of the  **index**  page. For example, the following  **index.css**  code snippet describes how  **container**  and  **title**  will be displayed on the page:

    ```
    .container {
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    .title {
      font-size: 100px;
    }
    ```

-   **main \> js \> default \> pages \> index \> index.js**: defines the service logic on the  **index**  page, such as data binding and event processing. In this example, the string  **World**  is assigned to  **title**.

    ```
    export default {
      data: {
        title: '',
      },
      onInit() {
        this.title = this.$t('strings.world');
      },
    }
    ```


## Repositories Involved<a name="section1599816111011"></a>

JS UI framework

ace\_ace\_engine

ace\_ace\_engine\_lite

ace\_napi