From 725053acfeba4c7f2a21ac47ae8100588a710476 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Mon, 20 Jul 2015 16:29:40 -0700 Subject: [PATCH] [Animated][BREAKING_CHANGE] Convert to Animated Summary: Because we don't want to integrate Animated inside of the core of React, we can only pass Animated.Value to styles of . TouchableOpacity unfortunately used cloneElement. This means that we should have asked every single call site to replace their children to Animated.View. This isn't great. The other solution is to stop using cloneElement and instead wrap the children inside of an . This has many advantages: - We no longer use cloneElement so we're no longer messing up with elements that are not our own. - Refs are now working correctly for children elements - No longer need to enforce that there's only one child and that this child is a native element The downside is that we're introducing a into the hierarchy. Sadly with CSS there is no way to have a View that doesn't affect layout. What we need to do is to remove the inner and transfer all the styles to the TouchableOpacity. It is annoying but fortunately a pretty mechanical process. I think that having a wrapper is the best solution. I will investigate to see if we can make wrappers on TouchableHighliht and TouchableWithoutFeedback as well. **Upgrade Path:** If the child is a View, move the style of the View to TouchableOpacity and remove the View itself. ``` ... --> ... ``` If the child is an Image or Text, on all the examples at Facebook it worked without any change. But it is a great idea to double check them anyway. --- Examples/UIExplorer/ListViewPagingExample.js | 40 ++++++------ .../Navigator/BreadcrumbNavSample.js | 20 +++--- .../Navigator/NavigationBarSample.js | 22 +++---- .../js/IntegrationTestsApp.js | 12 ++-- Examples/UIExplorer/WebViewExample.js | 24 +++---- .../Components/Touchable/TouchableOpacity.js | 63 ++++++++----------- Libraries/ReactIOS/WarningBox.js | 61 +++++++++--------- 7 files changed, 109 insertions(+), 133 deletions(-) diff --git a/Examples/UIExplorer/ListViewPagingExample.js b/Examples/UIExplorer/ListViewPagingExample.js index ab67c9160..7167f3eea 100644 --- a/Examples/UIExplorer/ListViewPagingExample.js +++ b/Examples/UIExplorer/ListViewPagingExample.js @@ -48,19 +48,19 @@ var Thumb = React.createClass({ }, render: function() { return ( - - - - - - {this.state.dir === 'column' ? - - Oooo, look at this new text! So awesome it may just be crazy. - Let me keep typing here so it wraps at least one line. - : - - } - + + + + + {this.state.dir === 'column' ? + + Oooo, look at this new text! So awesome it may just be crazy. + Let me keep typing here so it wraps at least one line. + : + + } ); } @@ -127,14 +127,12 @@ var ListViewPagingExample = React.createClass({ 1 Like : null; return ( - - - {headerLikeText} - - - Table Header (click me) - - + + {headerLikeText} + + + Table Header (click me) + ); diff --git a/Examples/UIExplorer/Navigator/BreadcrumbNavSample.js b/Examples/UIExplorer/Navigator/BreadcrumbNavSample.js index 5abdcd11f..08b8571ae 100644 --- a/Examples/UIExplorer/Navigator/BreadcrumbNavSample.js +++ b/Examples/UIExplorer/Navigator/BreadcrumbNavSample.js @@ -55,26 +55,24 @@ var BreadcrumbNavSample = React.createClass({ return ( navigator.push(_getRandomRoute())}> - - {route.title} - + {route.title} ); }, iconForRoute: function(route, navigator) { return ( - { - navigator.popToRoute(route); - }}> - - + { navigator.popToRoute(route); }} + style={styles.crumbIconPlaceholder} + /> ); }, separatorForRoute: function(route, navigator) { return ( - - - + ); } }; diff --git a/Examples/UIExplorer/Navigator/NavigationBarSample.js b/Examples/UIExplorer/Navigator/NavigationBarSample.js index 545f76b82..3148ad9c1 100644 --- a/Examples/UIExplorer/Navigator/NavigationBarSample.js +++ b/Examples/UIExplorer/Navigator/NavigationBarSample.js @@ -51,12 +51,11 @@ var NavigationBarRouteMapper = { var previousRoute = navState.routeStack[index - 1]; return ( navigator.pop()}> - - - {previousRoute.title} - - + onPress={() => navigator.pop()} + style={styles.navBarLeftButton}> + + {previousRoute.title} + ); }, @@ -64,12 +63,11 @@ var NavigationBarRouteMapper = { RightButton: function(route, navigator, index, navState) { return ( navigator.push(newRandomRoute())}> - - - Next - - + onPress={() => navigator.push(newRandomRoute())} + style={styles.navBarRightButton}> + + Next + ); }, diff --git a/Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp.js b/Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp.js index 519e333a2..339766b54 100644 --- a/Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp.js +++ b/Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp.js @@ -59,12 +59,12 @@ var IntegrationTestsApp = React.createClass({ {TESTS.map((test) => [ - this.setState({test})}> - - - {test.displayName} - - + this.setState({test})} + style={styles.row}> + + {test.displayName} + , ])} diff --git a/Examples/UIExplorer/WebViewExample.js b/Examples/UIExplorer/WebViewExample.js index b9137e87c..478c2a995 100644 --- a/Examples/UIExplorer/WebViewExample.js +++ b/Examples/UIExplorer/WebViewExample.js @@ -58,19 +58,19 @@ var WebViewExample = React.createClass({ return ( - - - - {'<'} - - + + + {'<'} + - - - - {'>'} - - + + + {'>'} + + {this.props.children} + + ); }, }); @@ -188,6 +176,5 @@ var TouchableOpacity = React.createClass({ */ var PRESS_RECT_OFFSET = {top: 20, left: 20, right: 20, bottom: 30}; -var CHILD_REF = keyOf({childRef: null}); module.exports = TouchableOpacity; diff --git a/Libraries/ReactIOS/WarningBox.js b/Libraries/ReactIOS/WarningBox.js index 37076ef5c..8caaa5e02 100644 --- a/Libraries/ReactIOS/WarningBox.js +++ b/Libraries/ReactIOS/WarningBox.js @@ -174,15 +174,13 @@ var WarningRow = React.createClass({ {...this.panGesture.panHandlers}> - - { this.text = text; }}> - {countText} - {this.props.warning} - - + { this.text = text; }}> + {countText} + {this.props.warning} + { this.closeButton = closeButton; }} @@ -212,30 +210,27 @@ var WarningBoxOpened = React.createClass({ return ( - - - {countText} - {this.props.warning} - - - - - - Dismiss - - - - - - - Ignore - - - - + onPress={this.props.onClose} + style={styles.yellowBox}> + + {countText} + {this.props.warning} + + + + + Dismiss + + + + + Ignore + + );