-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiab.ios.js
51 lines (44 loc) · 1.06 KB
/
iab.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Linking } from 'react-native';
import SafariView from 'react-native-safari-view';
let onShowSubscription = null;
let onHideSubscription = null;
export function openBrowser(url, options = {}) {
SafariView.isAvailable()
.then(() =>
SafariView.show({
...(options.ios || {}),
url,
}),
)
.catch(e => {
if (!options.noExternal) {
return Linking.openURL(url);
}
throw e;
});
}
export function closeBrowser() {
SafariView.dismiss();
}
export function onShow(cb) {
clearOnShow();
SafariView.addEventListener('onShow', cb);
onShowSubscription = cb;
}
export function clearOnShow() {
if (onShowSubscription) {
SafariView.removeEventListener('onShow', onShowSubscription);
onShowSubscription = null;
}
}
export function onHide(cb) {
clearOnHide();
SafariView.addEventListener('onDismiss', cb);
onHideSubscription = cb;
}
export function clearOnHide() {
if (onHideSubscription) {
SafariView.removeEventListener('onDismiss', onHideSubscription);
onHideSubscription = null;
}
}