1 Star 0 Fork 0

灵界 / OpenHarmonyDoc

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
Apache-2.0

说明

1、来源:本工程是 OpenHarmony 应用开发文档 的演示工程。

2、目的:旨在把文档内容代码化,方便开发时查询。

3、版本:

v4.1 Release API 11 Release---截止2024.04.11

应用开发导读

入门

快速入门

开发准备

构建第一个ArkTS应用(Stage模型)

开发基础知识

应用程序包基础知识

应用程序包概述

HAP(分entry和feature)、HAR、HSP所有文档链接罗列如下:

1、Module类型

2、编译态包结构-->选择合适的包类型

3、HAP

4、HAR

5、HSP

6、动态import

7、工程管理

8、受2启发:当多包(HAP/HSP)同时引用同一个共享包时,采用HSP替代HAR,可以避免HAR造成的多包间代码和资源的重复拷贝,从而减小应用包大小。---我的理解:当HAR被应用内共享时,外包一层HSP,以避免包体积膨胀和状态无法共享问题。

9、受2启发:HAR和HSP没有XxxAbility,意味着它们不能独立运行,只能依赖HAP。

10、受3启发:因为HAP不支持导出接口和ArkUI组件,给其他模块使用,所以HAP和HAP之间没有依赖关系,但是可以通过UIAbility组件间交互(设备内)进行通信。

11、如果HAR包含HSP发布,第三方无法引用!

应用程序包结构

Stage模型应用程序包结构
AppScope:应用的全局配置信息。由DevEco Studio自动生成,不可更改。
    resources :用于存放应用需要用到的资源文件。编译后会合入到模块(比如“entry”)下面资源目录中,如果两个目录下的存在重名文件,编译打包后只会保留AppScope目录下的资源文件。---stage模型多工程情况下,共有的资源文件放到此目录。
entry:应用的主模块,包含应用的入口界面、入口图标和主功能特性,编译后生成entry类型(module.json5中的“type”字段)的HAP包。每一个应用分发到 >>同一类型<< 的设备上的应用程序包,只能包含唯一一个entry类型的HAP。目录名称可以自定义。
    src > main > ets:用于存放ArkTS源码文件(.ets文件)。编译后会生成.abc文件。
    src > main > ets > entryability:应用/服务的入口。
    src > main > ets > pages:应用/服务包含的页面。
    src > main > resources:用于存放应用/服务所用到的资源文件,如图形、多媒体、字符串、布局文件等。关于资源文件,详见资源文件的分类①。
                    base:默认存在的目录。二级子目录element用于存放字符串、颜色、布尔值等基础元素,media、profile存放媒体、动画、布局等资源文件。
                    en_US:默认存在的目录,设备语言环境是美式英文时,优先匹配此目录下资源。二级子目录element用于存放字符串、颜色、布尔值等基础元素,media、profile存放媒体、动画、布局等资源文件。
                    zh_CN:默认存在的目录,设备语言环境是简体中文时,优先匹配此目录下资源。二级子目录element用于存放字符串、颜色、布尔值等基础元素,media、profile存放媒体、动画、布局等资源文件。
                    en_GB-vertical-car-mdpi:自定义限定词目录示例,由开发者创建
                    rawfile:其他类型文件目录,支持创建多层子目录,子目录名称可以自定义,文件夹内可以自由放置各类资源文件。文件以文件形式保存,不会被集成到resources.index文件中。文件名可自定义。
                    resfile:其他类型文件目录,支持创建多层子目录,子目录名称可以自定义,文件夹内可以自由放置各类资源文件。文件以文件形式保存,不会被集成到resources.index文件中。文件名可自定义。资源会被解压到应用沙箱路径,通过Context属性resourceDir获取到resfile资源目录后,可通过文件路径访问。
feature1:应用的动态特性模块,编译后生成feature类型(module.json5中的“type”字段)的HAP包。一个应用中可以包含0、1或多个feature类型的HAP。
library_static1:静态共享库。编译后会生成一个以.har为后缀的文件,即静态共享包HAR(Harmony Archive)。
library_shared1:动态共享库。编译后会生成一个以.hsp为后缀的文件,即动态共享包HSP(Harmony Shared Package)。实际上,Shared Library编译后除了会生成一个.hsp文件,还会生成一个.har文件。这个.har文件中包含了HSP对外导出的接口,应用中的其他模块需要通过.har文件来引用HSP的功能。为了表述方便,我们通常认为Shared Library编译后生成HSP。
oh_modules:用于存放三方库依赖信息。

