From 1bfb0b10f59857fa63db79098bfb0c71c350a418 Mon Sep 17 00:00:00 2001 From: mlanter Date: Tue, 28 Feb 2017 18:56:11 -0800 Subject: [PATCH 1/2] [touchable opacity] Set initial opacity based on style Set the initial opacity based on the style opacity instead of defaulting to 1. --- Libraries/Components/Touchable/TouchableOpacity.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Libraries/Components/Touchable/TouchableOpacity.js b/Libraries/Components/Touchable/TouchableOpacity.js index 8d3e53312ae0f6..f23900a027f5b0 100644 --- a/Libraries/Components/Touchable/TouchableOpacity.js +++ b/Libraries/Components/Touchable/TouchableOpacity.js @@ -77,7 +77,7 @@ var TouchableOpacity = React.createClass({ getInitialState: function() { return { ...this.touchableGetInitialState(), - anim: new Animated.Value(1), + anim: new Animated.Value(this._getChildStyleOpacityWithDefault()), }; }, @@ -156,9 +156,8 @@ var TouchableOpacity = React.createClass({ }, _opacityInactive: function(duration: number) { - var childStyle = flattenStyle(this.props.style) || {}; this.setOpacityTo( - childStyle.opacity === undefined ? 1 : childStyle.opacity, + this._getChildStyleOpacityWithDefault(), duration ); }, @@ -166,6 +165,11 @@ var TouchableOpacity = React.createClass({ _opacityFocused: function() { this.setOpacityTo(this.props.focusedOpacity); }, + + _getChildStyleOpacityWithDefault: function() { + var childStyle = flattenStyle(this.props.style) || {}; + return childStyle.opacity === undefined ? 1 : childStyle.opacity; + }, render: function() { return ( From 1755c66c8f7a7f88b792ce8243437a5433a21d05 Mon Sep 17 00:00:00 2001 From: mlanter Date: Wed, 1 Mar 2017 17:25:33 -0800 Subject: [PATCH 2/2] Change to == undefined --- Libraries/Components/Touchable/TouchableOpacity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Components/Touchable/TouchableOpacity.js b/Libraries/Components/Touchable/TouchableOpacity.js index f23900a027f5b0..40079f44538f00 100644 --- a/Libraries/Components/Touchable/TouchableOpacity.js +++ b/Libraries/Components/Touchable/TouchableOpacity.js @@ -168,7 +168,7 @@ var TouchableOpacity = React.createClass({ _getChildStyleOpacityWithDefault: function() { var childStyle = flattenStyle(this.props.style) || {}; - return childStyle.opacity === undefined ? 1 : childStyle.opacity; + return childStyle.opacity == undefined ? 1 : childStyle.opacity; }, render: function() {