[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.
pull/1745/head
Saúl Ibarra Corretgé 7 years ago committed by Lyubo Marinov
parent 35fddfa8f4
commit cc9249ba1a
  1. 5
      react/features/app/components/AbstractApp.js
  2. 35
      react/index.native.js

@ -137,6 +137,11 @@ export class AbstractApp extends Component {
store: this._maybeCreateStore(nextProps)
});
}
// Deal with URL changes
if (typeof nextProps.url !== 'undefined') {
this._openURL(nextProps.url || this._getDefaultURL());
}
}
/**

@ -56,18 +56,33 @@ class Root extends Component {
url: this.props.url
};
// Handle the URL, if any, with which the app was launched.
Linking.getInitialURL()
.then(url => this.setState({ url }))
.catch(err => {
console.error('Failed to get initial URL', err);
// Handle the URL the application was launched with, but props have
// precedence.
if (typeof this.props.url === 'undefined') {
Linking.getInitialURL()
.then(url => {
this.setState({ url });
})
.catch(err => {
console.error('Failed to get initial URL', err);
// XXX Start with an empty URL if getting the initial URL fails;
// otherwise, nothing will be rendered.
if (this.state.url !== null) {
// Start with an empty URL if getting the initial URL fails
// otherwise, nothing will be rendered.
this.setState({ url: null });
}
});
});
}
}
/**
* Implements React's {@link Component#componentWillReceiveProps()}.
*
* New props can be set from the native side by setting the appProperties
* property (on iOS) or calling setAppProperties (on Android).
*
* @inheritdoc
*/
componentWillReceiveProps(nextProps) {
this.setState({ url: nextProps.url || null });
}
/**

Loading…
Cancel
Save