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
Original file line number Diff line number Diff line change
@@ -1,63 +1,13 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

The first step to enable any data capture mode is to create a new [DataCaptureContext](https://docs.scandit.com/data-capture-sdk/react-native/core/api/data-capture-context.html#class-scandit.datacapture.core.DataCaptureContext). The `DataCaptureContext` handles licensing and a valid Scandit Data Capture SDK license key must be passed during initialization to activate scanning.
The first step to enable any data capture mode is to initialize the [DataCaptureContext](https://docs.scandit.com/data-capture-sdk/react-native/core/api/data-capture-context.html#class-scandit.datacapture.core.DataCaptureContext) with a valid Scandit Data Capture SDK license key.

:::tip
If an error message appears on screen after initialization, review the [Context Status Codes](https://docs.scandit.com/data-capture-sdk/react-native/core/api/context-status.html#status-codes) to learn more about the specific reason.
:::

If the app uses only a single scanning mode, create a single `DataCaptureContext` within the scanner component.

<Tabs defaultValue="ts" values={[
{label: 'TypeScript', value: 'ts'},
{label: 'JavaScript', value: 'js'},
]}>
<TabItem value="ts">
```ts
const context = useMemo(() => {
return DataCaptureContext.initialize('-- ENTER YOUR SCANDIT LICENSE KEY HERE --');
}, []);
```
</TabItem>
<TabItem value="js">
```js
const context = useMemo(() => {
return DataCaptureContext.initialize('-- ENTER YOUR SCANDIT LICENSE KEY HERE --');
}, []);
```
</TabItem>
</Tabs>

If the app uses multiple scanning modes, create the `DataCaptureContext` as a singleton instance and import it into each scanner component.

<Tabs defaultValue="ts" values={[
{label: 'TypeScript', value: 'ts'},
{label: 'JavaScript', value: 'js'},
]}>
<TabItem value="ts">
```ts
import { DataCaptureContext } from 'scandit-react-native-datacapture-core';

DataCaptureContext.initialize('-- ENTER YOUR SCANDIT LICENSE KEY HERE --');

export default DataCaptureContext.instance;
```
```ts
import dataCaptureContext from 'path/to/DataCaptureContext'
```
</TabItem>
<TabItem value="js">
```js
import { DataCaptureContext } from 'scandit-react-native-datacapture-core';

DataCaptureContext.initialize('-- ENTER YOUR SCANDIT LICENSE KEY HERE --');

export default DataCaptureContext.instance;
```
```ts
await DataCaptureContext.initialize('-- ENTER YOUR SCANDIT LICENSE KEY HERE --');
```

```js
import dataCaptureContext from 'path/to/DataCaptureContext'
```
</TabItem>
</Tabs>
:::note
`DataCaptureContext` should be initialized only once. Use `DataCaptureContext.sharedInstance` to access it afterwards.
:::
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import EnableSymbologies from '../../../partials/configure-symbologies/_enable-s
The following lines of code show you how to enable scanning Code 128 codes for barcode capture:

```js
const settings = new Scandit.BarcodeCaptureSettings();
settings.enableSymbology(Scandit.Symbology.Code128, true);
const settings = new BarcodeCaptureSettings();
settings.enableSymbology(Symbology.Code128, true);
```

import CapturePresents from '../../../partials/configure-symbologies/_capture-presents.mdx'
Expand All @@ -42,16 +42,8 @@ If you want to read codes that are shorter/longer than the specified default ran
The below lines of code show how to change the active symbol count for Code 128 to read codes with 6, 7 and 8 symbols.

```js
const settings = new Scandit.BarcodeCaptureSettings();
const symbologySettings = settings.settingsForSymbology(
Scandit.Symbology.Code128
);
symbologySettings.activeSymbolCounts = [6, 7, 8];

const settings = new ScanditBarcode.BarcodeCaptureSettings();
const symbologySettings = settings.settingsForSymbology(
ScanditBarcode.Symbology.Code128
);
const settings = new BarcodeCaptureSettings();
const symbologySettings = settings.settingsForSymbology(Symbology.Code128);
symbologySettings.activeSymbolCounts = [6, 7, 8];
```

Expand All @@ -68,10 +60,8 @@ This is not possible for all symbologies as it could lead to false reads when th
When you enable a symbology as described above, only dark-on-bright codes are enabled (see [SymbologySettings.isEnabled](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/symbology-settings.html#property-scandit.datacapture.barcode.SymbologySettings.IsEnabled 'SymbologySettings.isEnabled property')). When you also want to read bright-on-dark codes, color-inverted reading for that symbology must also be enabled (see [SymbologySettings.isColorInvertedEnabled](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/symbology-settings.html#property-scandit.datacapture.barcode.SymbologySettings.IsColorInvertedEnabled)):

```js
const settings = new Scandit.BarcodeCaptureSettings();
const symbologySettings = settings.settingsForSymbology(
Scandit.Symbology.Code128
);
const settings = new BarcodeCaptureSettings();
const symbologySettings = settings.settingsForSymbology(Symbology.Code128);
symbologySettings.isColorInvertedEnabled = true;
```

Expand All @@ -85,11 +75,9 @@ You can enforce a specific checksum by setting it through
[SymbologySettings.checksums](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/symbology-settings.html#property-scandit.datacapture.barcode.SymbologySettings.Checksums):

```js
const settings = new Scandit.BarcodeCaptureSettings();
const symbologySettings = settings.settingsForSymbology(
Scandit.Symbology.Code39
);
symbologySettings.checksums = [Scandit.Checksum.Mod43];
const settings = new BarcodeCaptureSettings();
const symbologySettings = settings.settingsForSymbology(Symbology.Code39);
symbologySettings.checksums = [Checksum.Mod43];
```

## Enable Symbology-Specific Extensions
Expand All @@ -103,10 +91,8 @@ To enable/disable a symbology extension, use [SymbologySettings.setExtensionEnab
The following code shows how to enable the full ASCII extension for Code 39.

```js
const settings = new Scandit.BarcodeCaptureSettings();
const symbologySettings = settings.settingsForSymbology(
Scandit.Symbology.Code39
);
const settings = new BarcodeCaptureSettings();
const symbologySettings = settings.settingsForSymbology(Symbology.Code39);
symbologySettings.setExtensionEnabled('full_ascii', true);
```

Expand Down
50 changes: 25 additions & 25 deletions docs/sdks/capacitor/barcode-capture/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,41 @@ In this guide you will learn step-by-step how to add Barcode Capture to your app
The general steps are:

- Include the ScanditBarcodeCapture library and its dependencies to your project, if any.
- Create a new [data capture context](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/data-capture-context.html#class-scandit.datacapture.core.DataCaptureContext) instance, initialized with your license key.
- Initialize the [data capture context](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/data-capture-context.html#class-scandit.datacapture.core.DataCaptureContext) with your license key.
- Create a [barcode capture settings](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/barcode-capture-settings.html#class-scandit.datacapture.barcode.BarcodeCaptureSettings) and enable the [barcode symbologies](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/symbology.html#enum-scandit.datacapture.barcode.Symbology) you want to read in your application.
- Create a new [barcode capture mode](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/barcode-capture.html#class-scandit.datacapture.barcode.BarcodeCapture) instance and initialize it with the settings created above.
- Register a [barcode capture listener](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/barcode-capture-listener.html#interface-scandit.datacapture.barcode.IBarcodeCaptureListener) to receive scan events. Process the successful scans according to your application’s needs, e.g. by looking up information in a database. After a successful scan, decide whether more codes will be scanned, or the scanning process should be stopped.
- Obtain a [camera](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/camera.html#class-scandit.datacapture.core.Camera) instance and set it as the frame source on the data capture context.
- Display the camera preview by creating a [data capture view](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/ui/data-capture-view.html#class-scandit.datacapture.core.ui.DataCaptureView).
- If displaying a preview, optionally create a new [overlay](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/ui/barcode-capture-overlay.html#class-scandit.datacapture.barcode.ui.BarcodeCaptureOverlay) and add it to [data capture view](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/ui/data-capture-view.html#class-scandit.datacapture.core.ui.DataCaptureView) for a better visual feedback.

## Create the Data Capture Context
## Initialize the Data Capture Context

The first step to add capture capabilities to your application is to create a new [data capture context](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/data-capture-context.html#class-scandit.datacapture.core.DataCaptureContext). The context expects a valid Scandit Data Capture SDK license key during construction.
The first step to add capture capabilities to your application is to initialize the [data capture context](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/data-capture-context.html#class-scandit.datacapture.core.DataCaptureContext) with a valid Scandit Data Capture SDK license key.

```js
const context = Scandit.DataCaptureContext.forLicenseKey(
'-- ENTER YOUR SCANDIT LICENSE KEY HERE --'
);
await DataCaptureContext.initialize('-- ENTER YOUR SCANDIT LICENSE KEY HERE --');
```

:::note
`DataCaptureContext` should be initialized only once. Use `DataCaptureContext.sharedInstance` to access it afterwards.
:::

## Configure the Barcode Scanning Behavior

Barcode scanning is orchestrated by the [BarcodeCapture](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/barcode-capture.html#class-scandit.datacapture.barcode.BarcodeCapture) [data capture mode](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/data-capture-mode.html#interface-scandit.datacapture.core.IDataCaptureMode). This class is the main entry point for scanning barcodes. It is configured through [BarcodeCaptureSettings](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/barcode-capture-settings.html#class-scandit.datacapture.barcode.BarcodeCaptureSettings) and allows to register one or more [listeners](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/barcode-capture-listener.html#interface-scandit.datacapture.barcode.IBarcodeCaptureListener) that will get informed whenever new codes have been recognized.

For this tutorial, we will setup barcode scanning for a small list of different barcode types, called [symbologies](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/symbology.html#enum-scandit.datacapture.barcode.Symbology). The list of symbologies to enable is highly application specific. We recommend that you only enable the list of symbologies your application requires.

```js
const settings = new Scandit.BarcodeCaptureSettings();
const settings = new BarcodeCaptureSettings();
settings.enableSymbologies([
Scandit.Symbology.Code128,
Scandit.Symbology.Code39,
Scandit.Symbology.QR,
Scandit.Symbology.EAN8,
Scandit.Symbology.UPCE,
Scandit.Symbology.EAN13UPCA,
Symbology.Code128,
Symbology.Code39,
Symbology.QR,
Symbology.EAN8,
Symbology.UPCE,
Symbology.EAN13UPCA,
]);
```

Expand All @@ -56,8 +58,8 @@ If you are not disabling barcode capture immediately after having scanned the fi
Next, create a [BarcodeCapture](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/barcode-capture.html#class-scandit.datacapture.barcode.BarcodeCapture) instance with the settings initialized in the previous step:

```js
const barcodeCapture = new Scandit.BarcodeCapture(settings);
context.addMode(barcodeCapture);
const barcodeCapture = new BarcodeCapture(settings);
DataCaptureContext.sharedInstance.addMode(barcodeCapture);
```

## Register the Barcode Capture Listener
Expand Down Expand Up @@ -90,7 +92,7 @@ The example below will only scan barcodes beginning with the digits `09` and ign
```js
...
if (!barcode.data || !barcode.data.startsWith('09:')) {
window.overlay.brush = Scandit.Brush.transparent;
window.overlay.brush = Brush.transparent;
return;
}
...
Expand All @@ -111,11 +113,11 @@ In Android, the user must explicitly grant permission for each app to access cam
When using the built-in camera there are recommended settings for each capture mode. These should be used to achieve the best performance and user experience for the respective mode. The following couple of lines show how to get the recommended settings and create the camera from it:

```js
const cameraSettings = Scandit.BarcodeCapture.recommendedCameraSettings;
const cameraSettings = BarcodeCapture.createRecommendedCameraSettings();

// Depending on the use case further camera settings adjustments can be made here.

const camera = Scandit.Camera.default;
const camera = Camera.default;

if (camera) {
camera.applySettings(cameraSettings);
Expand All @@ -125,31 +127,29 @@ if (camera) {
Because the frame source is configurable, the data capture context must be told which frame source to use. This is done with a call to [DataCaptureContext.setFrameSource()](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/data-capture-context.html#method-scandit.datacapture.core.DataCaptureContext.SetFrameSourceAsync):

```js
context.setFrameSource(camera);
DataCaptureContext.sharedInstance.setFrameSource(camera);
```

The camera is off by default and must be turned on. This is done by calling [FrameSource.switchToDesiredState()](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/frame-source.html#method-scandit.datacapture.core.IFrameSource.SwitchToDesiredStateAsync) with a value of [FrameSourceState.On](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/frame-source.html#value-scandit.datacapture.core.FrameSourceState.On):

```js
camera.switchToDesiredState(Scandit.FrameSourceState.On);
camera.switchToDesiredState(FrameSourceState.On);
```

## Use a Capture View to Visualize the Scan Process

When using the built-in camera as frame source, you will typically want to display the camera preview on the screen together with UI elements that guide the user through the capturing process. To do that, add a [DataCaptureView](https://docs.scandit.com/data-capture-sdk/capacitor/core/api/ui/data-capture-view.html#class-scandit.datacapture.core.ui.DataCaptureView) to your view hierarchy:

```js
const view = Scandit.DataCaptureView.forContext(context);
const view = DataCaptureView.forContext(DataCaptureContext.sharedInstance);
view.connectToElement(htmlElement);
```

To visualize the results of barcode scanning, the following [overlay](https://docs.scandit.com/data-capture-sdk/capacitor/barcode-capture/api/ui/barcode-capture-overlay.html#class-scandit.datacapture.barcode.ui.BarcodeCaptureOverlay) can be added:

```js
const overlay = Scandit.BarcodeCaptureOverlay.withBarcodeCaptureForView(
barcodeCapture,
view
);
const overlay = new BarcodeCaptureOverlay(barcodeCapture);
view.addOverlay(overlay);
```

## Disabling Barcode Capture
Expand Down
Loading