mirror of
https://github.com/tappollo/react-native-safari-view.git
synced 2026-04-29 04:15:06 +08:00
69 lines
1.6 KiB
JavaScript
69 lines
1.6 KiB
JavaScript
/**
|
|
* @providesModule SafariViewManager
|
|
*/
|
|
'use strict';
|
|
import {
|
|
NativeModules,
|
|
NativeAppEventEmitter,
|
|
DeviceEventEmitter,
|
|
processColor
|
|
} from 'react-native';
|
|
const NativeSafariViewManager = NativeModules.SafariViewManager;
|
|
|
|
/**
|
|
* High-level docs for the SafariViewManager iOS API can be written here.
|
|
*/
|
|
|
|
export default {
|
|
show(options) {
|
|
if (options && options.tintColor) {
|
|
options.tintColor = processColor(options.tintColor);
|
|
}
|
|
if (options && options.barTintColor) {
|
|
options.barTintColor = processColor(options.barTintColor);
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
NativeSafariViewManager.show(options, (error) => {
|
|
if (error) {
|
|
return reject(error);
|
|
}
|
|
|
|
resolve(true);
|
|
});
|
|
});
|
|
},
|
|
|
|
dismiss() {
|
|
NativeSafariViewManager.dismiss();
|
|
},
|
|
|
|
isAvailable() {
|
|
return new Promise((resolve, reject) => {
|
|
NativeSafariViewManager.isAvailable((error) => {
|
|
if (error) {
|
|
return reject(error);
|
|
}
|
|
|
|
resolve(true);
|
|
});
|
|
});
|
|
},
|
|
|
|
addEventListener(event, listener) {
|
|
if (event === 'onShow') {
|
|
return DeviceEventEmitter.addListener('SafariViewOnShow', listener);
|
|
} else if (event === 'onDismiss') {
|
|
return NativeAppEventEmitter.addListener('SafariViewOnDismiss', listener);
|
|
}
|
|
},
|
|
|
|
removeEventListener(event, listener) {
|
|
if (event === 'onShow') {
|
|
DeviceEventEmitter.removeListener('SafariViewOnShow', listener);
|
|
} else if (event === 'onDismiss') {
|
|
NativeAppEventEmitter.removeListener('SafariViewOnDismiss', listener);
|
|
}
|
|
}
|
|
};
|