mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 20:01:01 +08:00
fix forwardRef displayName on Text and View
Reviewed By: TheSavior Differential Revision: D8342852 fbshipit-source-id: 5af80edfd5de5b6d6ea6fdc24abf8931f767c812
This commit is contained in:
committed by
Facebook Github Bot
parent
d0219a0301
commit
ddf2c2ffd6
@@ -32,19 +32,24 @@ const RCTView = requireNativeComponent('RCTView');
|
||||
|
||||
let ViewToExport = RCTView;
|
||||
if (__DEV__) {
|
||||
const View = (props: Props, forwardedRef: ?React.Ref<'RCTView'>) => {
|
||||
return (
|
||||
<TextAncestor.Consumer>
|
||||
{hasTextAncestor => {
|
||||
invariant(
|
||||
!hasTextAncestor,
|
||||
'Nesting of <View> within <Text> is not currently supported.',
|
||||
);
|
||||
return <RCTView {...props} ref={forwardedRef} />;
|
||||
}}
|
||||
</TextAncestor.Consumer>
|
||||
);
|
||||
};
|
||||
View.displayName = 'View'; // TODO(T30332650) remove bug workaround
|
||||
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
|
||||
ViewToExport = React.forwardRef((props, ref) => (
|
||||
<TextAncestor.Consumer>
|
||||
{hasTextAncestor => {
|
||||
invariant(
|
||||
!hasTextAncestor,
|
||||
'Nesting of <View> within <Text> is not currently supported.',
|
||||
);
|
||||
return <RCTView {...props} ref={ref} />;
|
||||
}}
|
||||
</TextAncestor.Consumer>
|
||||
));
|
||||
ViewToExport.displayName = 'View';
|
||||
ViewToExport = React.forwardRef(View);
|
||||
}
|
||||
|
||||
module.exports = ((ViewToExport: any): Class<NativeComponent<ViewProps>>);
|
||||
module.exports = ((ViewToExport: $FlowFixMe): Class<
|
||||
NativeComponent<ViewProps>,
|
||||
>);
|
||||
|
||||
Reference in New Issue
Block a user