Skip to content

Commit

Permalink
Introduce disabling for Touchable* elements
Browse files Browse the repository at this point in the history
Summary:Introduce a `disabled` property for Touchable* components.

Fix #2103
Closes #5931

Differential Revision: D2969790

Pulled By: mkonicek

fb-gh-sync-id: 570a4ff882219f52f2d2ebef3eb73b1df50a0877
shipit-source-id: 570a4ff882219f52f2d2ebef3eb73b1df50a0877
  • Loading branch information
Kureev Alexey authored and facebook-github-bot-7 committed Feb 24, 2016
1 parent 9d1abf0 commit 9951e1a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
53 changes: 53 additions & 0 deletions Examples/UIExplorer/TouchableExample.js
Expand Up @@ -100,6 +100,13 @@ exports.examples = [
render: function(): ReactElement {
return <TouchableHitSlop />;
},
}, {
title: 'Disabled Touchable*',
description: '<Touchable*> components accept disabled prop which prevents ' +
'any interaction with component',
render: function(): ReactElement {
return <TouchableDisabled />;
},
}];

var TextOnPressBox = React.createClass({
Expand Down Expand Up @@ -292,6 +299,45 @@ var TouchableHitSlop = React.createClass({
}
});

var TouchableDisabled = React.createClass({
render: function() {
return (
<View>
<TouchableOpacity disabled={true} style={[styles.row, styles.block]}>
<Text style={styles.disabledButton}>Disabled TouchableOpacity</Text>
</TouchableOpacity>

<TouchableOpacity disabled={false} style={[styles.row, styles.block]}>
<Text style={styles.button}>Enabled TouchableOpacity</Text>
</TouchableOpacity>

<TouchableHighlight
activeOpacity={1}
disabled={true}
animationVelocity={0}
underlayColor="rgb(210, 230, 255)"
style={[styles.row, styles.block]}
onPress={() => console.log('custom THW text - hightlight')}>
<Text style={styles.disabledButton}>
Disabled TouchableHighlight
</Text>
</TouchableHighlight>

<TouchableHighlight
activeOpacity={1}
animationVelocity={0}
underlayColor="rgb(210, 230, 255)"
style={[styles.row, styles.block]}
onPress={() => console.log('custom THW text - hightlight')}>
<Text style={styles.button}>
Disabled TouchableHighlight

This comment has been minimized.

Copy link
@swescot

swescot Mar 23, 2016

This should be "Enabled TouchableHighlight", right?

This comment has been minimized.

Copy link
@Kureev

Kureev Mar 23, 2016

Contributor

Sure! Can you make a PR and cc me?

This comment has been minimized.

Copy link
@swescot

swescot Mar 24, 2016

Done!

This comment has been minimized.

Copy link
@Kureev

Kureev Mar 24, 2016

Contributor

Where's a PR, @swescot?

This comment has been minimized.

Copy link
@swescot

swescot Mar 24, 2016

Here: https://github.com/swescot/react-native/pull/1

I haven't used GitHub before so tell med if I've done something wrong :)

This comment has been minimized.

Copy link
@Kureev

Kureev Mar 24, 2016

Contributor

You made a PR to your own fork 😃

You need to compose a PR to the remote master. Probably it'll be interesting for you to read github's official article about PRs.

P.S. There are more chances get a constructive review of your PR if you're following an official github PR template 😉

This comment has been minimized.

Copy link
@swescot

swescot Mar 24, 2016

Thanks man, I'll look into it :)

</Text>
</TouchableHighlight>
</View>
);
}
});

var heartImage = {uri: 'https://pbs.twimg.com/media/BlXBfT3CQAA6cVZ.png:small'};

var styles = StyleSheet.create({
Expand All @@ -310,9 +356,16 @@ var styles = StyleSheet.create({
text: {
fontSize: 16,
},
block: {
padding: 10,
},
button: {
color: '#007AFF',
},
disabledButton: {
color: '#007AFF',
opacity: 0.5,
},
hitSlopButton: {
color: 'white',
},
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Components/Touchable/Touchable.js
Expand Up @@ -337,7 +337,7 @@ var TouchableMixin = {
* Must return true to start the process of `Touchable`.
*/
touchableHandleStartShouldSetResponder: function() {
return true;
return !this.props.disabled;
},

/**
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Expand Up @@ -44,6 +44,10 @@ var TouchableWithoutFeedback = React.createClass({
React.PropTypes.oneOf(View.AccessibilityTraits),
React.PropTypes.arrayOf(React.PropTypes.oneOf(View.AccessibilityTraits)),
]),
/**
* If true, disable all interactions for this component.
*/
disabled: React.PropTypes.bool,
/**
* Called when the touch is released, but not if cancelled (e.g. by a scroll
* that steals the responder lock).
Expand Down

0 comments on commit 9951e1a

Please sign in to comment.