①:资源文件的分类

FA模型应用程序包结构

应用程序包开发与使用

HAP
HAR
HSP
动态import(API 11)

应用程序包安装卸载与更新

应用配置文件(Stage模型)

应用配置文件概述(Stage模型)

app.json5配置文件

module.json5配置文件

应用配置文件(FA模型)

资源分类与访问

学习ArkTS语言

初识ArkTS语言

ArkTS语言介绍

从TypeScript到ArkTS的适配指导

UI范式

基本语法

基本语法概述
声明式UI描述
自定义组件
创建自定义组件
装饰器 使用位置 作用 URL
@Entry Page页入口组件 一个页面最多一个此装饰的组件 自定义组件的基本结构
@Component 每个组件 仅装饰struct。使struct具备组件化的能力 自定义组件的基本结构
注:组件专指自定义组件。
页面和自定义组件生命周期
自定义组件的自定义布局
自定义组件冻结功能
@Builder装饰器:自定义构建函数
wrapBuilder:封装全局@Builder(API 11)
@Styles装饰器:定义组件重用样式
@Extend装饰器:定义扩展组件样式
stateStyles:多态样式
@AnimatableExtend装饰器:定义可动画属性
@Require装饰器:校验构造传参(API 11)
装饰器 使用位置 作用 URL
@Builder 封装UI描述的函数 使函数遵循build()函数语法规则,复用UI元素 @Builder装饰器:自定义构建函数
@BuilderParam 组件内成员变量(变量类型必须是@Builder装饰的函数) 父组件传递@Builder装饰的函数给子组件 @BuilderParam装饰器:引用@Builder函数
@Require 组件内成员变量(必须是@Prop或@BuilderParam装饰的变量) 限制@Prop和@BuilderParam装饰的变量必须在构造时传参 @Require装饰器:校验构造传参
@Styles 封装通用属性和通用事件的函数 复用 @Styles装饰器:定义组件重用样式
@Extend 封装属性、事件和自定义全局函数(比如@Styles装饰的全局函数)的全局函数 复用 @Extend装饰器:定义扩展组件样式
@AnimatableExtend 封装属性的全局函数 主要是让 不可动画属性 也能实现动画效果 @AnimatableExtend装饰器:定义可动画属性
函数 使用位置 作用 URL
wrapBuilder(@Builder builder: (...args: Args) => void): WrappedBuilder 封装1~N个全局@Builder构建函数 wrapBuilder:封装全局@Builder
* stateStyles(value: StateStyles): T 通用属性 设置不同状态下样式,类似Android中的selector(选择器) stateStyles:多态样式

注:

1、组件:这里专指自定义组件。
2、属性:属性方法简称。
3、事件:事件方法简称。
4、样式:属性和事件。
5、UI描述:系统组件、属性和事件。
6、* :优先掌握。

状态管理

状态管理概述

arkts-state-management-overview.png

组件状态:

装饰器 使用位置 组件内同步 组件间同步 父初始化 初始化子 URL
@State 组件内成员变量 Y 取决于搭配的装饰器 无状态、@State、@Prop、@Link、@ObjectLink、@Provide、@Consume、@StorageProp、@StorageLink、@LocalStorageProp、@LocalStorageLink 无状态、@State、@Prop、@Link、@Provide @State装饰器:组件内状态
@Prop 父@State -> 子@Prop
@Link 父@State <-> 子@Link
@ObjectLink 父@State <-> 子@Link

注:

1、所有(状态装饰器装饰的)状态变量都是组件内私有变量,不支持外部访问。
2、组件:这里专指自定义组件。
3、无状态:常规变量。

应用状态:

管理组件拥有的状态
@State装饰器:组件内状态
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/application-dev-guide.md演示工程 expand collapse
TypeScript and 3 more languages
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
1
https://gitee.com/lingjie666/open_harmony_doc.git
git@gitee.com:lingjie666/open_harmony_doc.git
lingjie666
open_harmony_doc
OpenHarmonyDoc
master

Search

53164aa7 5694891 3bd8fe86 5694891