Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TouchableOpacity] Reset opacity to the inactiveValue rather than always 1.0 #977

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Libraries/Components/Touchable/TouchableOpacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

var NativeMethodsMixin = require('NativeMethodsMixin');
var POPAnimationMixin = require('POPAnimationMixin');
var StyleSheetRegistry = require('StyleSheetRegistry');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

var React = require('React');
var Touchable = require('Touchable');
var TouchableWithoutFeedback = require('TouchableWithoutFeedback');
Expand Down Expand Up @@ -105,12 +106,17 @@ var TouchableOpacity = React.createClass({
},

touchableHandleActivePressOut: function() {
this.setOpacityTo(1.0);
var childStyle = this.refs[CHILD_REF].props.style;

if (typeof childStyle === 'number') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to use flattenStyle here. The type of childStyle can be a number, or an object, or an array of number or objects or array... :)

childStyle = StyleSheetRegistry.getStyleByID(childStyle);
}

this.setOpacityTo(childStyle && childStyle.opacity || 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot use || here. Otherwise if opacity is set to 0, it's going to be 1. You need childStyle.opacity === undefined ? 1 : childStyle.opacity

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that falsey 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript ❤️

this.props.onPressOut && this.props.onPressOut();
},

touchableHandlePress: function() {
this.setOpacityTo(1.0);
this.props.onPress && this.props.onPress();
},

Expand Down