[android] fix crash if breadcrumb refs don't exist

This commit is contained in:
Emily Janzer 2015-08-20 17:57:33 -07:00
parent 3bfa90e433
commit 4b28a847e6
1 changed files with 13 additions and 11 deletions

View File

@ -119,16 +119,16 @@ var NavigatorBreadcrumbNavigationBar = React.createClass({
} }
if (interpolate.Crumb(CRUMB_PROPS[index].style, amount)) { 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)) { 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)) { 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)) { 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]; var right = this.refs['right_' + index];
if (right && if (right &&
@ -165,13 +165,10 @@ var NavigatorBreadcrumbNavigationBar = React.createClass({
renderToHardwareTextureAndroid: renderToHardwareTexture, renderToHardwareTextureAndroid: renderToHardwareTexture,
}; };
this.refs['icon_' + index].setNativeProps(props); this._setPropsIfExists('icon_' + index, props);
this.refs['separator_' + index].setNativeProps(props); this._setPropsIfExists('separator_' + index, props);
this.refs['title_' + index].setNativeProps(props); this._setPropsIfExists('title_' + index, props);
var right = this.refs['right_' + index]; this._setPropsIfExists('right_' + index, props);
if (right) {
right.setNativeProps(props);
}
}, },
componentWillMount: function() { componentWillMount: function() {
@ -260,6 +257,11 @@ var NavigatorBreadcrumbNavigationBar = React.createClass({
this._descriptors.right = this._descriptors.right.set(route, rightButtonDescriptor); this._descriptors.right = this._descriptors.right.set(route, rightButtonDescriptor);
return rightButtonDescriptor; return rightButtonDescriptor;
}, },
_setPropsIfExists: function(ref, props) {
var ref = this.refs[ref];
ref && ref.setNativeProps(props);
},
}); });
var styles = StyleSheet.create({ var styles = StyleSheet.create({