Skip to content

Commit 8b95294

Browse files
authored
fix: make ForeignObject ordinary YogaLayoutableShadowNode (#2833)
# Summary It does the same thing as #2802 without affecting the performance. ## Test Plan I've added a few more examples that works the same as on web.
1 parent 5a3ea6e commit 8b95294

File tree

3 files changed

+85
-9
lines changed

3 files changed

+85
-9
lines changed

apps/common/example/examples/ForeignObject.tsx

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,86 @@ ForeignObjectExample.title = 'ForeignObject with centered Text';
3838

3939
function ForeignObjectWithView() {
4040
return (
41-
<Svg height="300" width="300" style={{backgroundColor: 'lightgray'}}>
42-
<ForeignObject width={300} height={300}>
41+
<Svg
42+
height="300"
43+
width="300"
44+
style={{backgroundColor: 'lightgray'}}
45+
viewBox="0 0 400 400">
46+
<ForeignObject x={50} y={50} width={300} height={300}>
47+
<View style={{width: '100%', height: '100%', backgroundColor: 'blue'}}>
48+
<View
49+
style={{
50+
width: '50%',
51+
height: '50%',
52+
backgroundColor: 'red',
53+
}}
54+
/>
55+
</View>
56+
</ForeignObject>
57+
<ForeignObject x={150} y={150} width={100} height={100}>
4358
<View
44-
style={{width: '100%', height: '100%', backgroundColor: 'blue'}}
45-
/>
59+
style={{width: '100%', height: '100%', backgroundColor: 'red'}}
60+
collapsable={false}>
61+
<View
62+
style={{
63+
width: '50%',
64+
height: '50%',
65+
backgroundColor: 'blue',
66+
}}
67+
/>
68+
</View>
4669
</ForeignObject>
4770
</Svg>
4871
);
4972
}
5073
ForeignObjectWithView.title = 'ForeignObject with full size View';
5174

75+
function ForeignObjectWithBigView() {
76+
return (
77+
<Svg
78+
height="300"
79+
width="300"
80+
style={{backgroundColor: 'lightgray'}}
81+
viewBox="0 0 600 600">
82+
<ForeignObject width={600} height={600}>
83+
<View style={{width: 600, height: 600, backgroundColor: 'blue'}}>
84+
<View
85+
style={{
86+
width: 300,
87+
height: 300,
88+
backgroundColor: 'red',
89+
}}
90+
/>
91+
</View>
92+
</ForeignObject>
93+
</Svg>
94+
);
95+
}
96+
ForeignObjectWithBigView.title = 'ForeignObject with big View';
97+
98+
function ForeignObjectWithFlexView() {
99+
return (
100+
<Svg
101+
height="300"
102+
width="300"
103+
style={{backgroundColor: 'lightgray'}}
104+
viewBox="0 0 600 600">
105+
<ForeignObject width={600} height={600}>
106+
<View
107+
style={{
108+
width: '100%',
109+
height: '100%',
110+
backgroundColor: 'blue',
111+
flexDirection: 'row',
112+
}}>
113+
<View style={{flex: 1 / 2, backgroundColor: 'red'}} />
114+
</View>
115+
</ForeignObject>
116+
</Svg>
117+
);
118+
}
119+
ForeignObjectWithFlexView.title = 'ForeignObject with flex View';
120+
52121
const styles = StyleSheet.create({
53122
iconContainer: {
54123
width: 15,
@@ -75,6 +144,11 @@ const icon = (
75144
</ForeignObject>
76145
</Svg>
77146
);
78-
const samples = [ForeignObjectExample, ForeignObjectWithView];
147+
const samples = [
148+
ForeignObjectExample,
149+
ForeignObjectWithView,
150+
ForeignObjectWithBigView,
151+
ForeignObjectWithFlexView,
152+
];
79153

80154
export {icon, samples};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
namespace facebook::react {
99

10-
template <const char *concreteComponentName, typename PropsT = ViewProps>
10+
template <const char *concreteComponentName, typename PropsT = ViewProps, typename ShadowNode = RNSVGLayoutableShadowNode>
1111
class RNSVGConcreteShadowNode : public ConcreteShadowNode<
1212
concreteComponentName,
13-
RNSVGLayoutableShadowNode,
13+
ShadowNode,
1414
PropsT,
1515
ViewEventEmitter,
1616
StateData> {
1717
public:
1818
using BaseShadowNode = ConcreteShadowNode<
1919
concreteComponentName,
20-
RNSVGLayoutableShadowNode,
20+
ShadowNode,
2121
PropsT,
2222
ViewEventEmitter,
2323
StateData>;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <jsi/jsi.h>
44
#include <react/renderer/components/rnsvg/EventEmitters.h>
55
#include <react/renderer/components/rnsvg/Props.h>
6+
#include <react/renderer/components/view/YogaLayoutableShadowNode.h>
67
#include "RNSVGConcreteShadowNode.h"
78
#include "RNSVGImageState.h"
89

@@ -114,7 +115,8 @@ JSI_EXPORT extern const char RNSVGForeignObjectComponentName[];
114115
*/
115116
using RNSVGForeignObjectShadowNode = RNSVGConcreteShadowNode<
116117
RNSVGForeignObjectComponentName,
117-
RNSVGForeignObjectProps>;
118+
RNSVGForeignObjectProps,
119+
YogaLayoutableShadowNode>;
118120

119121
JSI_EXPORT extern const char RNSVGGroupComponentName[];
120122

0 commit comments

Comments
 (0)