2016-10-11 00:18:42 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-10-11 00:18:42 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-10-11 00:18:42 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2018-08-09 15:32:04 +00:00
|
|
|
* @flow strict-local
|
2016-10-11 00:18:42 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2016-10-11 00:18:42 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
const {Alert, Button, View} = ReactNative;
|
2016-10-11 00:18:42 +00:00
|
|
|
|
2018-07-30 21:25:49 +00:00
|
|
|
function onButtonPress(buttonName) {
|
|
|
|
Alert.alert(`${buttonName} has been pressed!`);
|
|
|
|
}
|
2016-10-11 00:18:42 +00:00
|
|
|
|
|
|
|
exports.displayName = 'ButtonExample';
|
|
|
|
exports.framework = 'React';
|
|
|
|
exports.title = '<Button>';
|
|
|
|
exports.description = 'Simple React Native button component.';
|
|
|
|
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Simple Button',
|
2018-05-11 20:32:37 +00:00
|
|
|
description:
|
|
|
|
'The title and onPress handler are required. It is ' +
|
2016-10-11 00:18:42 +00:00
|
|
|
'recommended to set accessibilityLabel to help make your app usable by ' +
|
|
|
|
'everyone.',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Button
|
2018-07-30 21:25:49 +00:00
|
|
|
onPress={() => onButtonPress('Simple')}
|
2016-10-11 00:18:42 +00:00
|
|
|
title="Press Me"
|
|
|
|
accessibilityLabel="See an informative alert"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Adjusted color',
|
2018-05-11 20:32:37 +00:00
|
|
|
description:
|
|
|
|
'Adjusts the color in a way that looks standard on each ' +
|
2016-10-11 00:18:42 +00:00
|
|
|
'platform. On iOS, the color prop controls the color of the text. On ' +
|
|
|
|
'Android, the color adjusts the background color of the button.',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Button
|
2018-07-30 21:25:49 +00:00
|
|
|
onPress={() => onButtonPress('Purple')}
|
2016-10-11 00:18:42 +00:00
|
|
|
title="Press Purple"
|
|
|
|
color="#841584"
|
|
|
|
accessibilityLabel="Learn more about purple"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Fit to text layout',
|
2018-05-11 20:32:37 +00:00
|
|
|
description:
|
|
|
|
'This layout strategy lets the title define the width of ' + 'the button',
|
2016-10-11 00:18:42 +00:00
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
|
|
|
|
<Button
|
2018-07-30 21:25:49 +00:00
|
|
|
onPress={() => onButtonPress('Left')}
|
2016-10-11 00:18:42 +00:00
|
|
|
title="This looks great!"
|
|
|
|
accessibilityLabel="This sounds great!"
|
|
|
|
/>
|
|
|
|
<Button
|
2018-07-30 21:25:49 +00:00
|
|
|
onPress={() => onButtonPress('Right')}
|
2016-10-11 00:18:42 +00:00
|
|
|
title="Ok!"
|
|
|
|
color="#841584"
|
|
|
|
accessibilityLabel="Ok, Great!"
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2016-10-15 02:39:00 +00:00
|
|
|
{
|
|
|
|
title: 'Disabled Button',
|
|
|
|
description: 'All interactions for the component are disabled.',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
disabled
|
2018-07-30 21:25:49 +00:00
|
|
|
onPress={() => onButtonPress('Disabled')}
|
2016-10-15 02:39:00 +00:00
|
|
|
title="I Am Disabled"
|
|
|
|
accessibilityLabel="See an informative alert"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2016-10-11 00:18:42 +00:00
|
|
|
];
|