@tarojs/plugin-platform-harmony-cpp 4.0.8-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +270 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +1318 -0
- package/dist/runtime/apis/apis.ts +20 -0
- package/dist/runtime/apis/base/crypto.ts +4 -0
- package/dist/runtime/apis/base/debug.ts +5 -0
- package/dist/runtime/apis/base/index.ts +13 -0
- package/dist/runtime/apis/base/performance.ts +8 -0
- package/dist/runtime/apis/base/system.ts +181 -0
- package/dist/runtime/apis/base/update.ts +5 -0
- package/dist/runtime/apis/base/weapp/app-event.ts +75 -0
- package/dist/runtime/apis/base/weapp/life-cycle.ts +21 -0
- package/dist/runtime/apis/canvas/index.ts +27 -0
- package/dist/runtime/apis/data-analysis/index.ts +6 -0
- package/dist/runtime/apis/device/accelerometer.ts +79 -0
- package/dist/runtime/apis/device/accessibility.ts +4 -0
- package/dist/runtime/apis/device/battery.ts +24 -0
- package/dist/runtime/apis/device/bluetooth-ble.ts +19 -0
- package/dist/runtime/apis/device/bluetooth-peripheral.ts +6 -0
- package/dist/runtime/apis/device/bluetooth.ts +16 -0
- package/dist/runtime/apis/device/calendar.ts +5 -0
- package/dist/runtime/apis/device/clipboard.ts +85 -0
- package/dist/runtime/apis/device/compass.ts +21 -0
- package/dist/runtime/apis/device/contact.ts +5 -0
- package/dist/runtime/apis/device/crypto.ts +4 -0
- package/dist/runtime/apis/device/gyroscope.ts +77 -0
- package/dist/runtime/apis/device/iBeacon.ts +10 -0
- package/dist/runtime/apis/device/index.ts +24 -0
- package/dist/runtime/apis/device/keyboard.ts +63 -0
- package/dist/runtime/apis/device/memory.ts +11 -0
- package/dist/runtime/apis/device/motion.ts +6 -0
- package/dist/runtime/apis/device/network.ts +123 -0
- package/dist/runtime/apis/device/nfc.ts +10 -0
- package/dist/runtime/apis/device/phone.ts +44 -0
- package/dist/runtime/apis/device/scan.ts +4 -0
- package/dist/runtime/apis/device/screen.ts +80 -0
- package/dist/runtime/apis/device/sms.ts +4 -0
- package/dist/runtime/apis/device/vibrate.ts +32 -0
- package/dist/runtime/apis/device/wifi.ts +15 -0
- package/dist/runtime/apis/ext/index.ts +5 -0
- package/dist/runtime/apis/files/index.ts +136 -0
- package/dist/runtime/apis/files/manager.ts +942 -0
- package/dist/runtime/apis/framework/index.ts +48 -0
- package/dist/runtime/apis/harmony/task-pool.ts +39 -0
- package/dist/runtime/apis/index.ts +61 -0
- package/dist/runtime/apis/location/index.ts +133 -0
- package/dist/runtime/apis/media/EditorContext.ts +32 -0
- package/dist/runtime/apis/media/audio/index.ts +36 -0
- package/dist/runtime/apis/media/background-audio/index.ts +16 -0
- package/dist/runtime/apis/media/camera.ts +16 -0
- package/dist/runtime/apis/media/common.ts +58 -0
- package/dist/runtime/apis/media/image/index.ts +291 -0
- package/dist/runtime/apis/media/index.ts +13 -0
- package/dist/runtime/apis/media/live.ts +5 -0
- package/dist/runtime/apis/media/map.ts +4 -0
- package/dist/runtime/apis/media/media-recorder.ts +4 -0
- package/dist/runtime/apis/media/recorder.ts +6 -0
- package/dist/runtime/apis/media/video/VideoContext.ts +67 -0
- package/dist/runtime/apis/media/video/index.ts +45 -0
- package/dist/runtime/apis/media/video-decoder.ts +4 -0
- package/dist/runtime/apis/media/video-processing.ts +4 -0
- package/dist/runtime/apis/media/voip.ts +19 -0
- package/dist/runtime/apis/navigate/index.ts +8 -0
- package/dist/runtime/apis/network/downloadFile.ts +85 -0
- package/dist/runtime/apis/network/index.ts +7 -0
- package/dist/runtime/apis/network/mdns.ts +13 -0
- package/dist/runtime/apis/network/request.ts +140 -0
- package/dist/runtime/apis/network/tcp.ts +4 -0
- package/dist/runtime/apis/network/udp.ts +4 -0
- package/dist/runtime/apis/network/uploadFile.ts +105 -0
- package/dist/runtime/apis/network/webSocket.ts +126 -0
- package/dist/runtime/apis/open-api/account.ts +4 -0
- package/dist/runtime/apis/open-api/address.ts +4 -0
- package/dist/runtime/apis/open-api/authorize.ts +5 -0
- package/dist/runtime/apis/open-api/card.ts +5 -0
- package/dist/runtime/apis/open-api/channels-live.ts +11 -0
- package/dist/runtime/apis/open-api/customer-service.ts +4 -0
- package/dist/runtime/apis/open-api/device-voip.ts +5 -0
- package/dist/runtime/apis/open-api/facial.ts +7 -0
- package/dist/runtime/apis/open-api/favorites.ts +5 -0
- package/dist/runtime/apis/open-api/group.ts +4 -0
- package/dist/runtime/apis/open-api/index.ts +21 -0
- package/dist/runtime/apis/open-api/invoice.ts +5 -0
- package/dist/runtime/apis/open-api/license-plate.ts +4 -0
- package/dist/runtime/apis/open-api/login.ts +6 -0
- package/dist/runtime/apis/open-api/my-miniprogram.ts +4 -0
- package/dist/runtime/apis/open-api/privacy.ts +7 -0
- package/dist/runtime/apis/open-api/red-package.ts +4 -0
- package/dist/runtime/apis/open-api/settings.ts +5 -0
- package/dist/runtime/apis/open-api/soter.ts +6 -0
- package/dist/runtime/apis/open-api/subscribe-message.ts +6 -0
- package/dist/runtime/apis/open-api/user-info.ts +70 -0
- package/dist/runtime/apis/open-api/werun.ts +5 -0
- package/dist/runtime/apis/payment/index.ts +6 -0
- package/dist/runtime/apis/route/index.ts +88 -0
- package/dist/runtime/apis/share/index.ts +33 -0
- package/dist/runtime/apis/storage/background-fetch.ts +7 -0
- package/dist/runtime/apis/storage/cache-manager.ts +4 -0
- package/dist/runtime/apis/storage/index.ts +203 -0
- package/dist/runtime/apis/ui/animation/animation.ts +264 -0
- package/dist/runtime/apis/ui/animation/index.ts +7 -0
- package/dist/runtime/apis/ui/background.ts +20 -0
- package/dist/runtime/apis/ui/custom-component.ts +1 -0
- package/dist/runtime/apis/ui/fonts.ts +4 -0
- package/dist/runtime/apis/ui/index.ts +12 -0
- package/dist/runtime/apis/ui/interaction/index.ts +198 -0
- package/dist/runtime/apis/ui/menu.ts +4 -0
- package/dist/runtime/apis/ui/navigation-bar/index.ts +72 -0
- package/dist/runtime/apis/ui/pull-down-refresh.ts +47 -0
- package/dist/runtime/apis/ui/scroll/index.ts +82 -0
- package/dist/runtime/apis/ui/sticky.ts +4 -0
- package/dist/runtime/apis/ui/tab-bar.ts +144 -0
- package/dist/runtime/apis/ui/window.ts +20 -0
- package/dist/runtime/apis/utils/constant.ts +1 -0
- package/dist/runtime/apis/utils/handler.ts +117 -0
- package/dist/runtime/apis/utils/index.ts +105 -0
- package/dist/runtime/apis/utils/permissions.ts +6 -0
- package/dist/runtime/apis/utils/types.ts +12 -0
- package/dist/runtime/apis/utils/unit.ts +104 -0
- package/dist/runtime/apis/utils/validate.ts +87 -0
- package/dist/runtime/apis/worker/index.ts +4 -0
- package/dist/runtime/apis/wxml/index.ts +17 -0
- package/dist/runtime/apis/wxml/intersectionObserver.ts +100 -0
- package/dist/runtime/apis/wxml/nodesRef.ts +58 -0
- package/dist/runtime/apis/wxml/selectorQuery.ts +221 -0
- package/dist/runtime/apischunk/index.d.ts +1606 -0
- package/dist/runtime/apischunk/index.js +5054 -0
- package/dist/runtime/components/deprecated.ets +43 -0
- package/dist/runtime/components/index.ets +49 -0
- package/dist/runtime/components/innerHtml.ets +16 -0
- package/dist/runtime/components/navigationBar.ets +65 -0
- package/dist/runtime/components/pageMeta.ets +94 -0
- package/dist/runtime/components/richText.ets +24 -0
- package/dist/runtime/components/slider.ets +119 -0
- package/dist/runtime/components/style.ets +286 -0
- package/dist/runtime/components/switch.ets +73 -0
- package/dist/runtime/components/tag.ts +58 -0
- package/dist/runtime/components/utils/AttributeManager.ets +252 -0
- package/dist/runtime/components/utils/DynamicCenter.ts +41 -0
- package/dist/runtime/components/utils/constant/event.ets +25 -0
- package/dist/runtime/components/utils/constant/style.ets +91 -0
- package/dist/runtime/components/utils/events.ts +26 -0
- package/dist/runtime/components/utils/flexManager.ets +49 -0
- package/dist/runtime/components/utils/helper.ets +51 -0
- package/dist/runtime/components/utils/htmlParser/HarmonyHTMLParser.ts +100 -0
- package/dist/runtime/components/utils/htmlParser/index.ts +58 -0
- package/dist/runtime/components/utils/index.ts +77 -0
- package/dist/runtime/components/utils/styles.ets +41 -0
- package/dist/runtime/components/video.ets +119 -0
- package/dist/runtime/components/webView.ets +55 -0
- package/dist/runtime/components/xComponent.ets +89 -0
- package/dist/runtime/framework/app.ts +248 -0
- package/dist/runtime/framework/connect.ts +24 -0
- package/dist/runtime/framework/constant.ts +3 -0
- package/dist/runtime/framework/hooks.ts +100 -0
- package/dist/runtime/framework/index.ts +15 -0
- package/dist/runtime/framework/native-page.ts +511 -0
- package/dist/runtime/framework/page.ts +256 -0
- package/dist/runtime/framework/utils/index.ts +17 -0
- package/dist/runtime/framework/utils/is.ts +26 -0
- package/dist/runtime/framework-reconciler/componentTree.ts +81 -0
- package/dist/runtime/framework-reconciler/constant.ts +86 -0
- package/dist/runtime/framework-reconciler/domInput.ts +90 -0
- package/dist/runtime/framework-reconciler/event.ts +108 -0
- package/dist/runtime/framework-reconciler/index.ts +99 -0
- package/dist/runtime/framework-reconciler/inputValueTracking.ts +106 -0
- package/dist/runtime/framework-reconciler/props.ts +132 -0
- package/dist/runtime/framework-reconciler/reconciler.ts +202 -0
- package/dist/runtime/framework-reconciler/render.ts +139 -0
- package/dist/runtime/framework-reconciler/workTags.ts +53 -0
- package/dist/runtime/runtime-cpp/bom/URL.ts +2 -0
- package/dist/runtime/runtime-cpp/bom/document.ts +45 -0
- package/dist/runtime/runtime-cpp/bom/history.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/location.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/navigator.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/raf.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/window.ts +57 -0
- package/dist/runtime/runtime-cpp/constant.ts +29 -0
- package/dist/runtime/runtime-cpp/current.ts +48 -0
- package/dist/runtime/runtime-cpp/dom/class-list.ts +41 -0
- package/dist/runtime/runtime-cpp/dom/comment.ts +9 -0
- package/dist/runtime/runtime-cpp/dom/dataSource.ts +87 -0
- package/dist/runtime/runtime-cpp/dom/document.ts +113 -0
- package/dist/runtime/runtime-cpp/dom/element/canvas.ts +285 -0
- package/dist/runtime/runtime-cpp/dom/element/element.ts +262 -0
- package/dist/runtime/runtime-cpp/dom/element/form.ts +371 -0
- package/dist/runtime/runtime-cpp/dom/element/index.ts +129 -0
- package/dist/runtime/runtime-cpp/dom/element/movable.ts +250 -0
- package/dist/runtime/runtime-cpp/dom/element/normal.ts +123 -0
- package/dist/runtime/runtime-cpp/dom/element/scroll_view.ts +32 -0
- package/dist/runtime/runtime-cpp/dom/element/text.ts +9 -0
- package/dist/runtime/runtime-cpp/dom/element/video.ts +66 -0
- package/dist/runtime/runtime-cpp/dom/element/web_view.ts +72 -0
- package/dist/runtime/runtime-cpp/dom/event-source.ts +1 -0
- package/dist/runtime/runtime-cpp/dom/event.ts +187 -0
- package/dist/runtime/runtime-cpp/dom/eventTarget.ts +81 -0
- package/dist/runtime/runtime-cpp/dom/node.ts +307 -0
- package/dist/runtime/runtime-cpp/dom/style.ts +44 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/index.ts +379 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/type.ts +212 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/util.ts +186 -0
- package/dist/runtime/runtime-cpp/emitter/emitter.ts +29 -0
- package/dist/runtime/runtime-cpp/env.ts +1 -0
- package/dist/runtime/runtime-cpp/harmony-library.ts +1 -0
- package/dist/runtime/runtime-cpp/index.ts +79 -0
- package/dist/runtime/runtime-cpp/interface/event.ts +10 -0
- package/dist/runtime/runtime-cpp/interface/index.ts +7 -0
- package/dist/runtime/runtime-cpp/next-tick.ts +14 -0
- package/dist/runtime/runtime-cpp/system.ts +213 -0
- package/dist/runtime/runtime-cpp/utils/index.ts +63 -0
- package/dist/runtime/runtime-cpp/utils/info.ts +123 -0
- package/dist/runtime/runtime-cpp/utils/page.ts +12 -0
- package/dist/runtime/runtime-cpp/utils/router.ts +1 -0
- package/dist/runtime/runtime-harmony/apis/helper.ets +33 -0
- package/dist/runtime/runtime-harmony/apis/network/common.ets +41 -0
- package/dist/runtime/runtime-harmony/apis/network/downloadFile.ets +327 -0
- package/dist/runtime/runtime-harmony/apis/network/index.ets +58 -0
- package/dist/runtime/runtime-harmony/apis/network/request.ets +206 -0
- package/dist/runtime/runtime-harmony/apis/network/uploadFile.ets +190 -0
- package/dist/runtime/runtime-harmony/apis/route.ets +110 -0
- package/dist/runtime/runtime-harmony/apis/taskpool.ets +149 -0
- package/dist/runtime/runtime-harmony/index.ets +41 -0
- package/dist/runtime/runtime-harmony/utils.ts +53 -0
- package/index.js +4 -0
- package/package.json +93 -0
- package/static/@taro-oh/library-4.0.8-beta.3.har +0 -0
- package/types/compile.d.ts +50 -0
- package/types/components.d.ts +49 -0
- package/types/define.d.ts +61 -0
- package/types/harmony.d.ts +28 -0
- package/types/runtime.d.ts +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# @tarojs/plugin-platform-harmony-cpp
|
|
2
|
+
|
|
3
|
+
## 快速开始
|
|
4
|
+
|
|
5
|
+
### 安装和使用
|
|
6
|
+
|
|
7
|
+
- 安装 harmony 插件
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
# 使用 npm 安装
|
|
11
|
+
$ npm i @tarojs/plugin-platform-harmony-cpp
|
|
12
|
+
# 使用 pnpm 安装
|
|
13
|
+
$ pnpm i @tarojs/plugin-platform-harmony-cpp
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- 添加插件配置
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import os from 'os'
|
|
20
|
+
import path from 'path'
|
|
21
|
+
|
|
22
|
+
const config = {
|
|
23
|
+
// ...
|
|
24
|
+
plugins: ['@tarojs/plugin-platform-harmony-cpp'],
|
|
25
|
+
harmony: {
|
|
26
|
+
// 当前仅支持使用 Vite 编译鸿蒙应用
|
|
27
|
+
compiler: 'vite',
|
|
28
|
+
// Note: 鸿蒙工程路径,可以参考 [鸿蒙应用创建导读](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V2/start-with-ets-stage-0000001477980905-V2) 创建
|
|
29
|
+
projectPath: path.join(os.homedir(), 'projects/my-business-project'),
|
|
30
|
+
// Taro 项目编译到对应鸿蒙模块名,默认为 entry
|
|
31
|
+
hapName: 'entry',
|
|
32
|
+
},
|
|
33
|
+
// ...
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 编译项目
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
# 编译鸿蒙应用
|
|
41
|
+
$ taro build --type harmony_cpp
|
|
42
|
+
# 编译鸿蒙原生组件
|
|
43
|
+
$ taro build native-components --type harmony_cpp
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
如果需要编译鸿蒙应用,同时使用编译鸿蒙原生组件,可以在页面配置中添加 `entryOption: false` 表示该页面是组件,同时可以用过 `componentName` 指定组件导出名。
|
|
47
|
+
|
|
48
|
+
```diff
|
|
49
|
+
export default {
|
|
50
|
+
navigationBarTitleText: 'Hello World',
|
|
51
|
+
+ componentName: 'MyComponent',
|
|
52
|
+
+ entryOption: false,
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 功能
|
|
57
|
+
|
|
58
|
+
### 使用公共依赖库
|
|
59
|
+
|
|
60
|
+
插件默认使用内置版本的公共依赖库,可以通过 useChoreLibrary 配置禁用或者配置指定版本依赖。
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const config = {
|
|
64
|
+
// ...
|
|
65
|
+
plugins: [
|
|
66
|
+
'@tarojs/plugin-platform-harmony-cpp', // useChoreLibrary: 'local'
|
|
67
|
+
// ['@tarojs/plugin-platform-harmony-cpp', { useChoreLibrary: false }],
|
|
68
|
+
// ['@tarojs/plugin-platform-harmony-cpp', { useChoreLibrary: '4.1.0-alpha.0' }],
|
|
69
|
+
],
|
|
70
|
+
// ...
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
插件版本可以通过 `ohPackage.dependencies` 配置或者鸿蒙工程内 `oh-package.json5` 配置覆盖。
|
|
75
|
+
|
|
76
|
+
### 类型定义
|
|
77
|
+
|
|
78
|
+
需要在 Taro 项目的 types/global.d.ts 文件夹里添加对插件类型的引用
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
/// <reference types="@tarojs/taro" />
|
|
82
|
+
/// <reference path="../node_modules/@tarojs/plugin-platform-harmony-cpp/types/define.d.ts" />
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 项目集成
|
|
87
|
+
|
|
88
|
+
Taro 默认支持构建鸿蒙应用,同时也允许开发者灵活扩展功能。你可以在 Taro 项目中使用鸿蒙原生模块,也可以在鸿蒙项目中集成 Taro 模块。
|
|
89
|
+
|
|
90
|
+
### 在 Taro 中使用鸿蒙原生模块
|
|
91
|
+
|
|
92
|
+
与 Taro 在其他端类似,可以通过配置 `usingComponents` 来引入鸿蒙原生组件。
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
/** index.config.ts */
|
|
96
|
+
export default {
|
|
97
|
+
usingComponents: {
|
|
98
|
+
title: './path/to/title-component'
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** index.ts */
|
|
103
|
+
import { View } from '@tarojs/components'
|
|
104
|
+
|
|
105
|
+
export default function Index () {
|
|
106
|
+
return <View>
|
|
107
|
+
<title title="Hello World!" />
|
|
108
|
+
</View>
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
如果希望使用 Taro 构建的鸿蒙原生组件或者为原生组件提供类型提示,也可以通过 `importNativeComponent` 方法来引入。
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
/** title.ts */
|
|
116
|
+
import { View } from '@tarojs/components'
|
|
117
|
+
|
|
118
|
+
definePageConfig({
|
|
119
|
+
entryOption: false,
|
|
120
|
+
componentName: 'Title',
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
export default function Title ({ title = 'Hello World' }) {
|
|
124
|
+
return <View>{title}</View>
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// importNativeComponent(path, moduleName, componentName)
|
|
128
|
+
export const Title = importNativeComponent<typeof import('./title').default>('./title', 'title', 'Title')
|
|
129
|
+
|
|
130
|
+
/** index.ts */
|
|
131
|
+
import { View } from '@tarojs/components'
|
|
132
|
+
import { Title } from './title'
|
|
133
|
+
|
|
134
|
+
export default function Index () {
|
|
135
|
+
return <View>
|
|
136
|
+
<Title title="Hello World!" />
|
|
137
|
+
</View>
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 在鸿蒙项目中集成 Taro 模块
|
|
142
|
+
|
|
143
|
+
在鸿蒙项目中可以通过页面或者组件的形式来接入 Taro 模块,但如果不是 Taro 创建的鸿蒙项目需要在入口处添加 Taro 相关的初始化方法:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { context, Current } from "@taro-oh/library/src/main/ets/npm/@tarojs/runtime"
|
|
147
|
+
import { TaroWindowUtil } from "@taro-oh/library/src/main/ets/npm/@tarojs/runtime"
|
|
148
|
+
|
|
149
|
+
export default class EntryAbility extends UIAbility {
|
|
150
|
+
...
|
|
151
|
+
onWindowStageCreate(stage: ohWindow.WindowStage) {
|
|
152
|
+
context.resolver(this.context)
|
|
153
|
+
TaroWindowUtil.setWindowStage(stage)
|
|
154
|
+
|
|
155
|
+
stage.loadContent('home_page', (err, data) => {
|
|
156
|
+
const windowClass = stage.getMainWindowSync()
|
|
157
|
+
Current.uiContext = windowClass.getUIContext()
|
|
158
|
+
windowClass.setWindowLayoutFullScreen(true)
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
更多配置可以参考项目生成的 `app.ts` 文件改造。
|
|
165
|
+
|
|
166
|
+
通过页面接入需要在模块配置文件 `module.json5` 中配置 pages 参数,如果是组件模式,可以参考原生 ets 组件方法引入。
|
|
167
|
+
|
|
168
|
+
```plain
|
|
169
|
+
import { Title } from './components/title'
|
|
170
|
+
|
|
171
|
+
@Builder
|
|
172
|
+
function render () {
|
|
173
|
+
Title({
|
|
174
|
+
props: {
|
|
175
|
+
title: 'Hello World!'
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### 定制 Taro 运行时
|
|
182
|
+
|
|
183
|
+
与其他端类似,开发者同样可以通过继承 HarmonyCPP 实例来修改 Taro 的默认行为,包括新增运行时代码等。
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
import { HarmonyCPP } from '@tarojs/plugin-platform-harmony-cpp'
|
|
187
|
+
|
|
188
|
+
export default class MyTaro extends HarmonyCPP {
|
|
189
|
+
// ...
|
|
190
|
+
constructor () {
|
|
191
|
+
super()
|
|
192
|
+
// ...
|
|
193
|
+
if (typeof this.runtimePath === 'string') {
|
|
194
|
+
this.runtimePath = [this.runtimePath, path.resolve(__dirname, 'my-runtime')] // Note: 如果有需要可以覆盖 runtime 禁用 taro 默认 API 行为
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
> 如果不想构建端应用插件,也可以通过配置 copy 将自定义 ets 代码注入到项目中。
|
|
201
|
+
|
|
202
|
+
通过注入运行时,开发者可以监听 Taro 抛出的 `__taroPluginEtsMethodsTrigger` 事件,可以通过监听事件实现获取开发用户调用 Taro 方法的参数,或者修改 Taro 的默认行为。
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import { eventCenter } from '@tarojs/runtime'
|
|
206
|
+
import { IEtsMethodsOptions } from '@tarojs/plugin-platform-harmony-cpp/dist/runtime/runtime-harmony'
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* interface IEtsMethodsOptions {
|
|
210
|
+
* methodName?: string
|
|
211
|
+
* name?: string
|
|
212
|
+
* scope?: string
|
|
213
|
+
* type?: string
|
|
214
|
+
* args?: TaroAny[]
|
|
215
|
+
* successHandler?: (...args: TaroAny[]) => void
|
|
216
|
+
* errorHandler?: (...args: TaroAny[]) => void
|
|
217
|
+
* onInit?: (obj: TaroAny) => void
|
|
218
|
+
* }
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
eventCenter?.on('__taroPluginEtsMethodsTrigger', (option: IEtsMethodsOptions) => {
|
|
222
|
+
switch (option.scope) {
|
|
223
|
+
case 'route':
|
|
224
|
+
// ...
|
|
225
|
+
break
|
|
226
|
+
default:
|
|
227
|
+
break
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
> 未实现的 API 可以通过监听 `__taroNotSupport` 事件自定义实现。
|
|
233
|
+
|
|
234
|
+
## 常见问题
|
|
235
|
+
|
|
236
|
+
### **ERROR: Failed to get ModuleInfo properties 'meta.pkgPath'**
|
|
237
|
+
|
|
238
|
+
本地可能存在部分混淆导致 IDE 无法正确解析依赖,需要检查 `build-profile.json5`、`obfuscation-rules.txt` 等文件中是否开启混淆配置,需要关闭后清理 IDE 缓存重新编译。
|
|
239
|
+
|
|
240
|
+
```diff
|
|
241
|
+
- -enable-property-obfuscation
|
|
242
|
+
- -enable-toplevel-obfuscation
|
|
243
|
+
- -enable-filename-obfuscation
|
|
244
|
+
- -enable-export-obfuscation
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### **ERROR: Cannot resolved import statement**
|
|
248
|
+
|
|
249
|
+
本地执行 library 编译时,启用 `useNormalizedOHMUrl` 配置会导致外部依赖无法解析,建议在 library 模块中使用 `useNormalizedOHMUrl: false` 或者移除该配置。
|
|
250
|
+
|
|
251
|
+
### **ERROR: Duplicated files found in module default**
|
|
252
|
+
|
|
253
|
+
不使用核心库切换到使用核心库时可能会出现该问题,需要清理 build-profile.json5 文件中关于 so 包的配置项。
|
|
254
|
+
|
|
255
|
+
```diff
|
|
256
|
+
{
|
|
257
|
+
"apiType": "stageMode",
|
|
258
|
+
"buildOption": {
|
|
259
|
+
- "externalNativeOptions": {
|
|
260
|
+
- "path": "./src/main/cpp/CMakeLists.txt",
|
|
261
|
+
- "arguments": "-DCMAKE_JOB_POOL_COMPILE:STRING=compile -DCMAKE_JOB_POOL_LINK:STRING=link -DCMAKE_JOB_POOLS:STRING=compile=8;link=8",
|
|
262
|
+
- "cppFlags": "",
|
|
263
|
+
- "abiFilters": [
|
|
264
|
+
- "arm64-v8a"
|
|
265
|
+
- ]
|
|
266
|
+
- }
|
|
267
|
+
},
|
|
268
|
+
...
|
|
269
|
+
}
|
|
270
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HarmonyOS_ArkTS } from '@tarojs/plugin-platform-harmony-ets/dist';
|
|
2
|
+
import { IPluginContext, TConfig } from '@tarojs/service';
|
|
3
|
+
import { IHarmonyConfig } from '@tarojs/taro/types/compile';
|
|
4
|
+
|
|
5
|
+
declare class Harmony extends HarmonyOS_ArkTS {
|
|
6
|
+
option: IOptions;
|
|
7
|
+
platform: string;
|
|
8
|
+
runtimePath: string;
|
|
9
|
+
useETS: boolean;
|
|
10
|
+
useJSON5: boolean;
|
|
11
|
+
get context(): IPluginContext;
|
|
12
|
+
constructor(ctx: IPluginContext, config: TConfig, option: IOptions);
|
|
13
|
+
get harmonyPluginPath(): string;
|
|
14
|
+
get harmonyCppPluginPath(): string;
|
|
15
|
+
get apiLibrary(): string;
|
|
16
|
+
get componentLibrary(): string;
|
|
17
|
+
get runtimeLibrary(): string;
|
|
18
|
+
get runtimeFrameworkLibrary(): string;
|
|
19
|
+
get runtimeFrameworkReconciler(): string;
|
|
20
|
+
modifyPageConfig(): void;
|
|
21
|
+
updateModulePackage(outputRoot: string, ohPackage?: Exclude<IHarmonyConfig['ohPackage'], undefined>, ohpm?: string): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface IOptions {
|
|
25
|
+
useConfigName?: string;
|
|
26
|
+
/** @default "local" */
|
|
27
|
+
useChoreLibrary?: 'local' | 'remote' | false | string;
|
|
28
|
+
}
|
|
29
|
+
declare const _default: (ctx: IPluginContext, options?: IOptions) => void;
|
|
30
|
+
|
|
31
|
+
export { Harmony as HarmonyCPP, _default as default };
|
|
32
|
+
export type { IOptions };
|