10
10
*/
11
11
'use strict' ;
12
12
13
- const NativeMethodsMixin = require ( 'NativeMethodsMixin' ) ;
14
13
const React = require ( 'React' ) ;
14
+ const ReactNative = require ( 'ReactNative' ) ;
15
15
const ReactNativeViewAttributes = require ( 'ReactNativeViewAttributes' ) ;
16
16
const TextPropTypes = require ( 'TextPropTypes' ) ;
17
17
const Touchable = require ( 'Touchable' ) ;
18
18
const UIManager = require ( 'UIManager' ) ;
19
19
20
- const createReactClass = require ( 'create-react-class' ) ;
21
20
const createReactNativeComponentClass = require ( 'createReactNativeComponentClass' ) ;
22
21
const mergeFast = require ( 'mergeFast' ) ;
23
22
const processColor = require ( 'processColor' ) ;
24
23
const { ViewContextTypes} = require ( 'ViewContext' ) ;
25
24
25
+ import type { PressEvent } from 'CoreEventTypes' ;
26
+ import type { TextProps } from 'TextProps' ;
27
+ import type { ViewChildContext } from 'ViewContext' ;
28
+
29
+ type State = {
30
+ isHighlighted : boolean ,
31
+ } ;
32
+
33
+ type RectOffset = {
34
+ top : number ,
35
+ left : number ,
36
+ right : number ,
37
+ bottom : number ,
38
+ } ;
39
+
40
+ const PRESS_RECT_OFFSET = { top : 20 , left : 20 , right : 20 , bottom : 30 } ;
41
+
26
42
const viewConfig = {
27
43
validAttributes : mergeFast ( ReactNativeViewAttributes . UIView , {
28
44
isHighlighted : true ,
@@ -39,54 +55,54 @@ const viewConfig = {
39
55
uiViewClassName : 'RCTText' ,
40
56
} ;
41
57
42
- import type { ViewChildContext } from 'ViewContext' ;
43
-
44
58
/**
45
59
* A React component for displaying text.
46
60
*
47
61
* See https://facebook.github.io/react-native/docs/text.html
48
62
*/
63
+ class Text extends ReactNative . NativeComponent < TextProps , State > {
64
+ static propTypes = TextPropTypes ;
65
+ static childContextTypes = ViewContextTypes ;
66
+ static contextTypes = ViewContextTypes ;
67
+
68
+ static defaultProps = {
69
+ accessible : true ,
70
+ allowFontScaling : true ,
71
+ ellipsizeMode : 'tail' ,
72
+ } ;
73
+
74
+ state = mergeFast ( Touchable . Mixin . touchableGetInitialState ( ) , {
75
+ isHighlighted : false ,
76
+ } ) ;
77
+
78
+ viewConfig = viewConfig ;
49
79
50
- const Text = createReactClass ( {
51
- displayName : 'Text' ,
52
- propTypes : TextPropTypes ,
53
- getDefaultProps ( ) : Object {
54
- return {
55
- accessible : true ,
56
- allowFontScaling : true ,
57
- ellipsizeMode : 'tail' ,
58
- } ;
59
- } ,
60
- getInitialState : function ( ) : Object {
61
- return mergeFast ( Touchable . Mixin . touchableGetInitialState ( ) , {
62
- isHighlighted : false ,
63
- } ) ;
64
- } ,
65
- mixins : [ NativeMethodsMixin ] ,
66
- viewConfig : viewConfig ,
67
80
getChildContext ( ) : ViewChildContext {
68
81
return {
69
82
isInAParentText : true ,
70
83
} ;
71
- } ,
72
- childContextTypes : ViewContextTypes ,
73
- contextTypes : ViewContextTypes ,
74
- /**
75
- * Only assigned if touch is needed.
76
- */
77
- _handlers : ( null : ?Object ) ,
84
+ }
85
+
86
+ _handlers : ?Object ;
87
+
78
88
_hasPressHandler ( ) : boolean {
79
89
return ! ! this . props . onPress || ! ! this . props . onLongPress ;
80
- } ,
90
+ }
81
91
/**
82
92
* These are assigned lazily the first time the responder is set to make plain
83
93
* text nodes as cheap as possible.
84
94
*/
85
- touchableHandleActivePressIn : ( null : ?Function ) ,
86
- touchableHandleActivePressOut : ( null : ?Function ) ,
87
- touchableHandlePress : ( null : ?Function ) ,
88
- touchableHandleLongPress : ( null : ?Function ) ,
89
- touchableGetPressRectOffset : ( null : ?Function ) ,
95
+ touchableHandleActivePressIn : ?Function ;
96
+ touchableHandleActivePressOut : ?Function ;
97
+ touchableHandlePress : ?Function ;
98
+ touchableHandleLongPress : ?Function ;
99
+ touchableHandleResponderGrant : ?Function ;
100
+ touchableHandleResponderMove : ?Function ;
101
+ touchableHandleResponderRelease : ?Function ;
102
+ touchableHandleResponderTerminate : ?Function ;
103
+ touchableHandleResponderTerminationRequest : ?Function ;
104
+ touchableGetPressRectOffset : ?Function ;
105
+
90
106
render ( ) : React . Element < any > {
91
107
let newProps = this . props ;
92
108
if ( this . props . onStartShouldSetResponder || this . _hasPressHandler ( ) ) {
@@ -95,7 +111,6 @@ const Text = createReactClass({
95
111
onStartShouldSetResponder : ( ) : boolean => {
96
112
const shouldSetFromProps =
97
113
this . props . onStartShouldSetResponder &&
98
- // $FlowFixMe(>=0.41.0)
99
114
this . props . onStartShouldSetResponder ( ) ;
100
115
const setResponder = shouldSetFromProps || this . _hasPressHandler ( ) ;
101
116
if ( setResponder && ! this . touchableHandleActivePressIn ) {
@@ -130,11 +145,11 @@ const Text = createReactClass({
130
145
} ) ;
131
146
} ;
132
147
133
- this . touchableHandlePress = ( e : SyntheticEvent < > ) => {
148
+ this . touchableHandlePress = ( e : PressEvent ) => {
134
149
this . props . onPress && this . props . onPress ( e ) ;
135
150
} ;
136
151
137
- this . touchableHandleLongPress = ( e : SyntheticEvent < > ) => {
152
+ this . touchableHandleLongPress = ( e : PressEvent ) => {
138
153
this . props . onLongPress && this . props . onLongPress ( e ) ;
139
154
} ;
140
155
@@ -145,28 +160,33 @@ const Text = createReactClass({
145
160
return setResponder ;
146
161
} ,
147
162
onResponderGrant : function ( e : SyntheticEvent < > , dispatchID : string ) {
163
+ // $FlowFixMe TouchableMixin handlers couldn't actually be null
148
164
this . touchableHandleResponderGrant ( e , dispatchID ) ;
149
165
this . props . onResponderGrant &&
150
166
this . props . onResponderGrant . apply ( this , arguments ) ;
151
167
} . bind ( this ) ,
152
168
onResponderMove : function ( e : SyntheticEvent < > ) {
169
+ // $FlowFixMe TouchableMixin handlers couldn't actually be null
153
170
this. touchableHandleResponderMove ( e ) ;
154
171
this . props . onResponderMove &&
155
172
this . props . onResponderMove . apply ( this , arguments ) ;
156
173
} . bind ( this ) ,
157
174
onResponderRelease : function ( e : SyntheticEvent < > ) {
175
+ // $FlowFixMe TouchableMixin handlers couldn't actually be null
158
176
this . touchableHandleResponderRelease ( e ) ;
159
177
this . props . onResponderRelease &&
160
178
this . props . onResponderRelease . apply ( this , arguments ) ;
161
179
} . bind ( this ) ,
162
180
onResponderTerminate : function ( e : SyntheticEvent < > ) {
181
+ // $FlowFixMe TouchableMixin handlers couldn't actually be null
163
182
this. touchableHandleResponderTerminate ( e ) ;
164
183
this . props . onResponderTerminate &&
165
184
this . props . onResponderTerminate . apply ( this , arguments ) ;
166
185
} . bind ( this ) ,
167
186
onResponderTerminationRequest : function ( ) : boolean {
168
187
// Allow touchable or props.onResponderTerminationRequest to deny
169
188
// the request
189
+ // $FlowFixMe TouchableMixin handlers couldn't actually be null
170
190
var allowTermination = this . touchableHandleResponderTerminationRequest ( ) ;
171
191
if ( allowTermination && this . props . onResponderTerminationRequest ) {
172
192
allowTermination = this . props . onResponderTerminationRequest . apply (
@@ -201,17 +221,8 @@ const Text = createReactClass({
201
221
} else {
202
222
return < RCTText { ...newProps } /> ;
203
223
}
204
- } ,
205
- } ) ;
206
-
207
- type RectOffset = {
208
- top : number ,
209
- left : number ,
210
- right : number ,
211
- bottom : number ,
212
- } ;
213
-
214
- var PRESS_RECT_OFFSET = { top : 20 , left : 20 , right : 20 , bottom : 30 } ;
224
+ }
225
+ }
215
226
216
227
var RCTText = createReactNativeComponentClass (
217
228
viewConfig . uiViewClassName ,
0 commit comments