forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonExample.js
More file actions
127 lines (120 loc) · 3.59 KB
/
ButtonExample.js
File metadata and controls
127 lines (120 loc) · 3.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
/**
* 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');
import {RNTesterThemeContext} from '../../components/RNTesterTheme';
function onButtonPress(buttonName) {
Alert.alert(`${buttonName} has been pressed!`);
}
exports.displayName = 'ButtonExample';
exports.framework = 'React';
exports.title = '<Button>';
exports.description = 'Simple React Native button component.';
exports.examples = [
{
title: 'Simple Button',
description: ('The title and onPress handler are required. It is ' +
'recommended to set accessibilityLabel to help make your app usable by ' +
'everyone.': string),
render: function(): React.Node {
return (
<RNTesterThemeContext.Consumer>
{theme => {
return (
<Button
onPress={() => onButtonPress('Simple')}
testID="simple_button"
color={theme.LinkColor}
title="Press Me"
accessibilityLabel="See an informative alert"
/>
);
}}
</RNTesterThemeContext.Consumer>
);
},
},
{
title: 'Adjusted color',
description: ('Adjusts the color in a way that looks standard on each ' +
'platform. 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 (
<RNTesterThemeContext.Consumer>
{theme => {
return (
<Button
onPress={() => onButtonPress('Purple')}
testID="purple_button"
color={theme.SystemPurpleColor}
title="Press Purple"
accessibilityLabel="Learn more about purple"
/>
);
}}
</RNTesterThemeContext.Consumer>
);
},
},
{
title: 'Fit to text layout',
description: ('This layout strategy lets the title define the width of ' +
'the button': string),
render: function(): React.Node {
return (
<RNTesterThemeContext.Consumer>
{theme => {
return (
<View style={styles.container}>
<Button
onPress={() => onButtonPress('Left')}
testID="left_button"
color={theme.LinkColor}
title="This looks great!"
accessibilityLabel="This sounds great!"
/>
<Button
onPress={() => onButtonPress('Right')}
testID="right_button"
color={theme.SystemPurpleColor}
title="Ok!"
accessibilityLabel="Ok, Great!"
/>
</View>
);
}}
</RNTesterThemeContext.Consumer>
);
},
},
{
title: 'Disabled Button',
description: 'All interactions for the component are disabled.',
render: function(): React.Node {
return (
<Button
disabled
onPress={() => onButtonPress('Disabled')}
testID="disabled_button"
title="I Am Disabled"
accessibilityLabel="See an informative alert"
/>
);
},
},
];
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
justifyContent: 'space-between',
},
});