[RN] Alternative to JitsiMeetView.loadURL w/o URL
Introduces loadURLObject in JitsiMeetView on Android and iOS which accepts a Bundle and NSDictionary, respectively, similar in structure to the JS object accepted by the constructor of Web's ExternalAPI. At this time, only the property url of the bundle/dictionary is supported. However, it allows the public API of loadURLObject to be consumed. The property url will be made optional in the future and other properties will be supported from which a URL will be constructed.
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
} from '../../base/participants';
|
||||
import { RouteRegistry } from '../../base/react';
|
||||
import { MiddlewareRegistry, ReducerRegistry } from '../../base/redux';
|
||||
import { toURLString } from '../../base/util';
|
||||
|
||||
import {
|
||||
appNavigate,
|
||||
@@ -52,7 +53,10 @@ export class AbstractApp extends Component {
|
||||
/**
|
||||
* The URL, if any, with which the app was launched.
|
||||
*/
|
||||
url: React.PropTypes.string
|
||||
url: React.PropTypes.oneOfType([
|
||||
React.PropTypes.object,
|
||||
React.PropTypes.string
|
||||
])
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -110,7 +114,7 @@ export class AbstractApp extends Component {
|
||||
|
||||
// If a URL was explicitly specified to this React Component, then open
|
||||
// it; otherwise, use a default.
|
||||
this._openURL(this.props.url || this._getDefaultURL());
|
||||
this._openURL(toURLString(this.props.url) || this._getDefaultURL());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,9 +143,10 @@ export class AbstractApp extends Component {
|
||||
}
|
||||
|
||||
// Deal with URL changes.
|
||||
const { url } = nextProps;
|
||||
let { url } = nextProps;
|
||||
|
||||
if (this.props.url !== url) {
|
||||
url = toURLString(url);
|
||||
if (toURLString(this.props.url) !== url) {
|
||||
this._openURL(url || this._getDefaultURL());
|
||||
}
|
||||
}
|
||||
@@ -391,12 +396,12 @@ export class AbstractApp extends Component {
|
||||
/**
|
||||
* Navigates this AbstractApp to (i.e. opens) a specific URL.
|
||||
*
|
||||
* @param {string} url - The URL to which to navigate this AbstractApp (i.e.
|
||||
* the URL to open).
|
||||
* @param {string|Object} url - The URL to navigate this AbstractApp to
|
||||
* (i.e. the URL to open).
|
||||
* @protected
|
||||
* @returns {void}
|
||||
*/
|
||||
_openURL(url) {
|
||||
this._getStore().dispatch(appNavigate(url));
|
||||
this._getStore().dispatch(appNavigate(toURLString(url)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,3 +262,53 @@ export function parseURIString(uri: ?string) {
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to return a {@code String} representation of a specific
|
||||
* {@code Object} which is supposed to represent a URL. Obviously, if a
|
||||
* {@code String} is specified, it is returned. If a {@code URL} is specified,
|
||||
* its {@code URL#href} is returned. Additionally, an {@code Object} similar to
|
||||
* the one accepted by the constructor of Web's ExternalAPI is supported on both
|
||||
* mobile/React Native and Web/React.
|
||||
*
|
||||
* @param {string|Object} obj - The URL to return a {@code String}
|
||||
* representation of.
|
||||
* @returns {string} - A {@code String} representation of the specified
|
||||
* {@code obj} which is supposed to represent a URL.
|
||||
*/
|
||||
export function toURLString(obj: ?(string | Object)): ?string {
|
||||
let str;
|
||||
|
||||
switch (typeof obj) {
|
||||
case 'object':
|
||||
if (obj) {
|
||||
if (obj instanceof URL) {
|
||||
str = obj.href;
|
||||
} else {
|
||||
str = _urlObjectToString(obj);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
str = String(obj);
|
||||
break;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to return a {@code String} representation of a specific
|
||||
* {@code Object} similar to the one accepted by the constructor
|
||||
* of Web's ExternalAPI.
|
||||
*
|
||||
* @param {Object} obj - The URL to return a {@code String} representation of.
|
||||
* @returns {string} - A {@code String} representation of the specified
|
||||
* {@code obj}.
|
||||
*/
|
||||
function _urlObjectToString({ url }: Object): ?string {
|
||||
// TODO Support properties other than url. Support (pretty much) all
|
||||
// properties accepted by the constructor of Web's ExternalAPI.
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user