Skip to content

Commit 9a12253

Browse files
Improve
1 parent 6d255b3 commit 9a12253

9 files changed

+117
-87
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "RNSVGNodeBaseShadowNode.h"
9+
10+
#include <react/renderer/core/LayoutConstraints.h>
11+
#include <react/renderer/core/LayoutContext.h>
12+
13+
namespace facebook {
14+
namespace react {
15+
16+
RNSVGNodeBaseShadowNode::RNSVGNodeBaseShadowNode(
17+
const ShadowNodeFragment &fragment,
18+
const ShadowNodeFamily::Shared &family,
19+
ShadowNodeTraits traits)
20+
: LayoutableShadowNode(fragment, family, traits) {}
21+
22+
RNSVGNodeBaseShadowNode::RNSVGNodeBaseShadowNode(
23+
const ShadowNode &sourceShadowNode,
24+
const ShadowNodeFragment &fragment)
25+
: LayoutableShadowNode(sourceShadowNode, fragment) {}
26+
27+
void RNSVGNodeBaseShadowNode::layoutTree(
28+
LayoutContext layoutContext,
29+
LayoutConstraints layoutConstraints) {}
30+
31+
void RNSVGNodeBaseShadowNode::layout(LayoutContext layoutContext) {}
32+
33+
void RNSVGNodeBaseShadowNode::cleanLayout() {}
34+
35+
void RNSVGNodeBaseShadowNode::dirtyLayout() {}
36+
37+
bool RNSVGNodeBaseShadowNode::getIsLayoutClean() const {
38+
return true;
39+
}
40+
41+
} // namespace react
42+
} // namespace facebook
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <react/renderer/core/LayoutableShadowNode.h>
11+
12+
namespace facebook {
13+
namespace react {
14+
15+
/**
16+
* Base shadow node used as base class for all nodes.
17+
*
18+
* Currently Fabric on Android requires shadow nodes to be subclasses of
19+
* LayoutableShadowNode so that it can instantiate views and setup the view
20+
* hierarchy properly. SVG nodes don't need layout so we just implement empty
21+
* methods.
22+
*/
23+
class RNSVGNodeBaseShadowNode : public LayoutableShadowNode {
24+
public:
25+
RNSVGNodeBaseShadowNode(
26+
const ShadowNodeFragment &fragment,
27+
const ShadowNodeFamily::Shared &family,
28+
ShadowNodeTraits traits);
29+
30+
RNSVGNodeBaseShadowNode(
31+
const ShadowNode &sourceShadowNode,
32+
const ShadowNodeFragment &fragment);
33+
34+
virtual void layoutTree(
35+
LayoutContext layoutContext,
36+
LayoutConstraints layoutConstraints);
37+
virtual void layout(LayoutContext layoutContext);
38+
virtual void cleanLayout();
39+
virtual void dirtyLayout();
40+
virtual bool getIsLayoutClean() const;
41+
42+
static ShadowNodeTraits BaseTraits() {
43+
auto traits = LayoutableShadowNode::BaseTraits();
44+
traits.set(ShadowNodeTraits::Trait::FormsStackingContext);
45+
traits.set(ShadowNodeTraits::Trait::FormsView);
46+
return traits;
47+
}
48+
};
49+
50+
} // namespace react
51+
} // namespace facebook

common/cpp/react/renderer/components/rnsvg/RNSVGNodeShadowNode.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

common/cpp/react/renderer/components/rnsvg/RNSVGShadowNodes.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@
99

1010
#include <jsi/jsi.h>
1111
#include <react/renderer/components/rnsvg/Props.h>
12+
#include <react/renderer/components/view/ViewEventEmitter.h>
1213
#include <react/renderer/core/ConcreteShadowNode.h>
1314
#include <react/renderer/core/ShadowNode.h>
1415

15-
#include "RNSVGNodeShadowNode.h"
16+
#include "RNSVGNodeBaseShadowNode.h"
1617

