Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
新增RNSVGRadialGradient 空实现
Browse files Browse the repository at this point in the history
  • Loading branch information
425765923 committed Apr 20, 2024
1 parent 0136457 commit f2e3f22
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 4 deletions.
Binary file modified harmony/svg.har
Binary file not shown.
4 changes: 4 additions & 0 deletions harmony/svg/src/main/cpp/ComponentDescriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern const char RN_SVG_T_SPAN_COMPONENT_NAME[] = "RNSVGTSpan";
extern const char RN_SVG_CLIP_PATH_COMPONENT_NAME[] = "RNSVGClipPath";
extern const char RN_SVG_MASK_COMPONENT_NAME[] = "RNSVGMask";
extern const char RN_SVG_USE_COMPONENT_NAME[] = "RNSVGUse";
extern const char RN_SVG_RADIAL_GRADIENT_NAME[] = "RNSVGRadialGradient";

using RNSVGSvgViewShadowNode = ConcreteViewShadowNode<RN_SVG_SVG_VIEW_COMPONENT_NAME, RNSVGSvgViewProps>;

Expand Down Expand Up @@ -74,6 +75,8 @@ using RNSVGMaskShadowNode = ConcreteViewShadowNode<RN_SVG_MASK_COMPONENT_NAME, R

using RNSVGUseShadowNode = ConcreteViewShadowNode<RN_SVG_USE_COMPONENT_NAME, RNSVGUseProps>;

using RNSVGRadialGradientShadowNode = ConcreteViewShadowNode<RN_SVG_RADIAL_GRADIENT_NAME, RNSVGRadialGradientProps>;

using RNSVGGroupComponentDescriptor = ConcreteComponentDescriptor<RNSVGGroupShadowNode>;
using RNSVGSvgViewComponentDescriptor = ConcreteComponentDescriptor<RNSVGSvgViewShadowNode>;
using RNSVGPathComponentDescriptor = ConcreteComponentDescriptor<RNSVGPathShadowNode>;
Expand All @@ -88,6 +91,7 @@ using RNSVGTSpanComponentDescriptor = ConcreteComponentDescriptor<RNSVGTSpanShad
using RNSVGClipPathComponentDescriptor = ConcreteComponentDescriptor<RNSVGClipPathShadowNode>;
using RNSVGMaskComponentDescriptor = ConcreteComponentDescriptor<RNSVGMaskShadowNode>;
using RNSVGUseComponentDescriptor = ConcreteComponentDescriptor<RNSVGUseShadowNode>;
using RNSVGRadialGradientComponentDescriptor = ConcreteComponentDescriptor<RNSVGRadialGradientShadowNode>;

} // namespace react
} // namespace facebook
1 change: 1 addition & 0 deletions harmony/svg/src/main/cpp/Props.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "RNSVGClipPathProps.h"
#include "RNSVGMaskProps.h"
#include "RNSVGUseProps.h"
#include "RNSVGRadialGradientProps.h"

namespace facebook {
namespace react {
Expand Down
43 changes: 43 additions & 0 deletions harmony/svg/src/main/cpp/RNSVGRadialGradientJSIBinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* 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.
*/

#pragma once

#include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"

namespace rnoh {

class RNSVGRadialGradientJSIBinder : public ViewComponentJSIBinder {
facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override
{
auto object = ViewComponentJSIBinder::createNativeProps(rt);
return object;
}

facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override
{
return facebook::jsi::Object(rt);
}
};
} // namespace rnoh
41 changes: 41 additions & 0 deletions harmony/svg/src/main/cpp/RNSVGRadialGradientNapiBinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* 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.
*/

#pragma once

#include "RNOHCorePackage/ComponentBinders/ViewComponentNapiBinder.h"
#include "RNOH/ArkJS.h"
#include "RNSVGMaskProps.h"

namespace rnoh {

class RNSVGRadialGradientNapiBinder : public ViewComponentNapiBinder {
public:
napi_value createProps(napi_env env, facebook::react::ShadowView const shadowView) override
{
napi_value napiViewProps = ViewComponentNapiBinder::createProps(env, shadowView);
return napiViewProps;
};
};
} // namespace rnoh
38 changes: 38 additions & 0 deletions harmony/svg/src/main/cpp/RNSVGRadialGradientProps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* 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.
*/

#include <react/renderer/components/image/conversions.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>
#include "RNSVGRadialGradientProps.h"

namespace facebook {
namespace react {


RNSVGRadialGradientProps::RNSVGRadialGradientProps(const PropsParserContext &context, const RNSVGRadialGradientProps &sourceProps,
const RawProps &rawProps)
: ViewProps(context, sourceProps, rawProps){}
} // namespace react
} // namespace facebook
45 changes: 45 additions & 0 deletions harmony/svg/src/main/cpp/RNSVGRadialGradientProps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* 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.
*/

#pragma once

#include <jsi/jsi.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>

namespace facebook {
namespace react {

class JSI_EXPORT RNSVGRadialGradientProps final : public ViewProps {
public:
RNSVGRadialGradientProps() = default;
RNSVGRadialGradientProps(const PropsParserContext& context, const RNSVGRadialGradientProps &sourceProps, const RawProps &rawProps);

#pragma mark - Props

};

} // namespace react
} // namespace facebook
11 changes: 8 additions & 3 deletions harmony/svg/src/main/cpp/SVGPackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "RNSVGClipPathNapiBinder.h"
#include "RNSVGMaskNapiBinder.h"
#include "RNSVGUseNapiBinder.h"
#include "RNSVGRadialGradientNapiBinder.h"

#include "RNSVGGroupJSIBinder.h"
#include "RNSVGSvgViewJSIBinder.h"
Expand All @@ -55,6 +56,7 @@
#include "RNSVGClipPathJSIBinder.h"
#include "RNSVGMaskJSIBinder.h"
#include "RNSVGUseJSIBinder.h"
#include "RNSVGRadialGradientJSIBinder.h"

using namespace rnoh;
using namespace facebook;
Expand All @@ -74,7 +76,8 @@ std::vector<react::ComponentDescriptorProvider> SVGPackage::createComponentDescr
react::concreteComponentDescriptorProvider<react::RNSVGTSpanComponentDescriptor>(),
react::concreteComponentDescriptorProvider<react::RNSVGClipPathComponentDescriptor>(),
react::concreteComponentDescriptorProvider<react::RNSVGMaskComponentDescriptor>(),
react::concreteComponentDescriptorProvider<react::RNSVGUseComponentDescriptor>()};
react::concreteComponentDescriptorProvider<react::RNSVGUseComponentDescriptor>(),
react::concreteComponentDescriptorProvider<react::RNSVGRadialGradientComponentDescriptor>()};
}

