rn: drop deep / universal links handling from JS
It's now all handled in the SDK an we'll get the new URLs via props.
This commit is contained in:
parent
90803c8ff6
commit
3fa5aed950
|
@ -1,7 +1,6 @@
|
|||
// @flow
|
||||
|
||||
import React from 'react';
|
||||
import { Linking } from 'react-native';
|
||||
|
||||
import '../../analytics';
|
||||
import '../../authentication';
|
||||
|
@ -73,9 +72,6 @@ export class App extends AbstractApp {
|
|||
constructor(props: Props) {
|
||||
super(props);
|
||||
|
||||
// Bind event handlers so they are only bound once for every instance.
|
||||
this._onLinkingURL = this._onLinkingURL.bind(this);
|
||||
|
||||
// In the Release configuration, React Native will (intentionally) throw
|
||||
// an unhandled JavascriptException for an unhandled JavaScript error.
|
||||
// This will effectively kill the app. In accord with the Web, do not
|
||||
|
@ -84,12 +80,11 @@ export class App extends AbstractApp {
|
|||
}
|
||||
|
||||
/**
|
||||
* Subscribe to notifications about activating URLs registered to be handled
|
||||
* by this app.
|
||||
* Initializes the color scheme.
|
||||
*
|
||||
* @inheritdoc
|
||||
*
|
||||
* @returns {void}
|
||||
* @see https://facebook.github.io/react-native/docs/linking.html
|
||||
*/
|
||||
componentDidMount() {
|
||||
super.componentDidMount();
|
||||
|
@ -99,22 +94,6 @@ export class App extends AbstractApp {
|
|||
// unnecessary re-renders.
|
||||
this.state.store.dispatch(setColorScheme(this.props.colorScheme));
|
||||
});
|
||||
|
||||
Linking.addEventListener('url', this._onLinkingURL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from notifications about activating URLs registered to be
|
||||
* handled by this app.
|
||||
*
|
||||
* @inheritdoc
|
||||
* @returns {void}
|
||||
* @see https://facebook.github.io/react-native/docs/linking.html
|
||||
*/
|
||||
componentWillUnmount() {
|
||||
Linking.removeEventListener('url', this._onLinkingURL);
|
||||
|
||||
super.componentWillUnmount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,22 +149,6 @@ export class App extends AbstractApp {
|
|||
}
|
||||
}
|
||||
|
||||
_onLinkingURL: (*) => void;
|
||||
|
||||
/**
|
||||
* Notified by React's Linking API that a specific URL registered to be
|
||||
* handled by this app was activated.
|
||||
*
|
||||
* @param {Object} event - The details of the notification/event.
|
||||
* @param {string} event.url - The URL registered to be handled by this app
|
||||
* which was activated.
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
_onLinkingURL({ url }) {
|
||||
super._openURL(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the platform specific dialog container.
|
||||
*
|
||||
|
|
|
@ -10,15 +10,12 @@
|
|||
// collect the polyfills' files.
|
||||
import './features/base/lib-jitsi-meet/native/polyfills-bundler';
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import { AppRegistry, Linking, NativeModules } from 'react-native';
|
||||
import React, { PureComponent } from 'react';
|
||||
import { AppRegistry } from 'react-native';
|
||||
|
||||
import { App } from './features/app';
|
||||
import { equals } from './features/base/redux';
|
||||
import { IncomingCallApp } from './features/mobile/incoming-call';
|
||||
|
||||
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
||||
|
||||
/**
|
||||
* The type of the React {@code Component} props of {@link Root}.
|
||||
*/
|
||||
|
@ -30,17 +27,6 @@ type Props = {
|
|||
url: Object | string
|
||||
};
|
||||
|
||||
/**
|
||||
* The type of the React {@code Component} state of {@link Root}.
|
||||
*/
|
||||
type State = {
|
||||
|
||||
/**
|
||||
* The URL, if any, with which the app was launched.
|
||||
*/
|
||||
url: ?Object | string
|
||||
};
|
||||
|
||||
/**
|
||||
* React Native doesn't support specifying props to the main/root component (in
|
||||
* the JS/JSX source code). So create a wrapper React Component (class) around
|
||||
|
@ -48,82 +34,7 @@ type State = {
|
|||
*
|
||||
* @extends Component
|
||||
*/
|
||||
class Root extends Component<Props, State> {
|
||||
/**
|
||||
* Initializes a new {@code Root} instance.
|
||||
*
|
||||
* @param {Props} props - The read-only properties with which the new
|
||||
* instance is to be initialized.
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
url: this.props.url
|
||||
};
|
||||
|
||||
// Handle the URL, if any, with which the app was launched. But props
|
||||
// have precedence.
|
||||
if (typeof this.props.url === 'undefined') {
|
||||
this._getInitialURL()
|
||||
.then(url => {
|
||||
if (typeof this.state.url === 'undefined') {
|
||||
this.setState({ url });
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Failed to get initial URL', err);
|
||||
|
||||
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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the initial URL the app was launched with. This can be a universal
|
||||
* (or deep) link, or a CallKit intent in iOS. Since the native
|
||||
* {@code Linking} module doesn't provide a way to access intents in iOS,
|
||||
* those are handled with the {@code LaunchOptions} module, which
|
||||
* essentially provides a replacement which takes that into consideration.
|
||||
*
|
||||
* @private
|
||||
* @returns {Promise} - A promise which will be fulfilled with the URL that
|
||||
* the app was launched with.
|
||||
*/
|
||||
_getInitialURL() {
|
||||
if (NativeModules.LaunchOptions) {
|
||||
return NativeModules.LaunchOptions.getInitialURL();
|
||||
}
|
||||
|
||||
return Linking.getInitialURL();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements React's {@link Component#componentDidUpdate()}.
|
||||
*
|
||||
* New props can be set from the native side by setting the appProperties
|
||||
* property (on iOS) or calling setAppProperties (on Android).
|
||||
*
|
||||
* @inheritdoc
|
||||
*/
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
// Ignore the special state update triggered on {@code Root}
|
||||
// instantiation where an undefined url prop is set to a default.
|
||||
if (typeof prevState.url === 'undefined'
|
||||
&& typeof this.state.url !== 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!equals(prevProps.url, this.props.url)) {
|
||||
// eslint-disable-next-line react/no-did-update-set-state
|
||||
this.setState({ url: this.props.url || null });
|
||||
}
|
||||
}
|
||||
|
||||
class Root extends PureComponent<Props> {
|
||||
/**
|
||||
* Implements React's {@link Component#render()}.
|
||||
*
|
||||
|
@ -131,26 +42,9 @@ class Root extends Component<Props, State> {
|
|||
* @returns {ReactElement}
|
||||
*/
|
||||
render() {
|
||||
const { url } = this.state;
|
||||
|
||||
// XXX We don't render the App component until we get the initial URL.
|
||||
// Either it's null or some other non-null defined value.
|
||||
if (typeof url === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {
|
||||
// The following props are forked in state:
|
||||
url: _, // eslint-disable-line no-unused-vars
|
||||
|
||||
// The remaining props are passed through to App.
|
||||
...props
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<App
|
||||
{ ...props }
|
||||
url = { url } />
|
||||
{ ...this.props } />
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue