@hxa-rn/react-native-gcanvas 6.0.24-beta.1 → 6.0.26
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/CHANGELOG.md +2 -2
- package/LICENSE +203 -21
- package/README.md +207 -207
- package/harmony/gcanvas/LICENSE +203 -21
- package/harmony/gcanvas/NOTICE +32 -32
- package/harmony/gcanvas/OAT.xml +37 -37
- package/harmony/gcanvas/build-profile.json5 +16 -16
- package/harmony/gcanvas/hvigorfile.ts +1 -1
- package/harmony/gcanvas/index.ets +1 -1
- package/harmony/gcanvas/oh-package.json5 +14 -14
- package/harmony/gcanvas/src/main/cpp/CMakeLists.txt +126 -126
- package/harmony/gcanvas/src/main/cpp/GCanvasNapi.cpp +485 -485
- package/harmony/gcanvas/src/main/cpp/GCanvasXComponent.cpp +106 -106
- package/harmony/gcanvas/src/main/cpp/GcanvasPackage.h +24 -24
- package/harmony/gcanvas/src/main/ets/GCanvasModuleTurboModule.ts +448 -448
- package/harmony/gcanvas/src/main/ets/GCanvasNativeEngine.ts +206 -206
- package/harmony/gcanvas/src/main/ets/components/GCanvasView.ets +64 -64
- package/harmony/gcanvas/src/main/module.json5 +21 -21
- package/harmony/gcanvas/src/main/resources/base/element/string.json +12 -12
- package/harmony/gcanvas/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/gcanvas/src/main/resources/zh_CN/element/string.json +12 -12
- package/harmony/gcanvas.har +0 -0
- package/package.json +4 -4
- package/packages/gcanvas/.babelrc +4 -4
- package/packages/gcanvas/.eslintrc.js +133 -133
- package/packages/gcanvas/package.json +19 -19
- package/packages/gcanvas/rollup.config.js +13 -13
- package/packages/gcanvas/src/bridge/react-native.js +286 -286
- package/packages/gcanvas/src/bridge/weex.js +210 -210
- package/packages/gcanvas/src/context/2d/FillStyleLinearGradient.js +16 -16
- package/packages/gcanvas/src/context/2d/FillStylePattern.js +7 -7
- package/packages/gcanvas/src/context/2d/FillStyleRadialGradient.js +16 -16
- package/packages/gcanvas/src/context/2d/OffScreenRenderingContext.js +48 -48
- package/packages/gcanvas/src/context/2d/RenderingContext.js +787 -787
- package/packages/gcanvas/src/context/webgl/ActiveInfo.js +10 -10
- package/packages/gcanvas/src/context/webgl/Buffer.js +20 -20
- package/packages/gcanvas/src/context/webgl/Framebuffer.js +20 -20
- package/packages/gcanvas/src/context/webgl/GLenum.js +300 -300
- package/packages/gcanvas/src/context/webgl/GLmethod.js +141 -141
- package/packages/gcanvas/src/context/webgl/GLtype.js +22 -22
- package/packages/gcanvas/src/context/webgl/Program.js +20 -20
- package/packages/gcanvas/src/context/webgl/Renderbuffer.js +20 -20
- package/packages/gcanvas/src/context/webgl/RenderingContext.js +1479 -1479
- package/packages/gcanvas/src/context/webgl/Shader.js +21 -21
- package/packages/gcanvas/src/context/webgl/ShaderPrecisionFormat.js +10 -10
- package/packages/gcanvas/src/context/webgl/Texture.js +21 -21
- package/packages/gcanvas/src/context/webgl/UniformLocation.js +21 -21
- package/packages/gcanvas/src/context/webgl/classUtils.js +2 -2
- package/packages/gcanvas/src/env/canvas.js +210 -210
- package/packages/gcanvas/src/env/image.js +76 -76
- package/packages/gcanvas/src/env/off-screen-canvas.js +74 -74
- package/packages/gcanvas/src/index.js +56 -56
- package/src/components/CanvasView.js +20 -20
- package/src/components/GCanvasComponent.js +408 -408
- package/src/index.js +69 -69
- package/src/packages/gcanvas/.babelrc +4 -4
- package/src/packages/gcanvas/.eslintrc.js +133 -133
- package/src/packages/gcanvas/package.json +19 -19
- package/src/packages/gcanvas/rollup.config.js +13 -13
- package/src/packages/gcanvas/src/bridge/react-native.js +288 -288
- package/src/packages/gcanvas/src/bridge/weex.js +210 -210
- package/src/packages/gcanvas/src/context/2d/FillStyleLinearGradient.js +16 -16
- package/src/packages/gcanvas/src/context/2d/FillStylePattern.js +7 -7
- package/src/packages/gcanvas/src/context/2d/FillStyleRadialGradient.js +16 -16
- package/src/packages/gcanvas/src/context/2d/OffScreenRenderingContext.js +48 -48
- package/src/packages/gcanvas/src/context/2d/RenderingContext.js +801 -801
- package/src/packages/gcanvas/src/context/webgl/ActiveInfo.js +10 -10
- package/src/packages/gcanvas/src/context/webgl/Buffer.js +20 -20
- package/src/packages/gcanvas/src/context/webgl/Framebuffer.js +20 -20
- package/src/packages/gcanvas/src/context/webgl/GLenum.js +300 -300
- package/src/packages/gcanvas/src/context/webgl/GLmethod.js +141 -141
- package/src/packages/gcanvas/src/context/webgl/GLtype.js +22 -22
- package/src/packages/gcanvas/src/context/webgl/Program.js +20 -20
- package/src/packages/gcanvas/src/context/webgl/Renderbuffer.js +20 -20
- package/src/packages/gcanvas/src/context/webgl/RenderingContext.js +1479 -1479
- package/src/packages/gcanvas/src/context/webgl/Shader.js +21 -21
- package/src/packages/gcanvas/src/context/webgl/ShaderPrecisionFormat.js +10 -10
- package/src/packages/gcanvas/src/context/webgl/Texture.js +21 -21
- package/src/packages/gcanvas/src/context/webgl/UniformLocation.js +21 -21
- package/src/packages/gcanvas/src/context/webgl/classUtils.js +2 -2
- package/src/packages/gcanvas/src/env/canvas.js +210 -210
- package/src/packages/gcanvas/src/env/image.js +76 -76
- package/src/packages/gcanvas/src/env/off-screen-canvas.js +74 -74
- package/src/packages/gcanvas/src/index.js +56 -56
- package/src/specs/v1/GCanvasViewNativeComponent.ts +42 -42
- package/src/specs/v1/NativeGCanvasModule.ts +140 -140
package/CHANGELOG.md
CHANGED
package/LICENSE
CHANGED
|
@@ -1,21 +1,203 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Modifications Copyright (c) 2026 HarmonyOS X-platform Alliance
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright [yyyy] [name of copyright owner]
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,207 +1,207 @@
|
|
|
1
|
-
# react-native-gcanvas
|
|
2
|
-
|
|
3
|
-
本项目基于 [@flyskywhy/react-native-gcanvas](https://github.com/flyskywhy/react-native-gcanvas)开发。如果在使用过程中有任何问题,欢迎在AtomGit提交Issue,会及时跟进。
|
|
4
|
-
|
|
5
|
-
## 项目介绍
|
|
6
|
-
|
|
7
|
-
`@hxa-rn/react-native-gcanvas` 是 `@flyskywhy/react-native-gcanvas@6.0.24` 的鸿蒙适配包,提供基于 C++ GCanvas(OpenGL ES)引擎的 Canvas 2D / WebGL 原生视图。业务侧通过 `harmony.alias` 继续 `import ... from '@flyskywhy/react-native-gcanvas'`。
|
|
8
|
-
|
|
9
|
-
本包含原生实现:C++ TurboModule `GCanvasModule`(20 个方法)+ Fabric 组件 `GCanvasView`(XComponent SURFACE + EGL)。JS 层复用上游命令字符串桥,鸿蒙侧补齐 `texImage2D` / `texSubImage2D`、`registerFont` / `getFontNames` 与远程图片下载。
|
|
10
|
-
|
|
11
|
-
当前版本:`6.0.
|
|
12
|
-
|
|
13
|
-
## 集成指南
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @hxa-rn/react-native-gcanvas
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
本包声明:
|
|
20
|
-
|
|
21
|
-
```json
|
|
22
|
-
{
|
|
23
|
-
"name": "@hxa-rn/react-native-gcanvas",
|
|
24
|
-
"version": "6.0.
|
|
25
|
-
"peerDependencies": {
|
|
26
|
-
"react-native": ">=0.72"
|
|
27
|
-
},
|
|
28
|
-
"harmony": {
|
|
29
|
-
"alias": "@flyskywhy/react-native-gcanvas"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
工程按 `harmony.alias` 解析后,业务代码仍从原包名导入:
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
import {GCanvasView, GImage, createCanvas, getFontNames, registerFont} from '@flyskywhy/react-native-gcanvas';
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
`peerDependencies` 为 `react-native` >= 0.72。本模块含 C++ TurboModule 与 Fabric 组件。Autolinking 可用时跳过手动注册;手动接入时需同时注册 C++ `GcanvasPackage` 与 ETS `GcanvasPackage`,并把 `harmony/gcanvas.har` 加入 entry 依赖。
|
|
41
|
-
|
|
42
|
-
## 使用说明
|
|
43
|
-
|
|
44
|
-
```tsx
|
|
45
|
-
import React from 'react';
|
|
46
|
-
import {StyleSheet, View} from 'react-native';
|
|
47
|
-
import {GCanvasView} from '@flyskywhy/react-native-gcanvas';
|
|
48
|
-
|
|
49
|
-
export default function App() {
|
|
50
|
-
return (
|
|
51
|
-
<View style={styles.container}>
|
|
52
|
-
<GCanvasView
|
|
53
|
-
style={styles.canvas}
|
|
54
|
-
onCanvasCreate={(canvas) => {
|
|
55
|
-
const ctx = canvas.getContext('2d');
|
|
56
|
-
ctx.fillStyle = '#FF5722';
|
|
57
|
-
ctx.fillRect(10, 10, 100, 100);
|
|
58
|
-
ctx.font = '24px';
|
|
59
|
-
ctx.fillStyle = '#222222';
|
|
60
|
-
ctx.fillText('Hello GCanvas', 10, 160);
|
|
61
|
-
}}
|
|
62
|
-
onIsReady={(value) => {
|
|
63
|
-
console.log('canvas ready:', value);
|
|
64
|
-
}}
|
|
65
|
-
/>
|
|
66
|
-
</View>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const styles = StyleSheet.create({
|
|
71
|
-
container: {flex: 1},
|
|
72
|
-
canvas: {width: 300, height: 200},
|
|
73
|
-
});
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
`onCanvasCreate` 拿到 canvas 后即可 `getContext('2d'|'webgl')`。`toDataURL` 同步返回 `data:image/png;base64,...`。`registerFont(src, fontFace?)` 在鸿蒙已开通,随后可用 `getFontNames()` 查看枚举结果。加载远程图片时须在 `module.json5` 声明 `ohos.permission.INTERNET`。
|
|
77
|
-
|
|
78
|
-
## 接口文档
|
|
79
|
-
|
|
80
|
-
### 导出
|
|
81
|
-
|
|
82
|
-
| 名称 | 类型 | 说明 |
|
|
83
|
-
|------|------|------|
|
|
84
|
-
| `GCanvasView` | React 组件 | Canvas 2D / WebGL 原生视图 |
|
|
85
|
-
| `GImage` | 类 | 图片对象,走 `preLoadImage` |
|
|
86
|
-
| `createCanvas(width, height)` | 函数 | 创建离屏 Canvas |
|
|
87
|
-
| `getFontNames()` | 函数 | 返回系统可用字体名数组 |
|
|
88
|
-
| `registerFont(src, fontFace?)` | 函数 | 注册自定义字体(鸿蒙已开通) |
|
|
89
|
-
|
|
90
|
-
### `<GCanvasView>` Props / 事件
|
|
91
|
-
|
|
92
|
-
| 名称 | 类型 | 说明 |
|
|
93
|
-
|------|------|------|
|
|
94
|
-
| `isGestureResponsible` | boolean | 是否响应画布内手势,默认 `true` |
|
|
95
|
-
| `isAutoClearRectBeforePutImageData` | boolean | `putImageData` 前是否先 clear,仅 2D |
|
|
96
|
-
| `isResetGlViewportAfterSetWidthOrHeight` | boolean | 宽高变化后是否重置 viewport |
|
|
97
|
-
| `devicePixelRatio` | number | 未传时使用 `PixelRatio.get()` |
|
|
98
|
-
| `offscreenCanvas` | boolean | 是否可作为 `document.createElement('canvas')` 离屏画布 |
|
|
99
|
-
| `disableAutoSwap` | boolean | 关闭 WebGL 自动 swap |
|
|
100
|
-
| `onCanvasCreate` | `(canvas) => void` | 画布对象就绪 |
|
|
101
|
-
| `onCanvasResize` | `({width, height, canvas}) => void` | 视图尺寸变化 |
|
|
102
|
-
| `onIsReady` | `(value) => void` | GL surface 就绪 / 销毁 |
|
|
103
|
-
| `onMouseDown` / `onMouseMove` / `onMouseUp` | `(e) => void` | 触摸转 PointerEvent |
|
|
104
|
-
|
|
105
|
-
### Canvas / 上下文
|
|
106
|
-
|
|
107
|
-
| API | 说明 |
|
|
108
|
-
|-----|------|
|
|
109
|
-
| `canvas.getContext('2d' \| 'webgl')` | 取得 2D 或 WebGL 上下文 |
|
|
110
|
-
| `canvas.toDataURL(mimeType, quality)` | 同步导出 Base64 |
|
|
111
|
-
| `canvas.reset()` | 调用原生 `resetComponent` |
|
|
112
|
-
| 2D:`fillRect` / `strokeRect` / `clearRect` / `fill` / `stroke` / `arc` | 矩形与路径 |
|
|
113
|
-
| 2D:`fillText` / `strokeText` / `measureText` | 文本 |
|
|
114
|
-
| 2D:`createLinearGradient` / `createRadialGradient` / `createPattern` | 渐变与图案 |
|
|
115
|
-
| 2D:`scale` / `rotate` / `translate` / `save` / `restore` | 变换 |
|
|
116
|
-
| 2D:`drawImage` / `getImageData` / `putImageData` | 图片与像素 |
|
|
117
|
-
| WebGL:`createShader` / `compileShader` / `texImage2D` / `drawArrays` 等 | WebGL 1.0 |
|
|
118
|
-
|
|
119
|
-
### TurboModule `GCanvasModule`(经 JS 桥内部调用)
|
|
120
|
-
|
|
121
|
-
| 方法 | 同步 | 说明 |
|
|
122
|
-
|------|------|------|
|
|
123
|
-
| `enable` / `disable` / `resetComponent` | 混合同步 | 画布生命周期 |
|
|
124
|
-
| `extendCallNative` | 同步 | 命令字符串执行并返回结果 |
|
|
125
|
-
| `render` | 异步 | 命令字符串投递后立即返回 |
|
|
126
|
-
| `setContextType` / `setDevicePixelRatio` / `resetGlViewport` | 同步 | 上下文与视口 |
|
|
127
|
-
| `toDataURL` | 同步 | `glReadPixels` → PNG → base64 |
|
|
128
|
-
| `preLoadImage` / `bindImageTexture` | 异步 | 图片解码与纹理绑定 |
|
|
129
|
-
| `texImage2D` / `texSubImage2D` | 同步 | WebGL 纹理上传 |
|
|
130
|
-
| `getFontNames` / `addFontFamily` / `setExtraFontLocation` | 同步 | 字体 |
|
|
131
|
-
| `setAlpha` | 异步 | 空壳,对齐 Android/iOS,不产生实际透明度 |
|
|
132
|
-
|
|
133
|
-
## 快速验证(运行 Example)
|
|
134
|
-
|
|
135
|
-
### 前置条件
|
|
136
|
-
|
|
137
|
-
| 依赖 | 版本要求 |
|
|
138
|
-
|------|----------|
|
|
139
|
-
| Node.js | >= 18 |
|
|
140
|
-
| DevEco Studio | 5.0+ / 6.0+ |
|
|
141
|
-
| HarmonyOS SDK | API 12+ |
|
|
142
|
-
|
|
143
|
-
### 运行步骤
|
|
144
|
-
|
|
145
|
-
**1. 克隆仓库**
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
git clone https://gitcode.com/hxa-rn/react-native-gcanvas.git
|
|
149
|
-
cd react-native-gcanvas
|
|
150
|
-
git checkout
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
**2. 安装仓库开发依赖**
|
|
154
|
-
|
|
155
|
-
```bash
|
|
156
|
-
npm install --legacy-peer-deps
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Example 已改为从 npm 公仓安装 `@hxa-rn/react-native-gcanvas@6.0.
|
|
160
|
-
|
|
161
|
-
**3. 进入 example 目录,安装依赖**
|
|
162
|
-
|
|
163
|
-
```bash
|
|
164
|
-
cd example
|
|
165
|
-
npm install --legacy-peer-deps
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
**4. 生成 JS Bundle**
|
|
169
|
-
|
|
170
|
-
```bash
|
|
171
|
-
npm run dev
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
产物:`harmony/entry/src/main/resources/rawfile/bundle.harmony.js`
|
|
175
|
-
|
|
176
|
-
**5. 用 DevEco Studio 打开鸿蒙工程**
|
|
177
|
-
|
|
178
|
-
- 打开 DevEco Studio
|
|
179
|
-
- 选择 `example/harmony` 目录
|
|
180
|
-
- 等待 Sync 完成
|
|
181
|
-
|
|
182
|
-
**6. 编译并运行 HAP**
|
|
183
|
-
|
|
184
|
-
在 DevEco Studio 中点击运行按钮,将 HAP 安装到设备/模拟器。
|
|
185
|
-
|
|
186
|
-
> **注意**:Example 中已预置插件依赖和 Package 注册,无需手动配置 Link。
|
|
187
|
-
|
|
188
|
-
## 约束与限制
|
|
189
|
-
|
|
190
|
-
- **兼容性**:Demo `compatibleSdkVersion` 为 `5.0.1(13)`;`react-native` >= 0.72;RNOH 0.72+;HarmonyOS API 12+(适配构建环境为 API 13)。
|
|
191
|
-
- **权限**:加载远程 `http(s)` 图片时需在应用 `module.json5` 声明 `ohos.permission.INTERNET`。库模块本身无额外系统权限。
|
|
192
|
-
- **远程图片**:鸿蒙 `image.createImageSource` 不接受 http URL,须先经 `@ohos.net.http` 下载。
|
|
193
|
-
- **`setAlpha`**:空实现,对齐 Android/iOS 原空壳语义。
|
|
194
|
-
- **`getImageData` / `measureText`**:走 `execWithoutDisplay`,读完后需再绘制才能上屏。
|
|
195
|
-
- **真机渲染**:2D / WebGL 实际画面、字形与远程图片效果需在设备上确认。
|
|
196
|
-
|
|
197
|
-
## 开源license
|
|
198
|
-
|
|
199
|
-
本项目基于
|
|
200
|
-
|
|
201
|
-
## 问题反馈渠道
|
|
202
|
-
|
|
203
|
-
欢迎在 AtomGit 提交 Issue。也可在 GitCode 仓库反馈:
|
|
204
|
-
|
|
205
|
-
https://gitcode.com/hxa-rn/react-native-gcanvas
|
|
206
|
-
|
|
207
|
-
https://gitcode.com/hxa-rn/react-native-gcanvas/issues
|
|
1
|
+
# react-native-gcanvas
|
|
2
|
+
|
|
3
|
+
本项目基于 [@flyskywhy/react-native-gcanvas](https://github.com/flyskywhy/react-native-gcanvas)开发。如果在使用过程中有任何问题,欢迎在AtomGit提交Issue,会及时跟进。
|
|
4
|
+
|
|
5
|
+
## 项目介绍
|
|
6
|
+
|
|
7
|
+
`@hxa-rn/react-native-gcanvas` 是 `@flyskywhy/react-native-gcanvas@6.0.24` 的鸿蒙适配包,提供基于 C++ GCanvas(OpenGL ES)引擎的 Canvas 2D / WebGL 原生视图。业务侧通过 `harmony.alias` 继续 `import ... from '@flyskywhy/react-native-gcanvas'`。
|
|
8
|
+
|
|
9
|
+
本包含原生实现:C++ TurboModule `GCanvasModule`(20 个方法)+ Fabric 组件 `GCanvasView`(XComponent SURFACE + EGL)。JS 层复用上游命令字符串桥,鸿蒙侧补齐 `texImage2D` / `texSubImage2D`、`registerFont` / `getFontNames` 与远程图片下载。
|
|
10
|
+
|
|
11
|
+
当前版本:`6.0.26`。
|
|
12
|
+
|
|
13
|
+
## 集成指南
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @hxa-rn/react-native-gcanvas
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
本包声明:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"name": "@hxa-rn/react-native-gcanvas",
|
|
24
|
+
"version": "6.0.26",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react-native": ">=0.72"
|
|
27
|
+
},
|
|
28
|
+
"harmony": {
|
|
29
|
+
"alias": "@flyskywhy/react-native-gcanvas"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
工程按 `harmony.alias` 解析后,业务代码仍从原包名导入:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import {GCanvasView, GImage, createCanvas, getFontNames, registerFont} from '@flyskywhy/react-native-gcanvas';
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`peerDependencies` 为 `react-native` >= 0.72。本模块含 C++ TurboModule 与 Fabric 组件。Autolinking 可用时跳过手动注册;手动接入时需同时注册 C++ `GcanvasPackage` 与 ETS `GcanvasPackage`,并把 `harmony/gcanvas.har` 加入 entry 依赖。
|
|
41
|
+
|
|
42
|
+
## 使用说明
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import React from 'react';
|
|
46
|
+
import {StyleSheet, View} from 'react-native';
|
|
47
|
+
import {GCanvasView} from '@flyskywhy/react-native-gcanvas';
|
|
48
|
+
|
|
49
|
+
export default function App() {
|
|
50
|
+
return (
|
|
51
|
+
<View style={styles.container}>
|
|
52
|
+
<GCanvasView
|
|
53
|
+
style={styles.canvas}
|
|
54
|
+
onCanvasCreate={(canvas) => {
|
|
55
|
+
const ctx = canvas.getContext('2d');
|
|
56
|
+
ctx.fillStyle = '#FF5722';
|
|
57
|
+
ctx.fillRect(10, 10, 100, 100);
|
|
58
|
+
ctx.font = '24px';
|
|
59
|
+
ctx.fillStyle = '#222222';
|
|
60
|
+
ctx.fillText('Hello GCanvas', 10, 160);
|
|
61
|
+
}}
|
|
62
|
+
onIsReady={(value) => {
|
|
63
|
+
console.log('canvas ready:', value);
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
</View>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const styles = StyleSheet.create({
|
|
71
|
+
container: {flex: 1},
|
|
72
|
+
canvas: {width: 300, height: 200},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`onCanvasCreate` 拿到 canvas 后即可 `getContext('2d'|'webgl')`。`toDataURL` 同步返回 `data:image/png;base64,...`。`registerFont(src, fontFace?)` 在鸿蒙已开通,随后可用 `getFontNames()` 查看枚举结果。加载远程图片时须在 `module.json5` 声明 `ohos.permission.INTERNET`。
|
|
77
|
+
|
|
78
|
+
## 接口文档
|
|
79
|
+
|
|
80
|
+
### 导出
|
|
81
|
+
|
|
82
|
+
| 名称 | 类型 | 说明 |
|
|
83
|
+
|------|------|------|
|
|
84
|
+
| `GCanvasView` | React 组件 | Canvas 2D / WebGL 原生视图 |
|
|
85
|
+
| `GImage` | 类 | 图片对象,走 `preLoadImage` |
|
|
86
|
+
| `createCanvas(width, height)` | 函数 | 创建离屏 Canvas |
|
|
87
|
+
| `getFontNames()` | 函数 | 返回系统可用字体名数组 |
|
|
88
|
+
| `registerFont(src, fontFace?)` | 函数 | 注册自定义字体(鸿蒙已开通) |
|
|
89
|
+
|
|
90
|
+
### `<GCanvasView>` Props / 事件
|
|
91
|
+
|
|
92
|
+
| 名称 | 类型 | 说明 |
|
|
93
|
+
|------|------|------|
|
|
94
|
+
| `isGestureResponsible` | boolean | 是否响应画布内手势,默认 `true` |
|
|
95
|
+
| `isAutoClearRectBeforePutImageData` | boolean | `putImageData` 前是否先 clear,仅 2D |
|
|
96
|
+
| `isResetGlViewportAfterSetWidthOrHeight` | boolean | 宽高变化后是否重置 viewport |
|
|
97
|
+
| `devicePixelRatio` | number | 未传时使用 `PixelRatio.get()` |
|
|
98
|
+
| `offscreenCanvas` | boolean | 是否可作为 `document.createElement('canvas')` 离屏画布 |
|
|
99
|
+
| `disableAutoSwap` | boolean | 关闭 WebGL 自动 swap |
|
|
100
|
+
| `onCanvasCreate` | `(canvas) => void` | 画布对象就绪 |
|
|
101
|
+
| `onCanvasResize` | `({width, height, canvas}) => void` | 视图尺寸变化 |
|
|
102
|
+
| `onIsReady` | `(value) => void` | GL surface 就绪 / 销毁 |
|
|
103
|
+
| `onMouseDown` / `onMouseMove` / `onMouseUp` | `(e) => void` | 触摸转 PointerEvent |
|
|
104
|
+
|
|
105
|
+
### Canvas / 上下文
|
|
106
|
+
|
|
107
|
+
| API | 说明 |
|
|
108
|
+
|-----|------|
|
|
109
|
+
| `canvas.getContext('2d' \| 'webgl')` | 取得 2D 或 WebGL 上下文 |
|
|
110
|
+
| `canvas.toDataURL(mimeType, quality)` | 同步导出 Base64 |
|
|
111
|
+
| `canvas.reset()` | 调用原生 `resetComponent` |
|
|
112
|
+
| 2D:`fillRect` / `strokeRect` / `clearRect` / `fill` / `stroke` / `arc` | 矩形与路径 |
|
|
113
|
+
| 2D:`fillText` / `strokeText` / `measureText` | 文本 |
|
|
114
|
+
| 2D:`createLinearGradient` / `createRadialGradient` / `createPattern` | 渐变与图案 |
|
|
115
|
+
| 2D:`scale` / `rotate` / `translate` / `save` / `restore` | 变换 |
|
|
116
|
+
| 2D:`drawImage` / `getImageData` / `putImageData` | 图片与像素 |
|
|
117
|
+
| WebGL:`createShader` / `compileShader` / `texImage2D` / `drawArrays` 等 | WebGL 1.0 |
|
|
118
|
+
|
|
119
|
+
### TurboModule `GCanvasModule`(经 JS 桥内部调用)
|
|
120
|
+
|
|
121
|
+
| 方法 | 同步 | 说明 |
|
|
122
|
+
|------|------|------|
|
|
123
|
+
| `enable` / `disable` / `resetComponent` | 混合同步 | 画布生命周期 |
|
|
124
|
+
| `extendCallNative` | 同步 | 命令字符串执行并返回结果 |
|
|
125
|
+
| `render` | 异步 | 命令字符串投递后立即返回 |
|
|
126
|
+
| `setContextType` / `setDevicePixelRatio` / `resetGlViewport` | 同步 | 上下文与视口 |
|
|
127
|
+
| `toDataURL` | 同步 | `glReadPixels` → PNG → base64 |
|
|
128
|
+
| `preLoadImage` / `bindImageTexture` | 异步 | 图片解码与纹理绑定 |
|
|
129
|
+
| `texImage2D` / `texSubImage2D` | 同步 | WebGL 纹理上传 |
|
|
130
|
+
| `getFontNames` / `addFontFamily` / `setExtraFontLocation` | 同步 | 字体 |
|
|
131
|
+
| `setAlpha` | 异步 | 空壳,对齐 Android/iOS,不产生实际透明度 |
|
|
132
|
+
|
|
133
|
+
## 快速验证(运行 Example)
|
|
134
|
+
|
|
135
|
+
### 前置条件
|
|
136
|
+
|
|
137
|
+
| 依赖 | 版本要求 |
|
|
138
|
+
|------|----------|
|
|
139
|
+
| Node.js | >= 18 |
|
|
140
|
+
| DevEco Studio | 5.0+ / 6.0+ |
|
|
141
|
+
| HarmonyOS SDK | API 12+ |
|
|
142
|
+
|
|
143
|
+
### 运行步骤
|
|
144
|
+
|
|
145
|
+
**1. 克隆仓库**
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
git clone https://gitcode.com/hxa-rn/react-native-gcanvas.git
|
|
149
|
+
cd react-native-gcanvas
|
|
150
|
+
git checkout main
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**2. 安装仓库开发依赖**
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm install --legacy-peer-deps
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Example 已改为从 npm 公仓安装 `@hxa-rn/react-native-gcanvas@6.0.26`,不再使用本地 `file:../xxx.tgz`,运行 Example 不必再执行 `npm pack`。
|
|
160
|
+
|
|
161
|
+
**3. 进入 example 目录,安装依赖**
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
cd example
|
|
165
|
+
npm install --legacy-peer-deps
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**4. 生成 JS Bundle**
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
npm run dev
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
产物:`harmony/entry/src/main/resources/rawfile/bundle.harmony.js`
|
|
175
|
+
|
|
176
|
+
**5. 用 DevEco Studio 打开鸿蒙工程**
|
|
177
|
+
|
|
178
|
+
- 打开 DevEco Studio
|
|
179
|
+
- 选择 `example/harmony` 目录
|
|
180
|
+
- 等待 Sync 完成
|
|
181
|
+
|
|
182
|
+
**6. 编译并运行 HAP**
|
|
183
|
+
|
|
184
|
+
在 DevEco Studio 中点击运行按钮,将 HAP 安装到设备/模拟器。
|
|
185
|
+
|
|
186
|
+
> **注意**:Example 中已预置插件依赖和 Package 注册,无需手动配置 Link。
|
|
187
|
+
|
|
188
|
+
## 约束与限制
|
|
189
|
+
|
|
190
|
+
- **兼容性**:Demo `compatibleSdkVersion` 为 `5.0.1(13)`;`react-native` >= 0.72;RNOH 0.72+;HarmonyOS API 12+(适配构建环境为 API 13)。
|
|
191
|
+
- **权限**:加载远程 `http(s)` 图片时需在应用 `module.json5` 声明 `ohos.permission.INTERNET`。库模块本身无额外系统权限。
|
|
192
|
+
- **远程图片**:鸿蒙 `image.createImageSource` 不接受 http URL,须先经 `@ohos.net.http` 下载。
|
|
193
|
+
- **`setAlpha`**:空实现,对齐 Android/iOS 原空壳语义。
|
|
194
|
+
- **`getImageData` / `measureText`**:走 `execWithoutDisplay`,读完后需再绘制才能上屏。
|
|
195
|
+
- **真机渲染**:2D / WebGL 实际画面、字形与远程图片效果需在设备上确认。
|
|
196
|
+
|
|
197
|
+
## 开源license
|
|
198
|
+
|
|
199
|
+
本项目基于 Apache-2.0 协议,详见 [LICENSE](./LICENSE) 文件。
|
|
200
|
+
|
|
201
|
+
## 问题反馈渠道
|
|
202
|
+
|
|
203
|
+
欢迎在 AtomGit 提交 Issue。也可在 GitCode 仓库反馈:
|
|
204
|
+
|
|
205
|
+
https://gitcode.com/hxa-rn/react-native-gcanvas
|
|
206
|
+
|
|
207
|
+
https://gitcode.com/hxa-rn/react-native-gcanvas/issues
|