import { NativeModules } from "react-native"; const { RNOkayCamPlus } = NativeModules; interface LabelConfig { text: string; color: string; size: number; } interface OkayCamBtnConfig { backgroundColor: string; contentColor: string; } interface SwitchBtnConfig { color: string; show: Boolean; } type cameraFacingType = "front" | "back"; // Set default values const defaultColor = "#ffffff"; const defaultColor2 = "#ffa500"; const imageResizedWidth = 1080; const labelConfig: LabelConfig = { text: "", color: defaultColor, size: 20, }; const okayCamBtnConfig: OkayCamBtnConfig = { backgroundColor: defaultColor2, contentColor: defaultColor, }; // cal native capture document export enum DocumentCaptureMode { FULL = "FULL", FRONT_ONLY = "FRONT_ONLY", FRONT_BACK = "FRONT_BACK", FRONT_WITH_FLASH = "FRONT_WITH_FLASH", } // cal native capture document export const captureDocument = ( license: string, base64: boolean, config: { width?: number; imageQuality?: number; mode?: string; autoCapture?: boolean; } = {}, ) => { const { width = imageResizedWidth, imageQuality = 1.0, mode = DocumentCaptureMode.FULL, autoCapture = true, } = config; return new Promise(function (resolve, reject) { console.log(`autoCapture: ${autoCapture}`); console.log(`mode: ${mode}`); RNOkayCamPlus.captureDocument({ license: license, base64: base64, config: { width: width, imageQuality: imageQuality, mode: mode, autoCapture: autoCapture, }, }) .then((result: string) => { resolve(JSON.parse(result)); }) .catch((error: any) => { reject({ code: error?.code ?? "UNKNOWN", message: error?.message ?? "Unknown error", }); }); }); }; const defaultSwitchBtnConfig: SwitchBtnConfig = { show: true, color: defaultColor, }; const cameraFacing: cameraFacingType = "front"; // call native capture selfie export const captureSelfie = ( license: string, base64: Boolean, { topLabel = labelConfig, bottomFrameColor = defaultColor2, captureBtnColor = defaultColor, switchBtnConfig = defaultSwitchBtnConfig, confirmBtnConfig = okayCamBtnConfig, retakeBtnConfig = okayCamBtnConfig, defaultCameraFacing = cameraFacing, width = imageResizedWidth, imageQuality = 1.0, }, ) => { return new Promise(function (resolve, reject) { RNOkayCamPlus.captureSelfie({ license: license, base64: base64, config: { topLabel: topLabel, bottomFrameColor: bottomFrameColor, captureBtnColor: captureBtnColor, switchBtnConfig: switchBtnConfig, confirmBtnConfig: confirmBtnConfig, retakeBtnConfig: retakeBtnConfig, defaultCameraFacing: defaultCameraFacing, width: width, imageQuality: imageQuality, }, }) .then((result: string) => { resolve(JSON.parse(result)); }) .catch((error: any) => { reject({ code: error?.code ?? "UNKNOWN", message: error?.message ?? "Unknown error", }); }); }); }; // call native capture selfie plus export const captureSelfiePlus = (license: string, base64: Boolean) => { return new Promise(function (resolve, reject) { RNOkayCamPlus.captureSelfiePlus({ license: license, base64: base64, }) .then((result: string) => { resolve(JSON.parse(result)); }) .catch((error: any) => { reject({ code: error?.code ?? "UNKNOWN", message: error?.message ?? "Unknown error", }); }); }); };