Skip to content

Commit a187e9b

Browse files
rigderncpojer
authored andcommitted
React Native: Allow Views to be nested inside of Text (#15464)
This feature is now supported on both iOS and Android. The Android feature was merged a couple of weeks ago: facebook/react-native#23195.
1 parent f85aade commit a187e9b

File tree

4 files changed

+14
-29
lines changed

4 files changed

+14
-29
lines changed

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,6 @@ export function createInstance(
191191
}
192192
}
193193

194-
invariant(
195-
type !== 'RCTView' || !hostContext.isInAParentText,
196-
'Nesting of <View> within <Text> is not currently supported.',
197-
);
198-
199194
const updatePayload = create(props, viewConfig.validAttributes);
200195

201196
const node = createNode(

packages/react-native-renderer/src/ReactNativeHostConfig.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ export function createInstance(
102102
}
103103
}
104104

105-
invariant(
106-
type !== 'RCTView' || !hostContext.isInAParentText,
107-
'Nesting of <View> within <Text> is not currently supported.',
108-
);
109-
110105
const updatePayload = create(props, viewConfig.validAttributes);
111106

112107
UIManager.createView(

packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ describe('ReactFabric', () => {
610610
expect(snapshots).toMatchSnapshot();
611611
});
612612

613-
it('should throw when <View> is used inside of a <Text> ancestor', () => {
613+
it('should not throw when <View> is used inside of a <Text> ancestor', () => {
614614
const Image = createReactNativeComponentClass('RCTImage', () => ({
615615
validAttributes: {},
616616
uiViewClassName: 'RCTImage',
@@ -624,16 +624,13 @@ describe('ReactFabric', () => {
624624
uiViewClassName: 'RCTView',
625625
}));
626626

627-
expect(() =>
628-
ReactFabric.render(
629-
<Text>
630-
<View />
631-
</Text>,
632-
11,
633-
),
634-
).toThrow('Nesting of <View> within <Text> is not currently supported.');
627+
ReactFabric.render(
628+
<Text>
629+
<View />
630+
</Text>,
631+
11,
632+
);
635633

636-
// Non-View things (e.g. Image) are fine
637634
ReactFabric.render(
638635
<Text>
639636
<Image />

packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ describe('ReactNative', () => {
486486
expect(mockArgs.length).toEqual(0);
487487
});
488488

489-
it('should throw when <View> is used inside of a <Text> ancestor', () => {
489+
it('should not throw when <View> is used inside of a <Text> ancestor', () => {
490490
const Image = createReactNativeComponentClass('RCTImage', () => ({
491491
validAttributes: {},
492492
uiViewClassName: 'RCTImage',
@@ -500,14 +500,12 @@ describe('ReactNative', () => {
500500
uiViewClassName: 'RCTView',
501501
}));
502502

503-
expect(() =>
504-
ReactNative.render(
505-
<Text>
506-
<View />
507-
</Text>,
508-
11,
509-
),
510-
).toThrow('Nesting of <View> within <Text> is not currently supported.');
503+
ReactNative.render(
504+
<Text>
505+
<View />
506+
</Text>,
507+
11,
508+
);
511509

512510
// Non-View things (e.g. Image) are fine
513511
ReactNative.render(

0 commit comments

Comments
 (0)