diff --git a/docs/docs/guides/CODE_SCANNING.mdx b/docs/docs/guides/CODE_SCANNING.mdx index 449ecdd..c062010 100644 --- a/docs/docs/guides/CODE_SCANNING.mdx +++ b/docs/docs/guides/CODE_SCANNING.mdx @@ -30,7 +30,18 @@ A Code Scanner is a separate Camera output (just like photo or video) that can d On iOS, the Code Scanner uses the platform-native APIs and can be used out of the box. -On Android, the [MLKit Vision Barcode Scanning](https://developers.google.com/ml-kit/vision/barcode-scanning) API will be used, and the model (2.2MB) needs to be downloaded first. To download the model when the user installs your app, add this to your `AndroidManifest.xml` file: +On Android, the [MLKit Vision Barcode Scanning](https://developers.google.com/ml-kit/vision/barcode-scanning) API will be used, and the model (2.2MB) needs to be downloaded first. + + + + +To download the model when the user installs your app, add this to your `AndroidManifest.xml` file: ```xml @@ -41,6 +52,29 @@ On Android, the [MLKit Vision Barcode Scanning](https://developers.google.com/ml ``` + + + +To download the model when the user installs your app, add the `enableCodeScanner` flag to your Expo config (`app.json`, `app.config.json` or `app.config.js`): + +```json +{ + "name": "my app", + "plugins": [ + [ + "react-native-vision-camera", + { + // ... + "enableCodeScanner": true + } + ] + ] +} +``` + + + + ## Usage To use a codescanner, simply create a [`CodeScanner`](/docs/api/interfaces/CodeScanner) and pass it to the ``: diff --git a/package/src/expo-plugin/withVisionCamera.ts b/package/src/expo-plugin/withVisionCamera.ts index 9c7d406..00d59a2 100644 --- a/package/src/expo-plugin/withVisionCamera.ts +++ b/package/src/expo-plugin/withVisionCamera.ts @@ -9,10 +9,36 @@ const CAMERA_USAGE = 'Allow $(PRODUCT_NAME) to access your camera' const MICROPHONE_USAGE = 'Allow $(PRODUCT_NAME) to access your microphone' type Props = { + /** + * The text to show in the native dialog when asking for Camera Permissions. + * @default 'Allow $(PRODUCT_NAME) to access your camera' + */ cameraPermissionText?: string + /** + * Whether to add Microphone Permissions to the native manifest or not. + * @default false + */ enableMicrophonePermission?: boolean + /** + * The text to show in the native dialog when asking for Camera Permissions. + * @default 'Allow $(PRODUCT_NAME) to access your microphone' + */ microphonePermissionText?: string + /** + * Whether to enable the Frame Processors runtime, or explicitly disable it. + * Disabling Frame Processors will make your app smaller as the C++ files will not be compiled. + * See [Frame Processors](https://www.react-native-vision-camera.com/docs/guides/frame-processors) + * @default false + */ disableFrameProcessors?: boolean + /** + * Whether to enable the QR/Barcode Scanner Model. If true, the MLKit Model will + * automatically be downloaded on app startup. If false, it will be downloaded + * once the Camera is created with a `CodeScanner`. + * See [QR/Barcode Scanning](https://www.react-native-vision-camera.com/docs/guides/code-scanning) + * @default false + */ + enableCodeScanner?: boolean } const withCamera: ConfigPlugin = (config, props = {}) => { @@ -32,7 +58,12 @@ const withCamera: ConfigPlugin = (config, props = {}) => { config = withDisableFrameProcessorsIOS(config) } - return withPlugins(config, [[AndroidConfig.Permissions.withPermissions, androidPermissions], withAndroidMLKitVisionModel]) + if (props.enableCodeScanner) { + // Adds meta download-request tag to AndroidManifest + config = withAndroidMLKitVisionModel(config) + } + + return withPlugins(config, [[AndroidConfig.Permissions.withPermissions, androidPermissions]]) } export default createRunOncePlugin(withCamera, pkg.name, pkg.version)