2020-04-03 16:23:29 +00:00
|
|
|
/**
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
2020-07-22 03:37:43 +00:00
|
|
|
import * as WebBrowser from 'expo-web-browser';
|
2020-04-03 16:23:29 +00:00
|
|
|
|
|
|
|
import Colors from '../constants/Colors';
|
|
|
|
|
|
|
|
export async function openBrowser(url, options) {
|
2020-07-22 03:37:43 +00:00
|
|
|
const finalOptions = Object.assign({
|
2020-12-30 19:22:46 +00:00
|
|
|
toolbarColor: Colors.blackish,
|
|
|
|
controlsColor: Colors.blue
|
2020-07-22 03:37:43 +00:00
|
|
|
}, options);
|
2020-04-03 16:23:29 +00:00
|
|
|
|
2020-07-22 03:37:43 +00:00
|
|
|
try {
|
|
|
|
await WebBrowser.openBrowserAsync(url, finalOptions);
|
|
|
|
} catch (err) {
|
|
|
|
// Workaround issue where swiping browser closed does not dismiss it.
|
|
|
|
// https://github.com/expo/expo/issues/6918
|
|
|
|
if (err.message === 'Another WebBrowser is already being presented.') {
|
|
|
|
try {
|
|
|
|
await WebBrowser.dismissBrowser();
|
|
|
|
return WebBrowser.openBrowserAsync(url, finalOptions);
|
|
|
|
} catch (retryErr) {
|
|
|
|
console.warn('Could not dismiss and reopen browser', retryErr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.warn('Could not open browser', err);
|
|
|
|
}
|
|
|
|
}
|
2020-04-03 16:23:29 +00:00
|
|
|
}
|