10
10
11
11
'use strict' ;
12
12
13
+ import { NativeText , NativeVirtualText } from './TextNativeComponent' ;
14
+
13
15
const DeprecatedTextPropTypes = require ( '../DeprecatedPropTypes/DeprecatedTextPropTypes' ) ;
14
16
const React = require ( 'react' ) ;
15
- const ReactNativeViewAttributes = require ( '../Components/View/ReactNativeViewAttributes' ) ;
16
17
const TextAncestor = require ( './TextAncestor' ) ;
17
18
const Touchable = require ( '../Components/Touchable/Touchable' ) ;
18
- const UIManager = require ( '../ReactNative/UIManager' ) ;
19
19
20
- const createReactNativeComponentClass = require ( '../Renderer/shims/createReactNativeComponentClass' ) ;
21
20
const nullthrows = require ( 'nullthrows' ) ;
22
21
const processColor = require ( '../StyleSheet/processColor' ) ;
23
22
@@ -27,7 +26,7 @@ import type {PressRetentionOffset, TextProps} from './TextProps';
27
26
28
27
type ResponseHandlers = $ReadOnly < { |
29
28
onStartShouldSetResponder : ( ) => boolean ,
30
- onResponderGrant : ( event : PressEvent , dispatchID : string ) => void ,
29
+ onResponderGrant : ( event : PressEvent ) => void ,
31
30
onResponderMove : ( event : PressEvent ) => void ,
32
31
onResponderRelease : ( event : PressEvent ) => void ,
33
32
onResponderTerminate : ( event : PressEvent ) => void ,
@@ -36,7 +35,7 @@ type ResponseHandlers = $ReadOnly<{|
36
35
37
36
type Props = $ReadOnly < { |
38
37
...TextProps ,
39
- forwardedRef : ?React . Ref < 'RCTText' | 'RCTVirtualText' > ,
38
+ forwardedRef : ?React . Ref < typeof NativeText | typeof NativeVirtualText > ,
40
39
| } > ;
41
40
42
41
type State = { |
@@ -51,36 +50,6 @@ type State = {|
51
50
52
51
const PRESS_RECT_OFFSET = { top : 20 , left : 20 , right : 20 , bottom : 30 } ;
53
52
54
- const viewConfig = {
55
- validAttributes : {
56
- ...ReactNativeViewAttributes . UIView ,
57
- isHighlighted : true ,
58
- numberOfLines : true ,
59
- ellipsizeMode : true ,
60
- allowFontScaling : true ,
61
- maxFontSizeMultiplier : true ,
62
- disabled : true ,
63
- selectable : true ,
64
- selectionColor : true ,
65
- adjustsFontSizeToFit : true ,
66
- minimumFontScale : true ,
67
- textBreakStrategy : true ,
68
- onTextLayout : true ,
69
- onInlineViewLayout : true ,
70
- dataDetectorType : true ,
71
- android_hyphenationFrequency : true ,
72
- } ,
73
- directEventTypes : {
74
- topTextLayout : {
75
- registrationName : 'onTextLayout' ,
76
- } ,
77
- topInlineViewLayout : {
78
- registrationName : 'onInlineViewLayout' ,
79
- } ,
80
- } ,
81
- uiViewClassName : 'RCTText' ,
82
- } ;
83
-
84
53
/**
85
54
* A React component for displaying text.
86
55
*
@@ -122,21 +91,19 @@ class TouchableText extends React.Component<Props, State> {
122
91
: null ;
123
92
}
124
93
125
- static viewConfig = viewConfig ;
126
-
127
94
render ( ) : React . Node {
128
- let props = this . props ;
129
- if ( isTouchable ( props ) ) {
95
+ let { forwardedRef , selectionColor , ... props } = this . props ;
96
+ if ( isTouchable ( this . props ) ) {
130
97
props = {
131
98
...props ,
132
99
...this . state . responseHandlers ,
133
100
isHighlighted : this . state . isHighlighted ,
134
101
} ;
135
102
}
136
- if ( props . selectionColor != null ) {
103
+ if ( selectionColor != null ) {
137
104
props = {
138
105
...props ,
139
- selectionColor : processColor ( props . selectionColor ) ,
106
+ selectionColor : processColor ( selectionColor ) ,
140
107
} ;
141
108
}
142
109
if ( __DEV__ ) {
@@ -151,16 +118,17 @@ class TouchableText extends React.Component<Props, State> {
151
118
< TextAncestor . Consumer >
152
119
{ hasTextAncestor =>
153
120
hasTextAncestor ? (
154
- < RCTVirtualText
121
+ // $FlowFixMe[prop-missing] For the `onClick` workaround.
122
+ < NativeVirtualText
155
123
{ ...props }
156
124
// This is used on Android to call a nested Text component's press handler from the context menu.
157
125
// TODO T75145059 Clean this up once Text is migrated off of Touchable
158
126
onClick = { props . onPress }
159
- ref = { props . forwardedRef }
127
+ ref = { forwardedRef }
160
128
/>
161
129
) : (
162
130
< TextAncestor . Provider value = { true } >
163
- < RCTText { ...props } ref = { props . forwardedRef } />
131
+ < NativeText { ...props } ref = { forwardedRef } />
164
132
</ TextAncestor . Provider >
165
133
)
166
134
}
@@ -263,26 +231,9 @@ const isTouchable = (props: Props): boolean =>
263
231
props . onLongPress != null ||
264
232
props . onStartShouldSetResponder != null ;
265
233
266
- const RCTText = createReactNativeComponentClass (
267
- viewConfig . uiViewClassName ,
268
- ( ) => viewConfig ,
269
- ) ;
270
-
271
- const RCTVirtualText =
272
- UIManager . getViewManagerConfig ( 'RCTVirtualText' ) == null
273
- ? RCTText
274
- : createReactNativeComponentClass ( 'RCTVirtualText' , ( ) => ( {
275
- validAttributes : {
276
- ...ReactNativeViewAttributes . UIView ,
277
- isHighlighted : true ,
278
- maxFontSizeMultiplier : true ,
279
- } ,
280
- uiViewClassName : 'RCTVirtualText' ,
281
- } ) ) ;
282
-
283
234
const Text = (
284
235
props : TextProps ,
285
- forwardedRef : ?React . Ref < 'RCTText' | 'RCTVirtualText' > ,
236
+ forwardedRef : ?React . Ref < typeof NativeText | typeof NativeVirtualText > ,
286
237
) => {
287
238
return < TouchableText { ...props } forwardedRef = { forwardedRef } /> ;
288
239
} ;
0 commit comments