@react-native-ohos/react-native-svg 15.12.1-rc.6 → 15.12.1-rc.7

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.
@@ -6,7 +6,7 @@
6
6
  name: '@react-native-ohos/react-native-svg',
7
7
  type: 'module',
8
8
  main: 'index.ets',
9
- version: '15.12.1-rc.6',
9
+ version: '15.12.1-rc.7',
10
10
  dependencies: {
11
11
  "@rnoh/react-native-openharmony": "file:../../node_modules/@react-native-oh/react-native-harmony/harmony/react_native_openharmony.har"
12
12
  },
@@ -40,11 +40,11 @@ SvgForeignObjectNode::~SvgForeignObjectNode() {
40
40
  }
41
41
  void SvgForeignObjectNode::insertChild(ArkUINode &child, std::size_t index) { mStackNode.insertChild(child, index); }
42
42
 
43
- void SvgForeignObjectNode::SetSnapHeight(float height) { _height = height; }
43
+ void SvgForeignObjectNode::SetSnapHeight(Dimension height) { _height = height; }
44
44
 
45
- void SvgForeignObjectNode::SetSnapWidth(float width) { _width = width; }
45
+ void SvgForeignObjectNode::SetSnapWidth(Dimension width) { _width = width; }
46
46
 
47
- void SvgForeignObjectNode::SetSnapPosition(float x, float y) {
47
+ void SvgForeignObjectNode::SetSnapPosition(Dimension x, Dimension y) {
48
48
  _positionX = x;
49
49
  _positionY = y;
50
50
  }
@@ -58,7 +58,8 @@ void SvgForeignObjectNode::onNodeEvent(ArkUI_NodeEventType eventType, EventArgs
58
58
  return;
59
59
  }
60
60
  _isGeneratedPixelMap = false;
61
- ForeignProps foreignProps = {pixelMap, _width, _height, _positionX, _positionY, _path, _clipRule, _mask};
61
+ ForeignProps foreignProps = {pixelMap, _width, _height, _positionX,
62
+ _positionY, _path, _clipRule, _mask, pointScaleFactor_, transform_};
62
63
  m_NodeDelegate->onDrawForeignImage(foreignProps);
63
64
  }
64
65
  }
@@ -24,6 +24,7 @@
24
24
  #include "RNOH/arkui/ArkUINode.h"
25
25
  #include "RNOH/arkui/StackNode.h"
26
26
  #include "SvgForeignObjectNodeDelegate.h"
27
+ #include "properties/Dimension.h"
27
28
 
