mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
Add disabled prop
Summary: Implemented feature requested in https://github.com/facebook/react-native/issues/10354, updated docs. The colours were picked from native interface for iOS and from material-ui for android. Closes https://github.com/facebook/react-native/pull/10398 Differential Revision: D4026189 Pulled By: ericvicenti fbshipit-source-id: f3316e76f5a4126c07ffcdfb134cd902f40624d5
This commit is contained in:
parent
efcdef711e
commit
c32ab7e608
@ -93,4 +93,18 @@ exports.examples = [
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'Disabled Button',
|
||||||
|
description: 'All interactions for the component are disabled.',
|
||||||
|
render: function() {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
disabled
|
||||||
|
onPress={onButtonPress}
|
||||||
|
title="I Am Disabled"
|
||||||
|
accessibilityLabel="See an informative alert"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
@ -54,6 +54,7 @@ class Button extends React.Component {
|
|||||||
onPress: () => any,
|
onPress: () => any,
|
||||||
color?: ?string,
|
color?: ?string,
|
||||||
accessibilityLabel?: ?string,
|
accessibilityLabel?: ?string,
|
||||||
|
disabled?: ?boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@ -69,6 +70,10 @@ class Button extends React.Component {
|
|||||||
* Color of the text (iOS), or background color of the button (Android)
|
* Color of the text (iOS), or background color of the button (Android)
|
||||||
*/
|
*/
|
||||||
color: ColorPropType,
|
color: ColorPropType,
|
||||||
|
/**
|
||||||
|
* If true, disable all interactions for this component.
|
||||||
|
*/
|
||||||
|
disabled: React.PropTypes.bool,
|
||||||
/**
|
/**
|
||||||
* Handler to be called when the user taps the button
|
* Handler to be called when the user taps the button
|
||||||
*/
|
*/
|
||||||
@ -81,6 +86,7 @@ class Button extends React.Component {
|
|||||||
color,
|
color,
|
||||||
onPress,
|
onPress,
|
||||||
title,
|
title,
|
||||||
|
disabled,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const buttonStyles = [styles.button];
|
const buttonStyles = [styles.button];
|
||||||
const textStyles = [styles.text];
|
const textStyles = [styles.text];
|
||||||
@ -90,6 +96,10 @@ class Button extends React.Component {
|
|||||||
} else if (color) {
|
} else if (color) {
|
||||||
buttonStyles.push({backgroundColor: color});
|
buttonStyles.push({backgroundColor: color});
|
||||||
}
|
}
|
||||||
|
if (disabled) {
|
||||||
|
buttonStyles.push(styles.buttonDisabled);
|
||||||
|
textStyles.push(styles.textDisabled);
|
||||||
|
}
|
||||||
invariant(
|
invariant(
|
||||||
typeof title === 'string',
|
typeof title === 'string',
|
||||||
'The title prop of a Button must be a string',
|
'The title prop of a Button must be a string',
|
||||||
@ -100,6 +110,7 @@ class Button extends React.Component {
|
|||||||
accessibilityComponentType="button"
|
accessibilityComponentType="button"
|
||||||
accessibilityLabel={accessibilityLabel}
|
accessibilityLabel={accessibilityLabel}
|
||||||
accessibilityTraits={['button']}
|
accessibilityTraits={['button']}
|
||||||
|
disabled={disabled}
|
||||||
onPress={onPress}>
|
onPress={onPress}>
|
||||||
<View style={buttonStyles}>
|
<View style={buttonStyles}>
|
||||||
<Text style={textStyles}>{formattedTitle}</Text>
|
<Text style={textStyles}>{formattedTitle}</Text>
|
||||||
@ -139,6 +150,21 @@ const styles = StyleSheet.create({
|
|||||||
fontWeight: '500',
|
fontWeight: '500',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
buttonDisabled: Platform.select({
|
||||||
|
ios: {},
|
||||||
|
android: {
|
||||||
|
elevation: 0,
|
||||||
|
backgroundColor: '#dfdfdf',
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
textDisabled: Platform.select({
|
||||||
|
ios: {
|
||||||
|
color: '#cdcdcd',
|
||||||
|
},
|
||||||
|
android: {
|
||||||
|
color: '#a1a1a1',
|
||||||
|
}
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = Button;
|
module.exports = Button;
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 251 KiB After Width: | Height: | Size: 330 KiB |
Loading…
x
Reference in New Issue
Block a user