[RN] Fix app startup from a CallKit intent
Story time. Currently the app can be started in 4 ways: - just tapping on the icon - via a deep link - via a universal link - via the phone's recent calls list The last 3 options will make the app join the specified room upon launch. React Native's Linking module implements the necessary bits to handle deep or universal linking, but CallKit is out of its scope. In order to blend any type of app startup mode, a new LaunchOptions module (iOS only) exports a getInitialURL function, akin to the one in the Linking module, but taking CallKit instents into consideration. This function is then used to make app startup with a URL consistent across all different modes.
This commit is contained in:
committed by
Paweł Domas
parent
d481c6f736
commit
bd301403c4
+21
-2
@@ -14,7 +14,7 @@ import './features/base/react/prop-types-polyfill';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { AppRegistry, Linking } from 'react-native';
|
||||
import { AppRegistry, Linking, NativeModules } from 'react-native';
|
||||
|
||||
import { App } from './features/app';
|
||||
import { equals } from './features/base/redux';
|
||||
@@ -77,7 +77,7 @@ class Root extends Component {
|
||||
// Handle the URL, if any, with which the app was launched. But props
|
||||
// have precedence.
|
||||
if (typeof this.props.url === 'undefined') {
|
||||
Linking.getInitialURL()
|
||||
this._getInitialURL()
|
||||
.then(url => {
|
||||
if (typeof this.state.url === 'undefined') {
|
||||
this.setState({ url });
|
||||
@@ -95,6 +95,25 @@ class Root extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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#componentWillReceiveProps()}.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user