From 08d30e751b8ed0b5d485d5a4d2f479a89e2863a1 Mon Sep 17 00:00:00 2001 From: James Ide Date: Fri, 15 May 2015 18:05:49 -0700 Subject: [PATCH] [ActivityIndicator] Add the onLayout prop to the outer container view Summary: ActivityIndicator was forwarding all of its props except `style` to the inner native view. This meant that onLayout would report a zero-sized frame that was relative to the wrapper view instead of the parent of the ActivityIndicator. This diff adds `onLayout` to the wrapper view instead of the native view. In general, all components that forward props need to be audited in this manner. Closes https://github.com/facebook/react-native/pull/1292 Github Author: James Ide Test Plan: `` reports the size of the spinner plus a position relative to its parent view. --- .../ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js | 12 ++++++++++-- Libraries/Components/View/View.js | 4 +++- Libraries/Image/Image.ios.js | 6 ++++++ Libraries/Text/Text.js | 6 ++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js b/Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js index a3f1fe6be..d6afa3e06 100644 --- a/Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js +++ b/Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js @@ -53,6 +53,12 @@ var ActivityIndicatorIOS = React.createClass({ 'small', 'large', ]), + /** + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout: PropTypes.func, }, getDefaultProps: function(): DefaultProps { @@ -65,10 +71,12 @@ var ActivityIndicatorIOS = React.createClass({ }, render: function() { - var {style, ...props} = this.props; + var {onLayout, style, ...props} = this.props; var sizeStyle = (this.props.size === 'large') ? styles.sizeLarge : styles.sizeSmall; return ( - + ); diff --git a/Libraries/Components/View/View.js b/Libraries/Components/View/View.js index bd7529e58..c3659e961 100644 --- a/Libraries/Components/View/View.js +++ b/Libraries/Components/View/View.js @@ -91,7 +91,9 @@ var View = React.createClass({ onStartShouldSetResponderCapture: PropTypes.func, /** - * Invoked on mount and layout changes with {x, y, width, height}. + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. */ onLayout: PropTypes.func, diff --git a/Libraries/Image/Image.ios.js b/Libraries/Image/Image.ios.js index f388468c4..45c1ad828 100644 --- a/Libraries/Image/Image.ios.js +++ b/Libraries/Image/Image.ios.js @@ -99,6 +99,12 @@ var Image = React.createClass({ * testing scripts. */ testID: PropTypes.string, + /** + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout: PropTypes.func, }, statics: { diff --git a/Libraries/Text/Text.js b/Libraries/Text/Text.js index dee0d8543..6e934a8e6 100644 --- a/Libraries/Text/Text.js +++ b/Libraries/Text/Text.js @@ -92,6 +92,12 @@ var Text = React.createClass({ * Used to locate this view in end-to-end tests. */ testID: React.PropTypes.string, + /** + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout: React.PropTypes.func, }, viewConfig: viewConfig,