UNPKG

rn-qr-generator

Version:
51 lines (50 loc) 1.67 kB
import { NativeModules, Platform, processColor } from "react-native"; const LINKING_ERROR = `The package 'rn-qr-generator' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) + "- You rebuilt the app after installing the package\n" + "- You are not using Expo Go\n"; // Try to get TurboModule first, then fall back to legacy const isTurboModuleEnabled = globalThis.__turboModuleProxy != null; const RNQrGeneratorModule = isTurboModuleEnabled ? require("./NativeRNQrGenerator").default : NativeModules.RNQrGenerator; const RNQrGenerator = RNQrGeneratorModule ? RNQrGeneratorModule : new Proxy({}, { get() { throw new Error(LINKING_ERROR); } }); export default { generate: options => { const { value, backgroundColor, color } = options; if (!value) { return Promise.reject('Property "value" is missing'); } const qrOptions = { correctionLevel: "H", ...options, backgroundColor: processColor(backgroundColor || "white"), color: processColor(color || "black") }; return new Promise((resolve, reject) => { RNQrGenerator.generate(qrOptions, error => reject(error), data => resolve(data)); }); }, detect: options => { const { uri, base64 } = options; if (!uri && !base64) { return Promise.reject('Property "uri" or "base64" are missing'); } const qrOptions = { ...options }; return new Promise((resolve, reject) => { RNQrGenerator.detect(qrOptions, error => reject(error), data => resolve(data)); }); } }; //# sourceMappingURL=index.js.map