28
29
  namespace rnoh {
29
30
  namespace svg {
@@ -34,9 +35,18 @@ public:
34
35
  void onNodeEvent(ArkUI_NodeEventType eventType, EventArgs &eventArgs) override;
35
36
  StackNode &getSnapNode() { return mStackNode; }
36
37
  void insertChild(ArkUINode &child, std::size_t index);
37
- void SetSnapPosition(float x, float y);
38
- void SetSnapWidth(float width);
39
- void SetSnapHeight(float height);
38
+ void SetSnapPosition(Dimension x, Dimension y);
39
+ void SetSnapWidth(Dimension width);
40
+ void SetSnapHeight(Dimension height);
41
+ void SetPointScaleFactor(float pointScaleFactor) {
42
+ pointScaleFactor_ = pointScaleFactor;
43
+ }
44
+ void SetTransform(std::vector<double> transform) {
45
+ transform_ = transform;
46
+ }
47
+ void setNodeSize(float w, float h){
48
+ mStackNode.setSize({w, h});
49
+ }
40
50
  OH_PixelmapNative *GetNodePixelMap();
41
51
  void SetForeignNodeDelegate(SvgForeignObjectNodeDelegate *delegate) { m_NodeDelegate = delegate; };
42
52
  void SetGeneratedPixelMap(bool isNeed) {
@@ -54,13 +64,15 @@ public:
54
64
  private:
55
65
  StackNode mStackNode;
56
66
  SvgForeignObjectNodeDelegate *m_NodeDelegate;
57
- float _width{0};
58
- float _height{0};
59
- float _positionX{0};
60
- float _positionY{0};
67
+ Dimension _width{0};
68
+ Dimension _height{0};
69
+ Dimension _positionX{0};
70
+ Dimension _positionY{0};
61
71
  std::string _path{""};
62
72
  std::string _mask{""};
73
+ std::vector<double> transform_;
63
74
  int _clipRule{0};
75
+ float pointScaleFactor_{0};
64
76
  bool _isGeneratedPixelMap{false}; //防止快照生成多次,导致性能影响
65
77
  };
66
78
 
@@ -21,16 +21,19 @@
21
21
 
22
22
  #ifndef HARMONY_FOREIGNPROPS_H
23
23
  #define HARMONY_FOREIGNPROPS_H
24
+ #include "properties/Dimension.h"
24
25
  #include <multimedia/image_framework/image/pixelmap_native.h>
25
26
  #include <string>
26
27
  struct ForeignProps {
27
28
  OH_PixelmapNative *foreignPixelMap{nullptr};
28
- float width;
29
- float height;
30
- float x;
31
- float y;
29
+ rnoh::svg::Dimension width;
30
+ rnoh::svg::Dimension height;
31
+ rnoh::svg::Dimension x;
32
+ rnoh::svg::Dimension y;
32
33
  std::string path;
33
34
  int clipRule;
34
35
  std::string mask;
36
+ float pointScaleFactor;
37
+ std::vector<double> transform;
35
38
  };
36
39
  #endif //HARMONY_FOREIGNPROPS_H
@@ -141,9 +141,8 @@ void SvgNode::OnMask(OH_Drawing_Canvas *canvas) {
141
141
  refMask->Draw(canvas);
142
142
  }
143
143
 
144
- void SvgNode::OnTransform(OH_Drawing_Canvas *canvas) {
144
+ void SvgNode::OnTransform(OH_Drawing_Canvas *canvas, std::vector<double> transform) {
145
145
  // input transfrom: (float scaleX, float skewY, float skewX, float scaleY, float transX, float transY)
146
- const auto &transform = attributes_.transform;
147
146
  /* (OH_Drawing_Matrix* , float scaleX, float skewX, float transX, float skewY, float scaleY, float transY, float
148
147
  persp0, float persp1, float persp2 )
149
148
  */
@@ -192,7 +191,7 @@ void SvgNode::Draw(OH_Drawing_Canvas *canvas) {
192
191
  const auto count = OH_Drawing_CanvasGetSaveCount(canvas);
193
192
  OH_Drawing_CanvasSave(canvas);
194
193
  if (!attributes_.transform.empty()) {
195
- OnTransform(canvas);
194
+ OnTransform(canvas, attributes_.transform);
196
195
  }
197
196
  if (!hrefClipPath_.empty()) {
198
197
  OnClipPath(canvas);
@@ -331,6 +330,9 @@ void SvgNode::DrawForeignPixelMap(OH_Drawing_Canvas *canvas, ForeignProps _forei
331
330
  DLOG(INFO) << "[svgForeignNode] foreignPixelMap is null";
332
331
  return;
333
332
  }
333
+ if (!_foreignProps.transform.empty()) {
334
+ OnTransform(canvas, _foreignProps.transform);
335
+ }
334
336
  if (!_foreignProps.path.empty()) {
335
337
  DrawForeignClip(canvas,_foreignProps.path, _foreignProps.clipRule);
336
338
  }
@@ -338,8 +340,10 @@ void SvgNode::DrawForeignPixelMap(OH_Drawing_Canvas *canvas, ForeignProps _forei
338
340
  if (!_foreignProps.mask.empty()) {
339
341
  DrawForeignMask(canvas,_foreignProps.mask);
340
342
  }
341
-
342
- DLOG(INFO) << "[svgForeignNode] DrawForeignPixelMap start , width:" << _foreignProps.width;
343
+ double postionX = _foreignProps.x.ParsePropsToPx(OH_Drawing_CanvasGetWidth(canvas), _foreignProps.pointScaleFactor);
344
+ double postionY = _foreignProps.y.ParsePropsToPx(OH_Drawing_CanvasGetHeight(canvas), _foreignProps.pointScaleFactor);
345
+ double foreignW = _foreignProps.width.ParsePropsToPx(OH_Drawing_CanvasGetWidth(canvas), _foreignProps.pointScaleFactor);
346
+ double foreignH = _foreignProps.height.ParsePropsToPx(OH_Drawing_CanvasGetHeight(canvas), _foreignProps.pointScaleFactor);
343
347
  OH_Pixelmap_ImageInfo *imageInfo;
344
348
  OH_PixelmapImageInfo_Create(&imageInfo);
345
349
 
@@ -354,7 +358,9 @@ void SvgNode::DrawForeignPixelMap(OH_Drawing_Canvas *canvas, ForeignProps _forei
354
358
  OH_PixelmapNative_Release(_foreignProps.foreignPixelMap);
355
359
  return;
356
360
  }
357
-
361
+ float originalRelWidth = originalWidth > foreignW ? foreignW : originalWidth;
362
+ float originalRelHeight = originalHeight > foreignH ? foreignH : originalHeight;
363
+ DLOG(INFO) << "[svgForeignNode] DrawForeignPixelMap start , foreignH:" << foreignH << ";originalHeight:" << originalHeight <<";originalRelHeight:" << originalRelHeight;
358
364
  OH_Drawing_PixelMap *ohPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(_foreignProps.foreignPixelMap);
359
365
  if (!ohPixelMap) {
360
366
  DLOG(WARNING) << "[svgForeignNode] Failed to get OH_Drawing_PixelMap";
@@ -364,15 +370,12 @@ void SvgNode::DrawForeignPixelMap(OH_Drawing_Canvas *canvas, ForeignProps _forei
364
370
 
365
371
  OH_Drawing_CanvasSave(canvas);
366
372
 
367
- OH_Drawing_CanvasTranslate(canvas, _foreignProps.x, _foreignProps.y);
368
-
369
-
370
- float scaleX = static_cast<float>(_foreignProps.width) / originalWidth;
371
- float scaleY = static_cast<float>(_foreignProps.height) / originalHeight;
373
+ OH_Drawing_CanvasTranslate(canvas, postionX, postionY);
374
+
372
375
  OH_Drawing_CanvasScale(canvas, 1, 1);
373
376
 
374
- OH_Drawing_Rect *srcRect = OH_Drawing_RectCreate(0, 0, originalWidth, originalHeight);
375
- OH_Drawing_Rect *dstRect = OH_Drawing_RectCreate(0, 0, originalWidth, originalHeight);
377
+ OH_Drawing_Rect *srcRect = OH_Drawing_RectCreate(0, 0, originalRelWidth, originalRelHeight);
378
+ OH_Drawing_Rect *dstRect = OH_Drawing_RectCreate(0, 0, originalRelWidth, originalRelHeight);
376
379
  OH_Drawing_SamplingOptions *sampling = OH_Drawing_SamplingOptionsCreate(FILTER_MODE_LINEAR, MIPMAP_MODE_LINEAR);
377
380
  OH_Drawing_CanvasDrawPixelMapRect(canvas, ohPixelMap, srcRect, dstRect, sampling);
378
381
 
@@ -311,7 +311,7 @@ protected:
311
311
  virtual void OnDrawTraversed(OH_Drawing_Canvas *canvas);
312
312
  void OnClipPath(OH_Drawing_Canvas *canvas);
313
313
  void OnMask(OH_Drawing_Canvas *canvas);
314
- void OnTransform(OH_Drawing_Canvas *canvas);
314
+ void OnTransform(OH_Drawing_Canvas *canvas, std::vector<double> transform);
315
315
 
316
316
  const Rect &GetRootViewBox() const;
317
317
 
@@ -40,55 +40,31 @@ RNSVGForeignObjectComponentInstance::~RNSVGForeignObjectComponentInstance() {
40
40
  void RNSVGForeignObjectComponentInstance::onFinalizeUpdates() {
41
41
  ComponentInstance::onFinalizeUpdates();
42
42
  if (m_props) {
43
- float pointScaleFactor = getLayoutMetrics().pointScaleFactor;
44
- mForeignStackNode.SetSnapPosition(pointScaleFactor * std::stof(DynamicUtils::DynamicToString(m_props->x)),
45
- pointScaleFactor * std::stof(DynamicUtils::DynamicToString(m_props->y)));
46
- mForeignStackNode.SetSnapWidth(pointScaleFactor * std::stof(DynamicUtils::DynamicToString(m_props->width)));
47
- mForeignStackNode.SetSnapHeight(pointScaleFactor * std::stof(DynamicUtils::DynamicToString(m_props->height)));
43
+ mForeignStackNode.SetPointScaleFactor(getLayoutMetrics().pointScaleFactor);
44
+ mForeignStackNode.SetSnapPosition(propsConversionValue(m_props->x), propsConversionValue(m_props->y));
45
+ mForeignStackNode.SetSnapWidth(propsConversionValue(m_props->width));
46
+ mForeignStackNode.SetSnapHeight(propsConversionValue(m_props->height));
48
47
 
49
48
  mForeignStackNode.SetClipPath(m_props->clipPath, m_props->clipRule);
50
49
  mForeignStackNode.SetMask(m_props->mask);
51
-
50
+ mForeignStackNode.SetTransform(m_props->matrix);
52
51
  auto childs = getChildren();
53
52
  if (childs.size() > 0) {
54
53
  for (ComponentInstance::Shared c : childs) {
55
54
  if ((m_props->opacity > 0 && m_props->opacity != 1)) {
56
55
  setOpacity(c->getLocalRootArkUINode(), m_props->opacity);
57
56
  }
58
- transform(c->getLocalRootArkUINode());
59
57
  }
60
58
  }
61
59
  mForeignStackNode.SetGeneratedPixelMap(true);
62
60
  }
63
61
  }
64
62
 
65
- void RNSVGForeignObjectComponentInstance::transform(ArkUINode &node) {
66
- if constexpr (requires { m_props->matrix; }) {
67
- // matrix 6 -> 16 ,2d->3d
68
- if (m_props->matrix.size() != 6) {
69
- return;
70
- }
71
- std::array<ArkUI_NumberValue, 16> transformValue;
72
- for (int i = 0; i < 16; i++) {
73
- if (i == 0 || i == 1) {
74
- transformValue[i] = {.f32 = static_cast<float>(m_props->matrix[i])};
75
- } else if (i == 4) {
76
- transformValue[i] = {.f32 = static_cast<float>(m_props->matrix[2])};
77
- } else if (i == 5) {
78
- transformValue[i] = {.f32 = static_cast<float>(m_props->matrix[3])};
79
- } else if (i == 10 || i == 15) {
80
- transformValue[i] = {.f32 = static_cast<float>(1)};
81
- } else if (i == 12) {
82
- transformValue[i] = {.f32 = static_cast<float>(m_props->matrix[4])};
83
- } else if (i == 13) {
84
- transformValue[i] = {.f32 = static_cast<float>(m_props->matrix[5])};
85
- } else {
86
- transformValue[i] = {.f32 = static_cast<float>(0)};
87
- }
88
- }
89
- ArkUI_AttributeItem transformItem = {transformValue.data(), transformValue.size()};
90
- NativeNodeApi::getInstance()->setAttribute(node.getArkUINodeHandle(), NODE_TRANSFORM, &transformItem);
63
+ Dimension RNSVGForeignObjectComponentInstance::propsConversionValue(const folly::dynamic &d) {
64
+ if (d.isNull()) {
65
+ return Dimension(0, DimensionUnit::INVALID);
91
66
  }
67
+ return StringUtils::StringToDimension(d.asString(), true);
92
68
  }
93
69
 
94
70
  void RNSVGForeignObjectComponentInstance::setOpacity(ArkUINode &node, float op) {
@@ -100,6 +76,9 @@ void RNSVGForeignObjectComponentInstance::setOpacity(ArkUINode &node, float op)
100
76
  void RNSVGForeignObjectComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
101
77
  std::size_t index) {
102
78
  CppComponentInstance::onChildInserted(childComponentInstance, index);
79
+ float width = childComponentInstance->getLayoutMetrics().frame.size.width;
80
+ float height = childComponentInstance->getLayoutMetrics().frame.size.height;
81
+ mForeignStackNode.setNodeSize(width, height);
103
82
  node.insertChild(childComponentInstance->getLocalRootArkUINode(), index);
104
83
  }
105
84
 
@@ -27,6 +27,8 @@
27
27
  #include "RNOH/arkui/ColumnNode.h"
28
28
  #include "RNOH/arkui/NativeNodeApi.h"
29
29
  #include "utils/DynamicUtils.h"
30
+ #include "properties/Dimension.h"
31
+ #include "utils/StringUtils.h"
30
32
  namespace rnoh {
31
33
  namespace svg {
32
34
  class RNSVGForeignObjectComponentInstance : public CppComponentInstance<facebook::react::RNSVGForeignObjectShadowNode> {
@@ -43,7 +45,7 @@ public:
43
45
 
44
46
  void setOpacity(ArkUINode &node, float op);
45
47
 
46
- void transform(ArkUINode &node);
48
+ Dimension propsConversionValue(const folly::dynamic& d);
47
49
  private:
48
50
  SvgForeignObjectNode mForeignStackNode;
49
51
  ColumnNode node;
@@ -49,8 +49,8 @@ void RNSVGSvgViewComponentInstance::onFinalizeUpdates() {
49
49
 
50
50
  void RNSVGSvgViewComponentInstance::onDrawForeignImage(ForeignProps foreignProps) {
51
51
  if (foreignProps.foreignPixelMap) {
52
- DLOG(INFO) << "[svgForeignNode] RNSVGSvgViewComponentInstance OH_PixelmapNative is not null, position:{ x:" << foreignProps.x
53
- << ",y:" << foreignProps.y << "},width:" << foreignProps.width << ";height:" << foreignProps.height;
52
+ DLOG(INFO) << "[svgForeignNode] RNSVGSvgViewComponentInstance OH_PixelmapNative is not null, position:{ x:" << foreignProps.x.Value()
53
+ << ",y:" << foreignProps.y.Value() << "},width:" << foreignProps.width.Value() << ";height:" << foreignProps.height.Value();
54
54
  m_svgArkUINode.SetForeignObject(foreignProps);
55
55
  m_svgArkUINode.markDirty();
56
56
  } else {
@@ -141,6 +141,20 @@ public:
141
141
  return 0.0;
142
142
  };
143
143
 
144
+ double ParsePropsToPx(double relative, float pointScaleFactor){
145
+ if (unit_ == DimensionUnit::NONE) {
146
+ return value_*pointScaleFactor;
147
+ }
148
+ if (unit_ == DimensionUnit::PERCENT) {
149
+ return value_*relative - pointScaleFactor;
150
+ }
151
+ if (unit_ == DimensionUnit::VP) {
152
+ return value_*pointScaleFactor;
153
+ } else {
154
+ return value_;
155
+ }
156
+ }
157
+
144
158
  double GetNativeValue(DimensionUnit unit, double scale) const {
145
159
  if (unit_ == unit) {
146
160
  return value_;
package/harmony/svg.har CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-ohos/react-native-svg",
3
- "version": "15.12.1-rc.6",
3
+ "version": "15.12.1-rc.7",
4
4
  "description": "",
5
5
  "react-native": "src/index",
6
6
  "main": "lib/commonjs/index",
@@ -8,7 +8,7 @@
8
8
  "types": "lib/typescript/index.d.ts",
9
9
  "scripts": {
10
10
  "prepack": "bob build",
11
- "prepublishOnly": "npm run prepack",
11
+ "prepublishOnly": "npm run prepack && react-native verify-package-harmony --package-path . --skip-checks oh_package_name_is_derived_from_npm_package_name",
12
12
  "update_version": "node ./scripts/update-version.js",
13
13
  "deploy": "node ./scripts/deploy.js",
14
14
  "codegen-lib": "react-native codegen-lib-harmony --no-safety-check --npm-package-name react-native-svg --cpp-output-path ./harmony/svg/src/main/cpp/generated --ets-output-path ./harmony/svg/src/main/ets/generated --cpp-components-spec-paths ./node_modules/react-native-svg/src/fabric"
@@ -21,7 +21,6 @@
21
21
  "react-native-svg": "15.12.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@rnoh/react-native-harmony-cli": "./packages/react-native-oh-react-native-harmony-cli-0.77.18.tgz",
25
24
  "@react-native-community/cli": "15.0.1",
26
25
  "@tsconfig/react-native": "^3.0.0",
27
26
  "@types/jest": "^29.5.1",