mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Check for negative numberOfLines in TextView
Summary: Negative `numberOfLines` prop is not supported by Android and causes a crash during layout measurement. This change adds a check in JS to catch the error earlier. Changelog: [Internal] Reviewed By: GijsWeterings Differential Revision: D30047103 fbshipit-source-id: 4248a0f573c3b6facd25c7ae6ce007a357a1469b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8408d723ff
commit
a8a85034e1
@@ -18,6 +18,7 @@ import {NativeText, NativeVirtualText} from './TextNativeComponent';
|
||||
import {type TextProps} from './TextProps';
|
||||
import * as React from 'react';
|
||||
import {useContext, useMemo, useState} from 'react';
|
||||
import invariant from 'invariant';
|
||||
|
||||
/**
|
||||
* Text is the fundamental component for displaying text.
|
||||
@@ -148,6 +149,15 @@ const Text: React.AbstractComponent<
|
||||
}
|
||||
}
|
||||
|
||||
const numberOfLines = restProps.numberOfLines;
|
||||
if (numberOfLines != null) {
|
||||
invariant(
|
||||
numberOfLines >= 0,
|
||||
'Number of lines in <Text/> component can not be negative, passed value: %s.',
|
||||
[numberOfLines],
|
||||
);
|
||||
}
|
||||
|
||||
const hasTextAncestor = useContext(TextAncestor);
|
||||
|
||||
return hasTextAncestor ? (
|
||||
|
||||
Reference in New Issue
Block a user