Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
When there is a change in tabs via props in ScrollableTabBar, recalcu…
…late width
  • Loading branch information
ghuh committed Jul 25, 2016
commit 2d8b556b8707b513ed478c8ee650dc16bcb66b7e
7 changes: 7 additions & 0 deletions ScrollableTabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ const ScrollableTabBar = React.createClass({
</View>;
},

componentWillReceiveProps(nextProps) {
// If the tabs change, force the width of the tabs container to be recalculated
if (JSON.stringify(this.props.tabs) != JSON.stringify(nextProps.tabs) && this.state._containerWidth) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you think that shallow comparison would be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I used JSON.stringify. It's a poor man's deep equals. There are more precise ways to do it but they all take a lot more code and have slower performance.

Regardless, yes, I believe this should be sufficient to ensure that any change will trigger the state to update correctly.

this.setState({ _containerWidth: null, });
}
},

onTabContainerLayout(e) {
this._tabContainerMeasurements = e.nativeEvent.layout;
let width = this._tabContainerMeasurements.width;
Expand Down