@swan-io/react-native-browser
Version:
An easy-to-use in-app browser module for React Native.
50 lines (49 loc) • 1.32 kB
JavaScript
;
import { Linking, NativeEventEmitter, processColor } from "react-native";
import NativeModule from "./NativeRNSwanBrowser";
const emitter = new NativeEventEmitter(NativeModule);
const convertColorToNumber = color => {
const processed = processColor(color);
if (typeof processed === "number") {
return processed;
}
};
export const openBrowser = (url, options) => {
const {
animationType,
dismissButtonStyle,
onOpen,
onClose
} = options;
const barTintColor = convertColorToNumber(options.barTintColor);
const controlTintColor = convertColorToNumber(options.controlTintColor);
return NativeModule.open(url, {
...(animationType != null && {
animationType
}),
...(dismissButtonStyle != null && {
dismissButtonStyle
}),
...(barTintColor != null && {
barTintColor
}),
...(controlTintColor != null && {
controlTintColor
})
}).then(() => {
let deeplink;
onOpen?.();
const linkListener = Linking.addListener("url", ({
url
}) => {
deeplink = url;
NativeModule.close();
});
const closeListener = emitter.addListener("swanBrowserDidClose", () => {
onClose?.(deeplink);
linkListener.remove();
closeListener.remove();
});
});
};
//# sourceMappingURL=index.js.map