forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathButtonExample.js
More file actions
163 lines (156 loc) · 4.59 KB
/
ButtonExample.js
File metadata and controls
163 lines (156 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/
'use strict';
const React = require('react');
const {Alert, Button, View, StyleSheet} = require('react-native');
function onButtonPress(buttonName) {
Alert.alert(`Your application has been ${buttonName}!`);
}
exports.displayName = 'ButtonExample';
exports.framework = 'React';
exports.title = 'Button';
exports.description = 'Simple React Native button component.';
exports.examples = [
{
title: 'Button with default styling',
render: function (): React.Node {
return (
<Button
onPress={() => onButtonPress('submitted')}
testID="button_default_styling"
title="Submit Application"
accessibilityLabel="Press to submit your application!"
/>
);
},
},
{
title: 'Button with color="red"',
description: ('Note: On iOS, the color prop controls the color of the text. On ' +
'Android, the color adjusts the background color of the button.': string),
render: function (): React.Node {
return (
<Button
onPress={() => onButtonPress('cancelled')}
testID="cancel_button"
color="red"
title="Cancel Application"
accessibilityLabel="Press to cancel your application!"
/>
);
},
},
{
title: 'Two Buttons with Flexbox layout',
description: ('Two buttons wrapped inside view with justifyContent: spaceBetween,' +
'This layout strategy lets the title define the width of the button': string),
render: function (): React.Node {
return (
<View style={styles.container}>
<Button
onPress={() => onButtonPress('cancelled')}
testID="two_cancel_button"
color="red"
title="Cancel"
accessibilityLabel="Press to cancel your application!"
/>
<Button
onPress={() => onButtonPress('submitted')}
testID="two_submit_button"
color="green"
title="Submit"
accessibilityLabel="Press to submit your application!"
/>
</View>
);
},
},
{
title: 'Three Buttons with Flexbox layout',
render: function (): React.Node {
return (
<View style={styles.container}>
<Button
onPress={() => onButtonPress('cancelled')}
testID="three_cancel_button"
color="red"
title="Cancel"
accessibilityLabel="Press to cancel your application!"
/>
<Button
onPress={() => onButtonPress('saved')}
testID="three_save_button"
title="Save For Later"
accessibilityLabel="Press to save your application!"
/>
<Button
onPress={() => onButtonPress('submitted')}
testID="three_submit_button"
color="green"
title="Submit"
accessibilityLabel="Press to submit your application!"
/>
</View>
);
},
},
{
title: 'Button with disabled={true}',
description:
'By passing disabled={true} all interactions for the button are disabled.',
render: function (): React.Node {
return (
<Button
disabled
onPress={() => onButtonPress('submitted')}
testID="disabled_button"
title="Submit Application"
accessibilityLabel="Press to submit your application!"
/>
);
},
},
{
title: 'Button with accessibilityLabel="label"',
description:
'Note: This prop changes the text that a screen ' +
'reader announces (there are no visual differences).',
render: function (): React.Node {
return (
<Button
onPress={() => onButtonPress('submitted')}
testID="accessibilityLabel_button"
title="Submit Application"
accessibilityLabel="Press to submit your application!"
/>
);
},
},
{
title: 'Button with no onPress',
description:
'Note: This button does not interact on touch. To fix, always remember to pass onPress handler to the button.',
render: function (): React.Node {
return (
<Button
testID="onPress_button"
title="Submit Application"
accessibilityLabel="See an informative alert"
/>
);
},
},
];
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
justifyContent: 'space-between',
},
});