10
10
11
11
'use strict' ;
12
12
13
- const ColorPropType = require ( 'ColorPropType' ) ;
14
13
const Platform = require ( 'Platform' ) ;
15
14
const React = require ( 'React' ) ;
16
- const PropTypes = require ( 'prop-types' ) ;
17
15
const StyleSheet = require ( 'StyleSheet' ) ;
18
16
const Text = require ( 'Text' ) ;
19
17
const TouchableNativeFeedback = require ( 'TouchableNativeFeedback' ) ;
@@ -22,6 +20,45 @@ const View = require('View');
22
20
23
21
const invariant = require ( 'fbjs/lib/invariant' ) ;
24
22
23
+ import type { PressEvent } from 'CoreEventTypes' ;
24
+
25
+ type ButtonProps = $ReadOnly < { |
26
+ /**
27
+ * Text to display inside the button
28
+ */
29
+ title : string ,
30
+
31
+ /**
32
+ * Handler to be called when the user taps the button
33
+ */
34
+ onPress : ( event ? : PressEvent ) = > mixed ,
35
+
36
+ /**
37
+ * Color of the text (iOS), or background color of the button (Android)
38
+ */
39
+ color ?: ?string ,
40
+
41
+ /**
42
+ * TV preferred focus (see documentation for the View component).
43
+ */
44
+ hasTVPreferredFocus ?: ?boolean ,
45
+
46
+ /**
47
+ * Text to display for blindness accessibility features
48
+ */
49
+ accessibilityLabel ?: ?string ,
50
+
51
+ /**
52
+ * If true, disable all interactions for this component.
53
+ */
54
+ disabled ?: ?boolean ,
55
+
56
+ /**
57
+ * Used to locate this view in end-to-end tests.
58
+ */
59
+ testID ?: ?string ,
60
+ | } > ;
61
+
25
62
/**
26
63
* A basic button component that should render nicely on any platform. Supports
27
64
* a minimal level of customization.
@@ -50,46 +87,7 @@ const invariant = require('fbjs/lib/invariant');
50
87
*
51
88
*/
52
89
53
- class Button extends React . Component < {
54
- title : string ,
55
- onPress : ( ) => any ,
56
- color ?: ?string ,
57
- hasTVPreferredFocus ?: ?boolean ,
58
- accessibilityLabel ?: ?string ,
59
- disabled ?: ?boolean ,
60
- testID ?: ?string ,
61
- } > {
62
- static propTypes = {
63
- /**
64
- * Text to display inside the button
65
- */
66
- title : PropTypes . string . isRequired ,
67
- /**
68
- * Text to display for blindness accessibility features
69
- */
70
- accessibilityLabel : PropTypes . string ,
71
- /**
72
- * Color of the text (iOS), or background color of the button (Android)
73
- */
74
- color : ColorPropType ,
75
- /**
76
- * If true, disable all interactions for this component.
77
- */
78
- disabled : PropTypes . bool ,
79
- /**
80
- * TV preferred focus (see documentation for the View component).
81
- */
82
- hasTVPreferredFocus : PropTypes . bool ,
83
- /**
84
- * Handler to be called when the user taps the button
85
- */
86
- onPress : PropTypes . func . isRequired ,
87
- /**
88
- * Used to locate this view in end-to-end tests.
89
- */
90
- testID : PropTypes . string ,
91
- } ;
92
-
90
+ class Button extends React . Component < ButtonProps > {
93
91
render ( ) {
94
92
const {
95
93
accessibilityLabel,
@@ -152,26 +150,28 @@ const styles = StyleSheet.create({
152
150
borderRadius : 2 ,
153
151
} ,
154
152
} ) ,
155
- text : Platform . select ( {
156
- ios : {
157
- // iOS blue from https://developer.apple.com/ios/human-interface-guidelines/visual-design/color/
158
- color : '#007AFF' ,
159
- textAlign : 'center' ,
160
- padding : 8 ,
161
- fontSize : 18 ,
162
- } ,
163
- android : {
164
- color : 'white' ,
165
- textAlign : 'center' ,
166
- padding : 8 ,
167
- fontWeight : '500' ,
153
+ text : {
154
+ ...Platform . select ( {
155
+ ios : {
156
+ // iOS blue from https://developer.apple.com/ios/human-interface-guidelines/visual-design/color/
157
+ color : '#007AFF' ,
158
+ textAlign : 'center' ,
159
+ padding : 8 ,
160
+ fontSize : 18 ,
161
+ } ,
162
+ android : {
163
+ color : 'white' ,
164
+ textAlign : 'center' ,
165
+ padding : 8 ,
166
+ fontWeight : '500' ,
167
+ } ,
168
+ desktop : {
169
+ color : '#007AFF' ,
170
+ textAlign : 'center' ,
171
+ fontSize : 14 ,
168
172
} ,
169
- desktop : {
170
- color : '#007AFF' ,
171
- textAlign : 'center' ,
172
- fontSize : 14 ,
173
- } ,
174
- } ) ,
173
+ } ) ,
174
+ } ,
175
175
buttonDisabled : Platform . select ( {
176
176
ios : { } ,
177
177
android : {
0 commit comments