ComponentNapiBinderByString rnoh::SVGPackage::createComponentNapiBinderByName()
Expand All @@ -92,7 +95,8 @@ ComponentNapiBinderByString rnoh::SVGPackage::createComponentNapiBinderByName()
{"RNSVGTSpan", std::make_shared<RNSVGTSpanNapiBinder>()},
{"RNSVGClipPath", std::make_shared<RNSVGClipPathNapiBinder>()},
{"RNSVGMask", std::make_shared<RNSVGMaskNapiBinder>()},
{"RNSVGUse", std::make_shared<RNSVGUseNapiBinder>()}};
{"RNSVGUse", std::make_shared<RNSVGUseNapiBinder>()},
{"RNSVGRadialGradient", std::make_shared<RNSVGRadialGradientNapiBinder>()}};
}

ComponentJSIBinderByString rnoh::SVGPackage::createComponentJSIBinderByName()
Expand All @@ -110,5 +114,6 @@ ComponentJSIBinderByString rnoh::SVGPackage::createComponentJSIBinderByName()
{"RNSVGTSpan", std::make_shared<RNSVGTSpanJSIBinder>()},
{"RNSVGClipPath", std::make_shared<RNSVGClipPathJSIBinder>()},
{"RNSVGMask", std::make_shared<RNSVGMaskJSIBinder>()},
{"RNSVGUse", std::make_shared<RNSVGUseJSIBinder>()}};
{"RNSVGUse", std::make_shared<RNSVGUseJSIBinder>()},
{"RNSVGRadialGradient", std::make_shared<RNSVGRadialGradientJSIBinder>()}};
};
5 changes: 5 additions & 0 deletions harmony/svg/src/main/ets/SVGComponentFactory.ets
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { SVGEllipse, SVG_ELLIPSE_TYPE_NAME } from './components/SVGEllipse'
import { SVGViewCommon } from './common/SVGType'
import { SVG_Mask_TYPE_NAME } from './common/SVGMask'
import { SVGUse, SVG_USE_TYPE_NAME } from './components/SVGUse'
import { SVGRadialGradient, SVG_RADIAL_GRADIENT_TYPE_NAME } from './components/SVGRadialGradient'

export type CustomComponentBuilder = (ctx: ComponentBuilderContext) => void

Expand Down Expand Up @@ -86,6 +87,8 @@ export struct SVGComponentFactory {
SVGText({ ctx: this.ctx, tag: this.tag })
} else if (this.componentName === SVG_CIRCLE_TYPE_NAME) {
SVGCircle({ ctx: this.ctx, tag: this.tag })
} else if (this.componentName === SVG_RADIAL_GRADIENT_TYPE_NAME) {
SVGRadialGradient({ ctx: this.ctx, tag: this.tag })
}
// else if (this.componentName === SVG_ELLIPSE_TYPE_NAME) {
// SVGEllipse({ ctx: this.ctx, tag: this.tag })
Expand Down Expand Up @@ -113,6 +116,8 @@ export function svgComponentFactoryBuilder(ctx: RNOHContext, tag: Tag, component
SVGUse({ ctx: ctx, tag: tag })
} else if (componentName === SVG_CIRCLE_TYPE_NAME) {
SVGCircle({ ctx: ctx, tag: tag })
} else if (componentName === SVG_RADIAL_GRADIENT_TYPE_NAME) {
SVGRadialGradient({ ctx: ctx, tag: tag })
}
// else if (componentName === SVG_ELLIPSE_TYPE_NAME) {
// SVGEllipse({ ctx: ctx, tag: tag })
Expand Down
22 changes: 22 additions & 0 deletions harmony/svg/src/main/ets/components/SVGRadialGradient.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Descriptor, RNOHContext, Tag ,RNViewBase} from "rnoh";
export const SVG_RADIAL_GRADIENT_TYPE_NAME = "RNSVGRadialGradient";

export type SVGRadialGradientDescriptor = Descriptor<"RNSVGRadialGradient">;


@Component
export struct SVGRadialGradient {
ctx!: RNOHContext;
tag: number = 0;
@State descriptor: SVGRadialGradientDescriptor = {} as SVGRadialGradientDescriptor;

aboutToAppear(): void {
this.descriptor = this.ctx.descriptorRegistry.getDescriptor<SVGRadialGradientDescriptor>(this.tag);
}

build() {
RNViewBase({ ctx: this.ctx, tag: this.tag }) {
// 空白占位
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "13.14.0-0.2.2",
"version": "13.14.0-0.2.3",
"name": "@react-native-oh-tpl/react-native-svg",
"description": "SVG library for react-native",
"homepage": "https://github.com/react-native-community/react-native-svg",
Expand Down

0 comments on commit f2e3f22

Please sign in to comment.