热门问题
时间线
聊天
视角

方舟UI框架

来自维基百科,自由的百科全书

Remove ads

方舟UI框架(简称ArkUI[1],原名方舟开发框架)是一个由华为[2]开发的声明式用户界面框架,用于在原生鸿蒙OpenHarmony以及Oniro OS应用程序上构建用户界面。ArkUI采用基于TypeScript声明式UI语法扩展而来的ArkTS英语ArkTS语言,同时也支持使用鸿蒙标记语言HarmonyOS Markup Language,缩写HML)、JavaScript和CSS以类似Vue.js 2的语法、MVVM范式开发。[3][4][5]

ArkUI与DevEco Studio IDE集成,提供实时预览[6]、调试和其他开发功能。

ArkUI-X是基于ArkUI扩展的跨平台用户界面框架,可使ArkUI不局限于OpenHarmony、HarmonyOS,运行到Android、 iOS等系统上。[7][8]

历史

在2023年8月的HDC 2023大会上,华为宣布了HarmonyOS 4.0的ArkUI改进,可以使用ArkTS和Ark Engine进行原生HarmonyOS NEXT软件开发,并引入了ArkGraphics 2D和ArkGraphics3D框架。[9]

特性

ArkUI架构分为三层:最上层提供了声明式UI范式,中间层为方舟编译器和运行时、UI后端引擎和渲染引擎;下层为平台适配桥接层。[8]

UI元素

页面是ArkUI中系统调度的最小单位,组件是最小分割单位。[3]系统组件是ArkUI框架中的内置组件,分为容器组件和基础组件两种。例如,Row和Column都属于容器组件,可容纳其他组件;Text和Button组件属于基础组件。[10]

多线程

ArkTS使用单线程模型,对象跨线程使用序列化方式通过ArrayBuffer和SharedArrayBuffer共享。[11]

示例代码

import ArkTS
// Index.ets

import router from '@ohos.router';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
        // Add a button to respond to user clicks.
        Button() {
          Text('Next')
            .fontSize(30)
            .fontWeight(FontWeight.Bold)
        }
        .type(ButtonType.Capsule)
        .margin({
          top: 20
        })
        .backgroundColor('#0D9FFB')
        .width('40%')
        .height('5%')
        // Bind the onClick event to the Next button so that clicking the button redirects the user to the second page.
        .onClick(() => {
          router.pushUrl({ url: 'pages/Second' })
        })
      }
      .width('100%')
    }
    .height('100%')
  }
}

其中,@ohos.router 路由库实现了页面的流转,调用前需在 main_pages.json 文件中声明。[12]

Remove ads

应用

  • 鸿蒙原生版淘宝通过使用ArkUI和ArkTs能力,将购物结算场景性能提升至安卓版本的1.5 倍。[13]

参考文献

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads