Skip to content

Commit

Permalink
fix: use defaults where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-MikeS committed May 16, 2024
1 parent 0dd4950 commit 59d9fc5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
2 changes: 2 additions & 0 deletions example-app/ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 9YN2HU59K8;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -369,6 +370,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 9YN2HU59K8;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
4 changes: 2 additions & 2 deletions example-app/ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PODS:
- CapacitorCordova
- CapacitorApp (6.0.0):
- Capacitor
- CapacitorBarcodeScanner (1.0.0-alpha.0):
- CapacitorBarcodeScanner (1.0.0):
- Capacitor
- OSBarcodeLib (~> 1.1.0)
- CapacitorCordova (6.0.0)
Expand Down Expand Up @@ -47,7 +47,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Capacitor: 559d073c4ca6c27f8e7002c807eea94c3ba435a9
CapacitorApp: 9d53aec7101f7b030a950c5bdc4df8612576b279
CapacitorBarcodeScanner: 80444aa11d911dac09a6af454560db735de81ee6
CapacitorBarcodeScanner: 3780aa09a86e526b2903d3b804bd867100f4c924
CapacitorCordova: 8c4bfdf69368512e85b1d8b724dd7546abeb30af
CapacitorHaptics: 9ebc9363f0e9b8eb4295088a0b474530acf1859b
CapacitorKeyboard: deacbd09d8d1029c3681197fb05d206b721d5f73
Expand Down
16 changes: 2 additions & 14 deletions example-app/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import { IonButton, IonContent, IonHeader, IonInput, IonPage, IonTitle, IonToolbar } from '@ionic/react';
import './Home.css';
import { useState } from 'react';
import { CapacitorBarcodeScanner, CapacitorBarcodeScannerTypeHint, CapacitorBarcodeScannerCameraDirection, CapacitorBarcodeScannerScanOrientation, CapacitorBarcodeScannerAndroidScanningLibrary } from '@capacitor/barcode-scanner';
import { CapacitorBarcodeScanner, CapacitorBarcodeScannerTypeHint } from '@capacitor/barcode-scanner';

const Home: React.FC = () => {
const [scannerResult, setScannerResult] = useState<string>('No Data...');

const scanBarcode = async () => {
const result = await CapacitorBarcodeScanner.scanBarcode({
hint: CapacitorBarcodeScannerTypeHint.ALL,
scanInstructions: 'Hold your device over the barcode to scan.',
scanButton: true, // TODO: Not implemented yet in the web implementation
scanText: 'Press To Start Scanning', // TODO: Not implemented yet in the web implementation
cameraDirection: CapacitorBarcodeScannerCameraDirection.BACK,
scanOrientation: CapacitorBarcodeScannerScanOrientation.ADAPTIVE, // TODO: Not implemented yet in the web implementation
android: {
scanningLibrary: CapacitorBarcodeScannerAndroidScanningLibrary.MLKIT,
},
web: {
showCameraSelection: false, // TODO: Not implemented yet in the web implementation
scannerFPS: 30
}
hint: CapacitorBarcodeScannerTypeHint.ALL
});
setScannerResult(result.ScanResult);
};
Expand Down
2 changes: 1 addition & 1 deletion plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Defines the structure of the result returned from a barcode scan.

Defines the options for configuring a barcode scan.

<code>{ hint: <a href="#capacitorbarcodescannertypehint">CapacitorBarcodeScannerTypeHint</a>, scanInstructions?: string, scanButton?: boolean, scanText?: string, cameraDirection?: <a href="#capacitorbarcodescannercameradirection">CapacitorBarcodeScannerCameraDirection</a>, scanOrientation?: <a href="#capacitorbarcodescannerscanorientation">CapacitorBarcodeScannerScanOrientation</a>, android?: { scanningLibrary?: <a href="#capacitorbarcodescannerandroidscanninglibrary">CapacitorBarcodeScannerAndroidScanningLibrary</a>, }, web?: { showCameraSelection?: boolean, scannerFPS?: number } }</code>
<code>{ hint: <a href="#capacitorbarcodescannertypehint">CapacitorBarcodeScannerTypeHint</a>; scanInstructions?: string; scanButton?: boolean; scanText?: string; cameraDirection?: <a href="#capacitorbarcodescannercameradirection">CapacitorBarcodeScannerCameraDirection</a>; scanOrientation?: <a href="#capacitorbarcodescannerscanorientation">CapacitorBarcodeScannerScanOrientation</a>; android?: { scanningLibrary?: <a href="#capacitorbarcodescannerandroidscanninglibrary">CapacitorBarcodeScannerAndroidScanningLibrary</a>; }; web?: { showCameraSelection?: boolean; scannerFPS?: number; }; }</code>


#### CapacitorBarcodeScannerTypeHint
Expand Down
23 changes: 20 additions & 3 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
import { registerPlugin } from '@capacitor/core';

import type { CapacitorBarcodeScannerPlugin } from './definitions'; // Importing the interface for type checking.
import {
CapacitorBarcodeScannerCameraDirection,
CapacitorBarcodeScannerScanOrientation,
type CapacitorBarcodeScannerOptions,
type CapacitorBarcodeScannerPlugin,
type CapacitorBarcodeScannerScanResult,
} from './definitions'; // Importing the interface for type checking.
import { applyCss, barcodeScannerCss } from './utils'; // Import utilities for applying CSS.

/**
* Registers the `OSBarcode` plugin with Capacitor.
* For web platforms, it applies necessary CSS for the barcode scanner and dynamically imports the web implementation.
* This allows for lazy loading of the web code only when needed, optimizing overall bundle size.
*/
const CapacitorBarcodeScanner = registerPlugin<CapacitorBarcodeScannerPlugin>('CapacitorBarcodeScanner', {
const CapacitorBarcodeScannerImpl = registerPlugin<CapacitorBarcodeScannerPlugin>('CapacitorBarcodeScanner', {
web: () => {
applyCss(barcodeScannerCss); // Apply the CSS styles necessary for the web implementation of the barcode scanner.
return import('./web').then((m) => new m.CapacitorBarcodeScannerWeb()); // Dynamically import the web implementation and instantiate it.
},
});

class CapacitorBarcodeScanner {
public static async scanBarcode(options: CapacitorBarcodeScannerOptions): Promise<CapacitorBarcodeScannerScanResult> {
options.scanInstructions = options.scanInstructions || ' '; // Ensure scanInstructions is at least a space.
options.scanButton = options.scanButton || false; // Set scanButton to false if not provided.
options.scanText = options.scanText || ' '; // Ensure scanText is at least a space.
options.cameraDirection = options.cameraDirection || CapacitorBarcodeScannerCameraDirection.BACK; // Set cameraDirection to 'BACK' if not provided.
options.scanOrientation = options.scanOrientation || CapacitorBarcodeScannerScanOrientation.ADAPTIVE; // Set scanOrientation to 'ADAPTIVE' if not provided.
return CapacitorBarcodeScannerImpl.scanBarcode(options);
}
}

export { CapacitorBarcodeScanner }; // Export the `CapacitorBarcodeScanner` class.
export * from './definitions'; // Re-export all exports from the definitions file.
export { CapacitorBarcodeScanner }; // Export the OSBarcode plugin for use in Capacitor projects.

0 comments on commit 59d9fc5

Please sign in to comment.