1718
namespace facebook {
1819
namespace react {
1920

20-
JSI_EXPORT extern const char RNSVGCircleComponentName[];
21+
template <ComponentName concreteComponentName, typename PropsT>
22+
using RNSVGNodeShadowNode = ConcreteShadowNode<
23+
concreteComponentName,
24+
RNSVGNodeBaseShadowNode,
25+
PropsT,
26+
ViewEventEmitter>;
27+
28+
extern const char RNSVGCircleComponentName[];
2129

2230
/*
2331
* `ShadowNode` for <RNSVGCircle> component.

common/cpp/react/renderer/components/rnsvg/RNSVGSvgViewAndroidComponentDescriptor.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,8 @@ namespace react {
1717
/*
1818
* Descriptor for <RNSVGSvgViewAndroid> component.
1919
*/
20-
class RNSVGSvgViewAndroidComponentDescriptor final
21-
: public ConcreteComponentDescriptor<RNSVGSvgViewAndroidShadowNode> {
22-
public:
23-
RNSVGSvgViewAndroidComponentDescriptor(
24-
ComponentDescriptorParameters const &parameters)
25-
: ConcreteComponentDescriptor(parameters) {}
26-
27-
void adopt(ShadowNode::Unshared const &shadowNode) const override {
28-
ConcreteComponentDescriptor::adopt(shadowNode);
29-
30-
auto svgViewShadowNode =
31-
std::static_pointer_cast<RNSVGSvgViewAndroidShadowNode>(shadowNode);
32-
33-
// All `RNSVGSvgViewAndroidShadowNode`s must have leaf Yoga nodes with
34-
// properly setup measure function.
35-
svgViewShadowNode->enableMeasurement();
36-
}
37-
};
20+
using RNSVGSvgViewAndroidComponentDescriptor =
21+
ConcreteComponentDescriptor<RNSVGSvgViewAndroidShadowNode>;
3822

3923
} // namespace react
4024
} // namespace facebook

common/cpp/react/renderer/components/rnsvg/RNSVGSvgViewAndroidShadowNode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class JSI_EXPORT RNSVGSvgViewAndroidShadowNode final
3030
static ShadowNodeTraits BaseTraits() {
3131
auto traits = ConcreteViewShadowNode::BaseTraits();
3232
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
33+
traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
3334
return traits;
3435
}
3536

common/cpp/react/renderer/components/rnsvg/RNSVGSvgViewComponentDescriptor.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,8 @@ namespace react {
1717
/*
1818
* Descriptor for <RNSVGSvgView> component.
1919
*/
20-
class RNSVGSvgViewComponentDescriptor final
21-
: public ConcreteComponentDescriptor<RNSVGSvgViewShadowNode> {
22-
public:
23-
RNSVGSvgViewComponentDescriptor(
24-
ComponentDescriptorParameters const &parameters)
25-
: ConcreteComponentDescriptor(parameters) {}
26-
27-
void adopt(ShadowNode::Unshared const &shadowNode) const override {
28-
ConcreteComponentDescriptor::adopt(shadowNode);
29-
30-
auto svgViewShadowNode =
31-
std::static_pointer_cast<RNSVGSvgViewShadowNode>(shadowNode);
32-
33-
// All `RNSVGSvgViewShadowNode`s must have leaf Yoga nodes with
34-
// properly setup measure function.
35-
svgViewShadowNode->enableMeasurement();
36-
}
37-
};
20+
using RNSVGSvgViewComponentDescriptor =
21+
ConcreteComponentDescriptor<RNSVGSvgViewShadowNode>;
3822

3923
} // namespace react
4024
} // namespace facebook

common/cpp/react/renderer/components/rnsvg/RNSVGSvgViewMeasurement.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "RNSVGSvgViewMeasurement.h"
99

10+
#include <algorithm>
11+
1012
namespace facebook {
1113
namespace react {
1214

common/cpp/react/renderer/components/rnsvg/RNSVGSvgViewShadowNode.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class JSI_EXPORT RNSVGSvgViewShadowNode final : public ConcreteViewShadowNode<
2626
public:
2727
using ConcreteViewShadowNode::ConcreteViewShadowNode;
2828

29+
static ShadowNodeTraits BaseTraits() {
30+
auto traits = ConcreteViewShadowNode::BaseTraits();
31+
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
32+
traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
33+
return traits;
34+
}
35+
2936
#pragma mark - LayoutableShadowNode
3037

3138
Size measureContent(

0 commit comments

Comments
 (0)