From 4b28a847e6f20c4d020ba4bd833613dd4df20783 Mon Sep 17 00:00:00 2001 From: Emily Janzer Date: Thu, 20 Aug 2015 17:57:33 -0700 Subject: [PATCH] [android] fix crash if breadcrumb refs don't exist --- .../NavigatorBreadcrumbNavigationBar.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Libraries/CustomComponents/Navigator/NavigatorBreadcrumbNavigationBar.js b/Libraries/CustomComponents/Navigator/NavigatorBreadcrumbNavigationBar.js index 7f8debc842..ddfd332665 100644 --- a/Libraries/CustomComponents/Navigator/NavigatorBreadcrumbNavigationBar.js +++ b/Libraries/CustomComponents/Navigator/NavigatorBreadcrumbNavigationBar.js @@ -119,16 +119,16 @@ var NavigatorBreadcrumbNavigationBar = React.createClass({ } if (interpolate.Crumb(CRUMB_PROPS[index].style, amount)) { - this.refs['crumb_' + index].setNativeProps(CRUMB_PROPS[index]); + this._setPropsIfExists('crumb_' + index, CRUMB_PROPS[index]); } if (interpolate.Icon(ICON_PROPS[index].style, amount)) { - this.refs['icon_' + index].setNativeProps(ICON_PROPS[index]); + this._setPropsIfExists('icon_' + index, ICON_PROPS[index]); } if (interpolate.Separator(SEPARATOR_PROPS[index].style, amount)) { - this.refs['separator_' + index].setNativeProps(SEPARATOR_PROPS[index]); + this._setPropsIfExists('separator_' + index, SEPARATOR_PROPS[index]); } if (interpolate.Title(TITLE_PROPS[index].style, amount)) { - this.refs['title_' + index].setNativeProps(TITLE_PROPS[index]); + this._setPropsIfExists('title_' + index, TITLE_PROPS[index]); } var right = this.refs['right_' + index]; if (right && @@ -165,13 +165,10 @@ var NavigatorBreadcrumbNavigationBar = React.createClass({ renderToHardwareTextureAndroid: renderToHardwareTexture, }; - this.refs['icon_' + index].setNativeProps(props); - this.refs['separator_' + index].setNativeProps(props); - this.refs['title_' + index].setNativeProps(props); - var right = this.refs['right_' + index]; - if (right) { - right.setNativeProps(props); - } + this._setPropsIfExists('icon_' + index, props); + this._setPropsIfExists('separator_' + index, props); + this._setPropsIfExists('title_' + index, props); + this._setPropsIfExists('right_' + index, props); }, componentWillMount: function() { @@ -260,6 +257,11 @@ var NavigatorBreadcrumbNavigationBar = React.createClass({ this._descriptors.right = this._descriptors.right.set(route, rightButtonDescriptor); return rightButtonDescriptor; }, + + _setPropsIfExists: function(ref, props) { + var ref = this.refs[ref]; + ref && ref.setNativeProps(props); + }, }); var styles = StyleSheet.create({