Skip to content

Commit b810501

Browse files
author
Brian Vaughn
committed
Added a test for <Text><ScrollingView>foo case
1 parent 4821bf8 commit b810501

File tree

4 files changed

+50
-16
lines changed

4 files changed

+50
-16
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const ReactFabricRenderer = ReactFiberReconciler({
191191
if (__DEV__) {
192192
warning(
193193
hostContext.isInAParentText,
194-
'Text strings must have a <Text> ancestor.',
194+
'Text strings must be rendered within a <Text>.',
195195
);
196196
}
197197

@@ -229,16 +229,16 @@ const ReactFabricRenderer = ReactFiberReconciler({
229229
type: string,
230230
): HostContext {
231231
if (__DEV__) {
232-
if (parentHostContext.isInAParentText) {
233-
return parentHostContext;
234-
} else if (
232+
const prevIsInAParentText = parentHostContext.isInAParentText;
233+
const isInAParentText =
235234
type === 'AndroidTextInput' ||
236235
type === 'RCTMultilineTextInputView' ||
237236
type === 'RCTText' ||
238237
type === 'RCTSinglelineTextInputView' ||
239-
type === 'RCTVirtualText'
240-
) {
241-
return {isInAParentText: true};
238+
type === 'RCTVirtualText';
239+
240+
if (prevIsInAParentText !== isInAParentText) {
241+
return {isInAParentText};
242242
} else {
243243
return parentHostContext;
244244
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const NativeRenderer = ReactFiberReconciler({
126126
if (__DEV__) {
127127
warning(
128128
hostContext.isInAParentText,
129-
'Text strings must have a <Text> ancestor.',
129+
'Text strings must be rendered within a <Text>.',
130130
);
131131
}
132132

@@ -181,16 +181,16 @@ const NativeRenderer = ReactFiberReconciler({
181181
type: string,
182182
): HostContext {
183183
if (__DEV__) {
184-
if (parentHostContext.isInAParentText) {
185-
return parentHostContext;
186-
} else if (
184+
const prevIsInAParentText = parentHostContext.isInAParentText;
185+
const isInAParentText =
187186
type === 'AndroidTextInput' ||
188187
type === 'RCTMultilineTextInputView' ||
189188
type === 'RCTText' ||
190189
type === 'RCTSinglelineTextInputView' ||
191-
type === 'RCTVirtualText'
192-
) {
193-
return {isInAParentText: true};
190+
type === 'RCTVirtualText';
191+
192+
if (prevIsInAParentText !== isInAParentText) {
193+
return {isInAParentText};
194194
} else {
195195
return parentHostContext;
196196
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,31 @@ describe('ReactFabric', () => {
306306
});
307307

308308
it('should warn about text not inside of a <Text> ancestor', () => {
309+
const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({
310+
validAttributes: {},
311+
uiViewClassName: 'RCTScrollView',
312+
}));
313+
const Text = createReactNativeComponentClass('RCTText', () => ({
314+
validAttributes: {},
315+
uiViewClassName: 'RCTText',
316+
}));
309317
const View = createReactNativeComponentClass('RCTView', () => ({
310318
validAttributes: {},
311319
uiViewClassName: 'RCTView',
312320
}));
313321

314322
expect(() =>
315323
ReactFabric.render(<View>this should warn</View>, 11),
316-
).toWarnDev('Text strings must have a <Text> ancestor.');
324+
).toWarnDev('Text strings must be rendered within a <Text>.');
325+
326+
expect(() =>
327+
ReactFabric.render(
328+
<Text>
329+
<ScrollView>hi hello hi</ScrollView>
330+
</Text>,
331+
11,
332+
),
333+
).toWarnDev('Text strings must be rendered within a <Text>.');
317334
});
318335

319336
it('should not warn warn about text inside of an indirect <Text> ancestor', () => {

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,31 @@ describe('ReactNative', () => {
216216
});
217217

218218
it('should warn about text not inside of a <Text> ancestor', () => {
219+
const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({
220+
validAttributes: {},
221+
uiViewClassName: 'RCTScrollView',
222+
}));
223+
const Text = createReactNativeComponentClass('RCTText', () => ({
224+
validAttributes: {},
225+
uiViewClassName: 'RCTText',
226+
}));
219227
const View = createReactNativeComponentClass('RCTView', () => ({
220228
validAttributes: {},
221229
uiViewClassName: 'RCTView',
222230
}));
223231

224232
expect(() =>
225233
ReactNative.render(<View>this should warn</View>, 11),
226-
).toWarnDev('Text strings must have a <Text> ancestor.');
234+
).toWarnDev('Text strings must be rendered within a <Text>.');
235+
236+
expect(() =>
237+
ReactNative.render(
238+
<Text>
239+
<ScrollView>hi hello hi</ScrollView>
240+
</Text>,
241+
11,
242+
),
243+
).toWarnDev('Text strings must be rendered within a <Text>.');
227244
});
228245

229246
it('should not warn warn about text inside of an indirect <Text> ancestor', () => {

0 commit comments

Comments
 (0)