Skip to content

Commit

Permalink
refactor: improve code readability and robustness (#320)
Browse files Browse the repository at this point in the history
Signed-off-by: Louis-C7 <[email protected]>
  • Loading branch information
Louis-C7 authored Dec 11, 2024
1 parent 2ce6cdc commit 0c5222e
Show file tree
Hide file tree
Showing 101 changed files with 714 additions and 907 deletions.
90 changes: 90 additions & 0 deletions OAT.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<oatconfig>
<licensefile>LICENSE</licensefile>
<policylist>
<policy name="projectPolicy" desc="">
<policyitem type="license" name="MIT" path=".*" desc="license under the MIT"/>
</policy>
<policy name="projectPolicy" desc="">
<policyitem type="compatibility" name="GPL-2.0+" path=".*" desc="Process that runs independently, invoked by the X process."/>
<policyitem type="compatibility" name="Apache-2.0" path=".*" desc="不影响兼容性"/>
<policyitem type="compatibility" name="BSDStyleLicense" path=".*" desc="不影响兼容性" />
<policyitem type="compatibility" name="MIT" path=".*" desc="不影响兼容性" />
<policyitem type="compatibility" name="GPLStyleLicense" path=".*" desc="不影响兼容性" />
</policy>
</policylist>
<filefilterlist>
<filefilter name="copyrightPolicyFilter" desc="Filters for compatibility,license header policies">
<filteritem type="filepath" name="react-native-harmony-svg/harmony/svg/hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filepath" name="tester/harmony/svg/src/main/cpp/generated/.*" desc="Codegen生成文件,不手动修改"/>
<filteritem type="filepath" name="tester/harmony/svg/src/main/ets/generated/.*" desc="Codegen生成文件,不手动修改"/>
<filteritem type="filename" name="LICENSE" desc="版权文件,不添加版权头"/>
<filteritem type="filename" name="hvigorw" desc="工程模板,不修改版权头,以防有修改版权风险"/>
<filteritem type="filename" name="hvigorw.bat" desc="工程模板,不修改版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/elements/Image.tsx" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/fabric/NativeSvgImageModule.ts" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/css/index.tsx" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/elements/Shape.tsx" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/index.tsx" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/.prettierrc.js" desc="项目配置文件,不添加版权头"/>
<filteritem type="filepath" name="tester/android/.*" desc="示例工程,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/harmony/entry/.*" desc="示例工程,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/harmony/svg/src/main/cpp/svgImage/.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="tester/harmony/svg/hvigorfile.ts" desc="工程模板,不修改版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="tester/harmony/svg/build-profile.json5" desc="工程模板,不修改版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="tester/svgDemoCases/.*" desc="测试用例,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/SVGDemo/.*" desc="测试用例,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/App.tsx" desc="测试用例,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/index.js" desc="测试用例,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/babel.config.js" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/.prettierrc.js" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/scripts/.*" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filename" name=".npmrc" desc="项目配置文件,不添加版权头"/>
<filteritem type="filepath" name="tester/.node-version" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/Gemfile" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/.watchmanconfig" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filename" name="*.json5" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/harmony/hvigorfile.ts" desc="配置文件,DevEco Studio自动生成,不手动修改"/> <filteritem type="filepath" name="tester/harmony/build-profile.template.json5" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/metro.config.js" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
<filteritem type="filepath" name="react-native-harmony-svg/harmony/svg/hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
<filteritem type="filepath" name="tester/harmony/svg/src/main/cpp/generated/.*" desc="Codegen生成文件,不手动修改"/>
<filteritem type="filepath" name="tester/harmony/svg/src/main/ets/generated/.*" desc="Codegen生成文件,不手动修改"/>
<filteritem type="filename" name="LICENSE" desc="版权文件,不添加版权头"/>
<filteritem type="filename" name="hvigorw" desc="工程模板,不修改版权头,以防有修改版权风险"/>
<filteritem type="filename" name="hvigorw.bat" desc="工程模板,不修改版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/elements/Image.tsx" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/fabric/NativeSvgImageModule.ts" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/css/index.tsx" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/elements/Shape.tsx" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/src/index.tsx" desc="第三方开源软件源码,原本无版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="react-native-harmony-svg/.prettierrc.js" desc="项目配置文件,不添加版权头"/>
<filteritem type="filepath" name="tester/android/.*" desc="示例工程,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/harmony/entry/.*" desc="示例工程,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/harmony/svg/src/main/cpp/svgImage/.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="tester/harmony/svg/hvigorfile.ts" desc="工程模板,不修改版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="tester/harmony/svg/build-profile.json5" desc="工程模板,不修改版权头,以防有修改版权风险"/>
<filteritem type="filepath" name="tester/svgDemoCases/.*" desc="测试用例,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/SVGDemo/.*" desc="测试用例,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/App.tsx" desc="测试用例,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/index.js" desc="测试用例,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/babel.config.js" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/.prettierrc.js" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/scripts/.*" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filename" name=".npmrc" desc="项目配置文件,不添加版权头"/>
<filteritem type="filepath" name="tester/.node-version" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/Gemfile" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/.watchmanconfig" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filename" name="*.json5" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/harmony/hvigorfile.ts" desc="配置文件,DevEco Studio自动生成,不手动修改"/> <filteritem type="filepath" name="tester/harmony/build-profile.template.json5" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
<filteritem type="filepath" name="tester/metro.config.js" desc="示例工程配置文件,非业务代码,不添加许可证头"/>
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for copyright header policies">
<filteritem type="filepath" name="react-native-harmony-svg/harmony/svg.har" desc="项目打包文件" />
<filteritem type="filepath" name="tester/.*" desc="示例工程,非业务代码" />
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>
21 changes: 21 additions & 0 deletions react-native-harmony-svg/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) [2015-2016] [Horcrux]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file not shown.
Binary file removed tester/harmony/dependencies/hvigor-4.3.0.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion tester/harmony/svg/src/main/cpp/Attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*
* This file incorporates code from another team within Huawei Device Co., Ltd, licensed under
* This file incorporates from the OpenHarmony project, licensed under
* the Apache License, Version 2.0. Specifically:
* - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine)
*
Expand Down
5 changes: 1 addition & 4 deletions tester/harmony/svg/src/main/cpp/SVGPackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ std::vector<react::ComponentDescriptorProvider> SVGPackage::createComponentDescr
};
}

