11
11
'use strict' ;
12
12
13
13
const React = require ( 'React' ) ;
14
- const ReactNative = require ( 'ReactNative' ) ;
15
14
const ReactNativeViewAttributes = require ( 'ReactNativeViewAttributes' ) ;
16
15
const TextAncestor = require ( 'TextAncestor' ) ;
17
16
const TextPropTypes = require ( 'TextPropTypes' ) ;
@@ -23,6 +22,7 @@ const nullthrows = require('fbjs/lib/nullthrows');
23
22
const processColor = require ( 'processColor' ) ;
24
23
25
24
import type { PressEvent } from 'CoreEventTypes' ;
25
+ import type { NativeComponent } from 'ReactNative' ;
26
26
import type { PressRetentionOffset , TextProps } from 'TextProps' ;
27
27
28
28
type ResponseHandlers = $ReadOnly < { |
@@ -34,7 +34,10 @@ type ResponseHandlers = $ReadOnly<{|
34
34
onResponderTerminationRequest : ( ) = > boolean ,
35
35
| } > ;
36
36
37
- type Props = TextProps ;
37
+ type Props = $ReadOnly < {
38
+ ...TextProps ,
39
+ forwardedRef : ?React . Ref < NativeComponent < TextProps , any >> ,
40
+ } > ;
38
41
39
42
type State = { |
40
43
touchable : { |
@@ -70,9 +73,7 @@ const viewConfig = {
70
73
*
71
74
* See https://facebook.github.io/react-native/docs/text.html
72
75
*/
73
- class Text extends ReactNative . NativeComponent < Props , State > {
74
- static propTypes = TextPropTypes ;
75
-
76
+ class TouchableText extends React . Component < Props , State > {
76
77
static defaultProps = {
77
78
accessible : true ,
78
79
allowFontScaling : true ,
@@ -138,10 +139,10 @@ class Text extends ReactNative.NativeComponent<Props, State> {
138
139
< TextAncestor . Consumer >
139
140
{ hasTextAncestor =>
140
141
hasTextAncestor ? (
141
- < RCTVirtualText { ...props } />
142
+ < RCTVirtualText { ...props } ref = { props . forwardedRef } />
142
143
) : (
143
144
< TextAncestor . Provider value = { true } >
144
- < RCTText { ...props } />
145
+ < RCTText { ...props } ref = { props . forwardedRef } />
145
146
</ TextAncestor . Provider >
146
147
)
147
148
}
@@ -260,4 +261,13 @@ const RCTVirtualText =
260
261
uiViewClassName : 'RCTVirtualText' ,
261
262
} ) ) ;
262
263
263
- module . exports = Text ;
264
+ // $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
265
+ const Text = React . forwardRef ( ( props , ref ) => (
266
+ < TouchableText { ...props } forwardedRef = { ref } />
267
+ ) ) ;
268
+ Text . displayName = 'Text' ;
269
+
270
+ // TODO: Deprecate this.
271
+ Text . propTypes = TextPropTypes ;
272
+
273
+ module . exports = ( ( Text : any ) : NativeComponent < TextProps , any > ) ;
0 commit comments