From cc9249ba1a940af999f61cf181c652234206f164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 6 Jul 2017 10:01:35 +0200 Subject: [PATCH] [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. --- react/features/app/components/AbstractApp.js | 5 +++ react/index.native.js | 35 ++++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/react/features/app/components/AbstractApp.js b/react/features/app/components/AbstractApp.js index 0701bfcef..65ecb251a 100644 --- a/react/features/app/components/AbstractApp.js +++ b/react/features/app/components/AbstractApp.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()); + } } /** diff --git a/react/index.native.js b/react/index.native.js index 5100227d2..eb88e081d 100644 --- a/react/index.native.js +++ b/react/index.native.js @@ -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 }); } /**