Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
33 changes: 33 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# React Native ML Kit Documentation

Documentation for [React Native ML Kit](https://github.com/a7medev/react-native-ml-kit), built with [Docusaurus](https://docusaurus.io/).

## Getting Started

### Installation

```bash
yarn install
```

### Local Development

```bash
yarn start
```
Starts the development server.

### Build

```bash
yarn build
```
Generates static content in the `build` directory.

### Deployment

To deploy to GitHub Pages:

```bash
GIT_USER=<Your GitHub username> yarn deploy
```
8 changes: 8 additions & 0 deletions docs/content/barcode-scanning/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Barcode Scanning",
"position": 3,
"link": {
"type": "doc",
"id": "intro"
}
}
72 changes: 72 additions & 0 deletions docs/content/barcode-scanning/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
sidebar_position: 4
title: API Reference
---

# API Reference

## Methods

### `scan(imageURL: string): Promise<Barcode[]>`

Scans an image for barcodes. The native module exposes a single method `scan` that takes one string argument (the image URL/path).

| Parameter | Type | Description |
| :---------- | :------- | :-------------------------------------------------------------------------- |
| `imageURL` | `string` | Local file URI (e.g. `file:///...`). On **Android** only, `http://` or `https://` URLs are also supported (image is downloaded then scanned). |

**Returns:** `Promise<Barcode[]>` — List of detected barcodes (empty array if none). Rejects with Barcode scanning failed (Android) or Barcode Scanning failed (iOS) on error.

---

## Types

### `Barcode`

```typescript
interface Barcode {
format: BarcodeFormat;
/** @deprecated Use displayValue or rawValue instead. */
value: string;
rawValue: string;
displayValue: string;
}
```

- **`format`**: Barcode type (number; use `BarcodeFormat` enum for comparison).
- **`rawValue`**: Machine-readable string (from native `rawValue` / `getRawValue()`).
- **`displayValue`**: Human-readable string when available (from native `displayValue` / `getDisplayValue()`).
- **`value`**: Deprecated; use `displayValue` or `rawValue`. On Android it equals `rawValue`; on iOS it equals `displayValue`.

### `BarcodeFormat`

Enum of supported formats (values match the native ML Kit format codes):

```typescript
enum BarcodeFormat {
UNKNOWN = -1,
ALL_FORMATS = 0,
CODE_128 = 1,
CODE_39 = 2,
CODE_93 = 4,
CODABAR = 8,
DATA_MATRIX = 16,
EAN_13 = 32,
EAN_8 = 64,
ITF = 128,
QR_CODE = 256,
UPC_A = 512,
UPC_E = 1024,
PDF417 = 2048,
AZTEC = 4096,
}
```

Example: checking for QR codes only:

```javascript
import BarcodeScanning, { BarcodeFormat } from '@react-native-ml-kit/barcode-scanning';

const barcodes = await BarcodeScanning.scan(uri);
const qrCodes = barcodes.filter((b) => b.format === BarcodeFormat.QR_CODE);
```
97 changes: 97 additions & 0 deletions docs/content/barcode-scanning/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
sidebar_position: 5
title: FAQ / Troubleshooting
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# FAQ / Troubleshooting

## Common Issues

### Build failed on iOS (Deployment Target)

:::note iOS 15.5+ Required
This package requires a minimum iOS deployment target of **15.5**.
:::

<Tabs>
<TabItem value="expo" label="Expo">

1. Install the plugin:
```bash
npx expo install expo-build-properties
```
2. In `app.json` or `app.config.js`:
```json
{
"expo": {
"plugins": [
[
"expo-build-properties",
{
"ios": {
"deploymentTarget": "15.5"
}
}
]
]
}
}
```

</TabItem>
<TabItem value="bare" label="Bare React Native">

In `ios/Podfile`:

```ruby
platform :ios, '15.5'
```

</TabItem>
</Tabs>

### App crashes on launch (iOS)

Make sure CocoaPods are installed and up to date:

```bash
cd ios && pod install
```

Then rebuild the app.

### BarcodeScanning is null / doesn't seem to be linked

The native module is not linked or the app wasn’t rebuilt after adding the package.

- **Expo**: Use a **development build** (e.g. `npx expo run:ios` / `run:android`). This will **not** work in Expo Go.
- **Bare**: Rebuild the native app after installing:
```bash
npx react-native run-ios
# or
npx react-native run-android
```

### No barcodes detected (empty array)

