[RN] Fix passing url prop to Root and App components

React (pun intended) to prop changes, that is, load the new specified URL.

In addition, fix a hidden bug in loading the initial URL from the linking
module: we prefer a prop to the URL the app was launched with, in case somehow
both are specified. We (the Jitsi Meet app) are not going to run into this
corner case, but let's be defensive just in case.
This commit is contained in:
Saúl Ibarra Corretgé 2017-07-06 10:01:35 +02:00 committed by Lyubo Marinov
parent 948d18f954
commit d5e89a60b7
1 changed files with 10 additions and 4 deletions

View File

@ -60,13 +60,19 @@ class Root extends Component {
// have precedence.
if (typeof this.props.url === 'undefined') {
Linking.getInitialURL()
.then(url => this.setState({ url }))
.then(url => {
if (typeof this.state.url === 'undefined') {
this.setState({ url });
}
})
.catch(err => {
console.error('Failed to get initial URL', err);
// Start with an empty URL if getting the initial URL fails;
// otherwise, nothing will be rendered.
this.setState({ url: null });
if (typeof this.state.url === 'undefined') {
// Start with an empty URL if getting the initial URL
// fails; otherwise, nothing will be rendered.
this.setState({ url: null });
}
});
}
}