ComponentNapiBinderByString SVGPackage::createComponentNapiBinderByName()
{
return {};
}
ComponentNapiBinderByString SVGPackage::createComponentNapiBinderByName() { return {}; }

ComponentJSIBinderByString SVGPackage::createComponentJSIBinderByName() {
return {
Expand Down
5 changes: 2 additions & 3 deletions tester/harmony/svg/src/main/cpp/SVGPackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ class SVGPackageComponentInstanceFactoryDelegate : public ComponentInstanceFacto
class SVGPackage : public Package {
public:
explicit SVGPackage(Package::Context ctx) : Package(ctx) {}

std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate()
override;

std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override;

ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate() override {
return std::make_shared<SVGPackageComponentInstanceFactoryDelegate>();
Expand Down
7 changes: 4 additions & 3 deletions tester/harmony/svg/src/main/cpp/SvgArkUINode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* found in the LICENSE file.
*/

#include "arkui/native_interface.h"
#include "arkui/native_node.h"
#include "arkui/native_type.h"
#include "RNOH/arkui/NativeNodeApi.h"
Expand All @@ -20,6 +19,8 @@
namespace rnoh {
namespace svg {

constexpr int NODE_EVENT_ID = 77;

// 对应SVGArkUINode
SvgArkUINode::SvgArkUINode() : ArkUINode(NativeNodeApi::getInstance()->createNode(ArkUI_NodeType::ARKUI_NODE_CUSTOM)) {
userCallback_ = new UserCallback();
Expand All @@ -35,15 +36,15 @@ SvgArkUINode::SvgArkUINode() : ArkUINode(NativeNodeApi::getInstance()->createNod
}
};
eventReceiver = [](ArkUI_NodeCustomEvent *event) {
if (OH_ArkUI_NodeCustomEvent_GetEventTargetId(event) == 77) {
if (OH_ArkUI_NodeCustomEvent_GetEventTargetId(event) == NODE_EVENT_ID) {
auto *userData = reinterpret_cast<UserCallback *>(OH_ArkUI_NodeCustomEvent_GetUserData(event));
if (userData != nullptr && userData->callback != nullptr) {
userData->callback(event);
}
}
};
maybeThrow(NativeNodeApi::getInstance()->addNodeCustomEventReceiver(m_nodeHandle, eventReceiver));
maybeThrow(NativeNodeApi::getInstance()->registerNodeCustomEvent(m_nodeHandle, ARKUI_NODE_CUSTOM_EVENT_ON_DRAW, 77,
maybeThrow(NativeNodeApi::getInstance()->registerNodeCustomEvent(m_nodeHandle, ARKUI_NODE_CUSTOM_EVENT_ON_DRAW, NODE_EVENT_ID,
userCallback_));
}

Expand Down
2 changes: 1 addition & 1 deletion tester/harmony/svg/src/main/cpp/SvgBaseAttribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*
* This file incorporates code from another team within Huawei Device Co., Ltd, licensed under
* This file incorporates from the OpenHarmony project, licensed under
* the Apache License, Version 2.0. Specifically:
* - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine)
*
Expand Down
14 changes: 7 additions & 7 deletions tester/harmony/svg/src/main/cpp/SvgDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ namespace rnoh {
namespace svg {

class SvgDefs : public SvgNode {

public:
SvgDefs() : SvgNode() { InitDefsFlag(); }

~SvgDefs() override = default;

void InitDefsFlag() {
Expand All @@ -28,12 +26,14 @@ class SvgDefs : public SvgNode {

drawing::Path AsPath() override {
drawing::Path path;
DLOG(INFO) << "[SvgDfes:AsPath] : arrived Defs AsPath";
for (auto child : children_) {
// Early return if there are no children
if (children_.empty()) {
return path;
}
for (const auto& child : children_) {
if (!child) {
DLOG(INFO) << "[SvgDfes:AsPath] : childnode is a null ptr";
} else {
DLOG(INFO) << "[SvgDfes:AsPath] : get child path:";
DLOG(WARNING) << "[SvgDefs:AsPath] Encountered a null child node";
continue;
}
auto childPath = child->AsPath();
path.Union(childPath);
Expand Down
22 changes: 15 additions & 7 deletions tester/harmony/svg/src/main/cpp/SvgGradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
namespace rnoh {
namespace svg {

constexpr int TRANSFORM_SCALE_X_INDEX = 0;
constexpr int TRANSFORM_SKEW_Y_INDEX = 1;
constexpr int TRANSFORM_SKEW_X_INDEX = 2;
constexpr int TRANSFORM_SCALE_Y_INDEX = 3;
constexpr int TRANSFORM_TRANSLATE_X_INDEX = 4;
constexpr int TRANSFORM_TRANSLATE_Y_INDEX = 5;
constexpr size_t GRADIENT_TRANSFORM_MATRIX_SIZE = 6;

SvgGradient::SvgGradient(GradientType gradientType)
{
gradientAttr_.gradient.SetType(gradientType);
Expand Down Expand Up @@ -88,13 +96,13 @@ void SvgGradient::SetAttrGradientTransforms(std::vector<Float> gradientTransform
0, 1, 0,
0, 0, 1,
};
if (gradientTransforms.size() == 6) {
newMatrix[0] = (Float) gradientTransforms[0];
newMatrix[1] = (Float) gradientTransforms[2];
newMatrix[2] = (Float) gradientTransforms[4] * scale_;
newMatrix[3] = (Float) gradientTransforms[1];
newMatrix[4] = (Float) gradientTransforms[3];
newMatrix[5] = (Float) gradientTransforms[5] * scale_;
if (gradientTransforms.size() == GRADIENT_TRANSFORM_MATRIX_SIZE) {
newMatrix[0] = (Float) gradientTransforms[TRANSFORM_SCALE_X_INDEX];
newMatrix[1] = (Float) gradientTransforms[TRANSFORM_SKEW_X_INDEX];
newMatrix[2] = (Float) gradientTransforms[TRANSFORM_TRANSLATE_X_INDEX] * scale_;
newMatrix[3] = (Float) gradientTransforms[TRANSFORM_SKEW_Y_INDEX];
newMatrix[4] = (Float) gradientTransforms[TRANSFORM_SCALE_Y_INDEX];
newMatrix[5] = (Float) gradientTransforms[TRANSFORM_TRANSLATE_Y_INDEX] * scale_;
gradientAttr_.gradient.SetGradientTransform(std::move(newMatrix));
}
}
Expand Down
Loading

0 comments on commit 0c5222e

Please sign in to comment.