- **Image source**: Use a **local file URI** (e.g. `file:///...`). On iOS, remote `http(s)` URLs are not supported; use a downloaded/local path.
- **Image quality**: Use a clear, well-lit image. Blur, glare, or very small barcodes often fail.
- **Orientation**: Try with the barcode upright and fully in frame.

### iOS build fails or “module not found” for ML Kit

- Run `cd ios && pod install` and ensure there are no CocoaPods errors.
- Clean and rebuild: e.g. in Xcode, **Product → Clean Build Folder**, then build again.
- If you use a different React Native or CocoaPods setup, check that `RNMLKitBarcodeScanning` is listed under **Pods** and that the app target links it.

### Android: “Barcode scanning failed” or crash

- Ensure the image URI is valid. For local files use a `content://` or `file://` URI that your app can read.
- If using a custom camera or capture pipeline, avoid passing a bitmap with non-zero rotation without converting to a proper file/URI first; ML Kit can be sensitive to rotation on some versions.

### Deprecated `value` on Barcode

The `value` field on `Barcode` is deprecated. Use **`displayValue`** for user-facing text and **`rawValue`** for the full machine-readable string.
71 changes: 71 additions & 0 deletions docs/content/barcode-scanning/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
sidebar_position: 2
title: Getting Started
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Getting Started

## Platform Support

| Android | iOS |
| :-----: | :-: |
| ✅ | ✅ |

## Installation

<Tabs>
<TabItem value="npm" label="npm">

```bash
npm install @react-native-ml-kit/barcode-scanning
```

</TabItem>
<TabItem value="yarn" label="Yarn">

```bash
yarn add @react-native-ml-kit/barcode-scanning
```

</TabItem>
</Tabs>

## Project Setup

<Tabs>
<TabItem value="expo" label="Expo">

:::info Development Build Required
This package uses native code and will **not** work in Expo Go.
:::

Rebuild your project to include the native module:

```bash
npx expo prebuild
# then
npx expo run:ios
# or
npx expo run:android
```

</TabItem>
<TabItem value="bare" label="Bare React Native">

### iOS Setup

Install the CocoaPods dependency:

```bash
cd ios && pod install
```

### Android Setup

No extra steps needed (autolinking).

</TabItem>
</Tabs>
15 changes: 15 additions & 0 deletions docs/content/barcode-scanning/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
sidebar_position: 1
title: Introduction
slug: /barcode-scanning
---

# Barcode Scanning

On-device barcode scanning using Google ML Kit. Fast, accurate, and works offline.

## Features

- **Multiple formats**: QR Code, EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF, Data Matrix, PDF417, Aztec.
- **Image-based**: Pass a local file path or image URI; no camera UI required (use with your own camera or image picker).
- **Raw and display value**: Access both machine-readable (`rawValue`) and human-readable (`displayValue`) content.
58 changes: 58 additions & 0 deletions docs/content/barcode-scanning/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
sidebar_position: 3
title: Usage
---

# Usage

## Basic Usage

Import the module and call `scan` with the image path (local file URI or `file://` path). It returns a list of detected barcodes.

```javascript
import BarcodeScanning, { BarcodeFormat } from '@react-native-ml-kit/barcode-scanning';

const scanBarcodes = async (imagePath) => {
try {
const barcodes = await BarcodeScanning.scan(imagePath);
console.log('Barcodes:', barcodes);

barcodes.forEach((barcode) => {
console.log('Format:', barcode.format);
console.log('Display:', barcode.displayValue);
console.log('Raw:', barcode.rawValue);
});
} catch (error) {
console.error('Scan failed:', error);
}
};
```

## Input Image

`scan` accepts:

- **Local file URI**: e.g. `file:///path/to/image.jpg` (from image picker or camera).
- **Android only**: `http://` or `https://` URLs (image is downloaded and then scanned).

Use a local file path when possible for best compatibility on both platforms.

### Using Expo Image Picker

Pass the asset `uri` from the picker result:

```javascript
import * as ImagePicker from 'expo-image-picker';
import BarcodeScanning from '@react-native-ml-kit/barcode-scanning';

const result = await ImagePicker.launchImageLibraryAsync();

if (!result.canceled) {
const uri = result.assets[0].uri;
const barcodes = await BarcodeScanning.scan(uri);
}
```

### No barcodes in image

If the image has no barcodes or they aren’t detected, `scan` returns an empty array `[]`. Ensure the image is clear, well lit, and the barcode is not too small or skewed.
8 changes: 8 additions & 0 deletions docs/content/face-detection/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Face Detection",
"position": 2,
"link": {
"type": "doc",
"id": "intro"
}
}
Loading