@react-native-ohos/react-native-svg 15.12.1-rc.3 → 15.12.1-rc.5

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.3',
9
+ version: '15.12.1-rc.5',
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
  },
@@ -21,6 +21,8 @@
21
21
 
22
22
  #include "SvgForeignObjectNode.h"
23
23
  #include "RNOH/arkui/NativeNodeApi.h"
24
+ #include <deviceinfo.h>
25
+ #include <info/application_target_sdk_version.h>
24
26
  namespace rnoh {
25
27
  namespace svg {
26
28
  SvgForeignObjectNode::SvgForeignObjectNode()
@@ -34,6 +36,7 @@ SvgForeignObjectNode::~SvgForeignObjectNode() {
34
36
  if (m_NodeDelegate) {
35
37
  m_NodeDelegate = nullptr;
36
38
  }
39
+ _isGeneratedPixelMap = false;
37
40
  }
38
41
  void SvgForeignObjectNode::insertChild(ArkUINode &child, std::size_t index) { mStackNode.insertChild(child, index); }
39
42
 
@@ -48,18 +51,26 @@ void SvgForeignObjectNode::SetSnapPosition(float x, float y) {
48
51
 
49
52
  void SvgForeignObjectNode::onNodeEvent(ArkUI_NodeEventType eventType, EventArgs &eventArgs) {
50
53
  if (eventType == ArkUI_NodeEventType::NODE_EVENT_ON_AREA_CHANGE) {
51
- if (m_NodeDelegate) {
54
+ if (m_NodeDelegate && _isGeneratedPixelMap) {
52
55
  OH_PixelmapNative *pixelMap = GetNodePixelMap();
53
56
  if (!pixelMap) {
54
57
  LOG(ERROR) << "[svgForeignNode] get node snapshot pixelMap is null";
55
58
  return;
56
59
  }
60
+ _isGeneratedPixelMap = false;
57
61
  m_NodeDelegate->onDrawForeignImage(pixelMap, _width, _height, _positionX, _positionY);
58
62
  }
59
63
  }
60
64
  }
61
65
 
62
66
  OH_PixelmapNative *SvgForeignObjectNode::GetNodePixelMap() {
67
+ DLOG(INFO) << "[svgForeignNode] OH_CURRENT_API_VERSION:" << OH_CURRENT_API_VERSION
68
+ << ";ROM SDK:" << OH_GetSdkApiVersion();
69
+
70
+ #if OH_CURRENT_API_VERSION >= 15
71
+ if (OH_GetSdkApiVersion() < 15) {
72
+ return nullptr;
73
+ }
63
74
  OH_PixelmapNative *pixelMap;
64
75
  ArkUI_SnapshotOptions *options = OH_ArkUI_CreateSnapshotOptions();
65
76
  OH_ArkUI_SnapshotOptions_SetScale(options, 1);
@@ -67,6 +78,7 @@ OH_PixelmapNative *SvgForeignObjectNode::GetNodePixelMap() {
67
78
  if (code == ARKUI_ERROR_CODE_NO_ERROR) {
68
79
  return pixelMap;
69
80
  }
81
+ #endif
70
82
  return nullptr;
71
83
  }
72
84
 
@@ -39,7 +39,9 @@ public:
39
39
  void SetSnapHeight(float height);
40
40
  OH_PixelmapNative *GetNodePixelMap();
41
41
  void SetForeignNodeDelegate(SvgForeignObjectNodeDelegate *delegate) { m_NodeDelegate = delegate; };
42
-
42
+ void SetGeneratedPixelMap(bool isNeed) {
43
+ _isGeneratedPixelMap = isNeed;
44
+ }
43
45
  private:
44
46
  StackNode mStackNode;
45
47
  SvgForeignObjectNodeDelegate *m_NodeDelegate;
@@ -47,6 +49,7 @@ private:
47
49
  float _height{0};
48
50
  float _positionX{0};
49
51
  float _positionY{0};
52
+ bool _isGeneratedPixelMap{false}; //防止快照生成多次,导致性能影响
50
53
  };
51
54
 
52
55
  } // namespace svg
@@ -6,6 +6,7 @@
6
6
 
7
7
  #include "SvgGroup.h"
8
8
  #include "SvgFilter.h"
9
+ #include "drawing/Brush.h"
9
10
 
10
11
  namespace rnoh {
11
12
  namespace svg {
@@ -30,7 +31,13 @@ void SvgGroup::OnInitStyle() {
30
31
  }
31
32
 
32
33
  void SvgGroup::OnDraw(OH_Drawing_Canvas *canvas) {
33
- OnDrawTraversed(canvas);
34
+ if (attributes_.selfOpacity < 1.0) {
35
+ drawing::Brush layerBrush;
36
+ uint8_t alpha= static_cast<uint8_t>(attributes_.selfOpacity* 255);
37
+ layerBrush.SetAlpha(alpha);
38
+ OH_Drawing_CanvasSaveLayer(canvas, nullptr, layerBrush.get());
39
+ }
40
+ SvgNode::OnDraw(canvas);
34
41
  }
35
42
 
36
43
  void SvgGroup::ApplyFilterToChildren(std::shared_ptr<SvgFilter> filter) {
@@ -77,6 +77,7 @@ void SvgNode::InitStyle(const SvgBaseAttribute &attr) {
77
77
  }
78
78
  }
79
79
  }
80
+ OnInitStyle();
80
81
  if (passStyle_) {
81
82
  for (auto &node : children_) {
82
83
  if (node) {
@@ -184,18 +184,32 @@ public:
184
184
 
185
185
  // Handle stroke properties - support both generic and text-specific structures
186
186
  if constexpr (requires { props->stroke; }) {
187
- if (!props->stroke.isNull() && props->stroke.count("type") > 0 && props->stroke.count("payload") > 0) {
187
+ if (!props->stroke.isNull() && props->stroke.count("type") > 0) {
188
188
  int strokeType = props->stroke["type"].asInt();
189
189
  if (strokeType == INHERIT_TYPE) {
190
- Color color = Color(static_cast<uint32_t>(props->stroke["payload"].asInt()));
191
- color.SetUseCurrentColor(true);
192
- attributes_.strokeState.SetColor(color, true);
193
- } else {
194
- uint32_t colorValue = static_cast<uint32_t>(props->stroke["payload"].asInt());
195
- if (facebook::react::isColorMeaningful(facebook::react::SharedColor(colorValue))) {
196
- attributes_.strokeState.SetColor(Color(colorValue), set.count("stroke"));
190
+ if (props->stroke.count("payload") > 0) {
191
+ Color color = Color(static_cast<uint32_t>(props->stroke["payload"].asInt()));
192
+ color.SetUseCurrentColor(true);
193
+ attributes_.strokeState.SetColor(color, true);
197
194
  } else {
198
- attributes_.strokeState.SetColor(Color::TRANSPARENT, set.count("stroke"));
195
+ if (props->color) {
196
+ Color color = Color(*props->color);
197
+ color.SetUseCurrentColor(true);
198
+ attributes_.strokeState.SetColor(color, true);
199
+ } else {
200
+ Color color = Color::TRANSPARENT;
201
+ color.SetUseCurrentColor(true);
202
+ attributes_.strokeState.SetColor(color, true);
203
+ }
204
+ }
205
+ } else {
206
+ if (props->stroke.count("payload") > 0) {
207
+ uint32_t colorValue = static_cast<uint32_t>(props->stroke["payload"].asInt());
208
+ if (facebook::react::isColorMeaningful(facebook::react::SharedColor(colorValue))) {
209
+ attributes_.strokeState.SetColor(Color(colorValue), set.count("stroke"));
210
+ } else {
211
+ attributes_.strokeState.SetColor(Color::TRANSPARENT, set.count("stroke"));
212
+ }
199
213
  }
200
214
  }
201
215
  } else if (!props->stroke.isNull() && props->stroke.count("payload") > 0) {
@@ -266,10 +280,14 @@ public:
266
280
  attributes_.Inherit(parent);
267
281
  // svg color -> current color
268
282
  if (attributes_.strokeState.GetColor().IsUseCurrentColor()) {
269
- attributes_.strokeState.SetColor(context_->GetSvgColor(), true);
283
+ if(context_) {
284
+ attributes_.strokeState.SetColor(context_->GetSvgColor(), true);
285
+ }
270
286
  }
271
287
  if (attributes_.fillState.GetColor().IsUseCurrentColor()) {
272
- attributes_.fillState.SetColor(context_->GetSvgColor(), true);
288
+ if(context_) {
289
+ attributes_.fillState.SetColor(context_->GetSvgColor(), true);
290
+ }
273
291
  }
274
292
  }
275
293
 
@@ -40,11 +40,11 @@ void RNSVGForeignObjectComponentInstance::onFinalizeUpdates() {
40
40
  ComponentInstance::onFinalizeUpdates();
41
41
  if (m_props) {
42
42
  float pointScaleFactor = getLayoutMetrics().pointScaleFactor;
43
- ;
44
43
  mForeignStackNode.SetSnapPosition(pointScaleFactor * std::stof(DynamicUtils::DynamicToString(m_props->x)),
45
44
  pointScaleFactor * std::stof(DynamicUtils::DynamicToString(m_props->y)));
46
45
  mForeignStackNode.SetSnapWidth(pointScaleFactor * std::stof(DynamicUtils::DynamicToString(m_props->width)));
47
46
  mForeignStackNode.SetSnapHeight(pointScaleFactor * std::stof(DynamicUtils::DynamicToString(m_props->height)));
47
+ mForeignStackNode.SetGeneratedPixelMap(true);
48
48
  }
49
49
  }
50
50
 
@@ -22,6 +22,7 @@ RNSVGSvgViewComponentInstance::RNSVGSvgViewComponentInstance(Context context)
22
22
 
23
23
  RNSVGSvgViewComponentInstance::~RNSVGSvgViewComponentInstance() {
24
24
  SvgViewManager::getInstance().onDropView(CppComponentInstance::getTag());
25
+ noSvgComponentIndex = 0;
25
26
  }
26
27
 
27
28
  void RNSVGSvgViewComponentInstance::onFinalizeUpdates() {
@@ -65,7 +66,8 @@ void RNSVGSvgViewComponentInstance::onChildInserted(ComponentInstance::Shared co
65
66
  for (ComponentInstance::Shared c : childInstance) {
66
67
  if (c->getComponentName().find("SVG") == std::string::npos) {
67
68
  NativeNodeApi::getInstance()->insertChildAt(m_svgArkUINode.getArkUINodeHandle(),
68
- c->getLocalRootArkUINode().getArkUINodeHandle(), index);
69
+ c->getLocalRootArkUINode().getArkUINodeHandle(), noSvgComponentIndex);
70
+ noSvgComponentIndex++;
69
71
  }
70
72
  auto groupChildInstance = c->getChildren();
71
73
  for (ComponentInstance::Shared c1 : groupChildInstance) {
@@ -49,6 +49,7 @@ public:
49
49
  private:
50
50
  SvgArkUINode m_svgArkUINode;
51
51
  std::shared_ptr<SvgSvg> m_svgSvg = std::make_shared<SvgSvg>();
52
+ int noSvgComponentIndex {0}; // 非svg添加的index(适配js侧view包裹会拆解子元素成平级)
52
53
  };
53
54
 
54
55
  } // namespace svg
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.3",
3
+ "version": "15.12.1-rc.5",
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,7 @@
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",
24
+ "@ohos/hvigor-ohos-plugin": "^6.20.0",
25
25
  "@react-native-community/cli": "15.0.1",
26
26
  "@tsconfig/react-native": "^3.0.0",
27
27
  "@types/jest": "^29.5.1",
@@ -29,7 +29,7 @@
29
29
  "@types/react": "^19.1.7",
30
30
  "@types/react-native": "^0.71.6",
31
31
  "react-native-builder-bob": "^0.20.4",
32
- "typescript": "^5.8.3"
32
+ "typescript": "^5.2.2"
33
33
  },
34
34
  "harmony": {
35
35
  "alias": "react-native-svg",
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "@tsconfig/react-native/tsconfig.json",
4
4
  ],
5
5
  "compilerOptions": {
6
- "noEmit": false
6
+ "noEmit": false,
7
7
  },
8
8
  "exclude": [
9
9
  "lib",