Skip to content

Commit

Permalink
React Native: Allow Views to be nested inside of Text (#15464)
Browse files Browse the repository at this point in the history
This feature is now supported on both iOS and Android. The Android feature was merged a couple of weeks ago: facebook/react-native#23195.
  • Loading branch information
rigdern authored and cpojer committed Apr 25, 2019
1 parent f85aade commit a187e9b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
5 changes: 0 additions & 5 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ export function createInstance(
}
}

invariant(
type !== 'RCTView' || !hostContext.isInAParentText,
'Nesting of <View> within <Text> is not currently supported.',
);

const updatePayload = create(props, viewConfig.validAttributes);

const node = createNode(
Expand Down
5 changes: 0 additions & 5 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ export function createInstance(
}
}

invariant(
type !== 'RCTView' || !hostContext.isInAParentText,
'Nesting of <View> within <Text> is not currently supported.',
);

const updatePayload = create(props, viewConfig.validAttributes);

UIManager.createView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ describe('ReactFabric', () => {
expect(snapshots).toMatchSnapshot();
});

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

expect(() =>
ReactFabric.render(
<Text>
<View />
</Text>,
11,
),
).toThrow('Nesting of <View> within <Text> is not currently supported.');
ReactFabric.render(
<Text>
<View />
</Text>,
11,
);

// Non-View things (e.g. Image) are fine
ReactFabric.render(
<Text>
<Image />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ describe('ReactNative', () => {
expect(mockArgs.length).toEqual(0);
});

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

expect(() =>
ReactNative.render(
<Text>
<View />
</Text>,
11,
),
).toThrow('Nesting of <View> within <Text> is not currently supported.');
ReactNative.render(
<Text>
<View />
</Text>,
11,
);

// Non-View things (e.g. Image) are fine
ReactNative.render(
Expand Down

0 comments on commit a187e9b

Please sign in to comment.