Skip to content

Conversation

@HyopeR
Copy link

@HyopeR HyopeR commented Apr 23, 2025

These changes include a few fixes and a few crash measures.

Android:

  1. Resolves overwriting error in multiple format inputs like ['qr', 'code_128']. If you give such an input on the Android platform, only code_128 will be detected. Because in the Android native code it was overwritten as follows.
optionsBuilder.setBarcodeFormats(FORMAT_QR_CODE)
optionsBuilder.setBarcodeFormats(FORMAT_CODE_128)
  1. Correct the use of setBarcodeFormats(). Correct multiple format transfer is as follows..
val firstFormat = barcodeFormats.first()
val otherFormats = barcodeFormats.drop(1).toIntArray()
barcodeOptionsBuilder.setBarcodeFormats(firstFormat, *otherFormats)
  1. 'data-matrix' -> 'data_matrix' spelling fixed.
// Old "data-matrix" -> FORMAT_DATA_MATRIX
// New "data_matrix" -> FORMAT_DATA_MATRIX

Android & Ios:

  1. Prevent crashes in inappropriate inputs.

    1. Recognize all barcodes in empty format inputs like null.
    2. Recognize all barcodes in empty format inputs like [].
    3. Recognize all barcodes in undefined format inputs like [true, 2].
    const {scanBarcodes} = useBarcodeScanner();
    const {scanBarcodes} = useBarcodeScanner([]);
    const {scanBarcodes} = useBarcodeScanner([true, 2]);
    
  2. Similarity in Swift and Kotlin codes.

    1. Added getSafeBarcodeOptions() function to get the barcodeOptions parameter received from the user as a safe list in Swift and Kotlin codes.

    2. Reorganized the installation of init() functions in Swift and Kotlin codes to be similar to each other.

@HyopeR
Copy link
Author

HyopeR commented Apr 23, 2025

@gev2002 Hey thanks for this well written package. Can you review the changes here?

@gev2002
Copy link
Owner

gev2002 commented Jun 10, 2025

Hi @HyopeR, thanks for pull request, I will review as soon as possible and if everything works fine, I'll merge it.

@HyopeR
Copy link
Author

HyopeR commented Jun 10, 2025

Hey hello. This pull request includes some new feature support and code fixes. I'm still working on the module. I'll post details and usage examples when I'm done.

At first I just added a few fixes. But then I needed more and had to do some development. So now it actually includes more than the title of this pull request.

@HyopeR
Copy link
Author

HyopeR commented Jun 12, 2025

About New Features

@gev2002 Hello, here is a copy of types with new features and their descriptions.
Initially, I fixed a few bugs in this package. But later I needed more and the new features here appeared.

Types

BarcodeType = 'aztec' | 'code_128' | 'code_39' | 'code_93' | 'codabar' | 'ean_13' | 'ean_8' | 'pdf_417' | 'qr' | 'upc_e' | 'upc_a' | 'itf' | 'data_matrix' | 'all'

Orientation: 'portrait' | 'landscape-left' | 'portrait-upside-down' | 'landscape-right'

formats

Required: false
Type: BarcodeType[]
Default: ['all']
Description: With this value, the barcode types to be defined can be determined.
Example:

const formats = ['code_128', 'qr']

// Now only QR and Code 128 can be scanned.
const {scanBarcodes} = useBarcodeScanner({formats});

<View style={{flex: 1}}>
    <Camera style={StyleSheet.absoluteFill} />
</View>

ratio

Required: false
Type: { width?: number, height?: number }
Default: { width: 1.0, height: 1.0 }
Description: The scanning area can be limited by specifying this value. For these values ​​to work 100% correctly, the viewSize parameter must also be provided.
Example:

const ratio = {width: 0.8, height: 0.5}
const viewSize = {width: 300, height: 600};

// Now the area with 80% width and 50% height in the central area of ​​the image will be scanned.
// The ratio and viewSize values ​​together give PixelPerfect results.
const {scanBarcodes} = useBarcodeScanner({ratio, viewSize});

<View style={{width: viewSize.width, height: viewSize.height}}>
    <Camera style={StyleSheet.absoluteFill} />
</View>

orientation

Required: false
Type: Orientation
Default: 'portrait'
Description: It ensures that barcode coordinates work with accurate results in different device orientations.
Example:

const [orientation, setOrientation] = useState<any>('portrait');

// Now the coordinates will work in all orientations.
const {scanBarcodes} = useBarcodeScanner({orientation});

<View style={{flex: 1}}>
    <Camera 
        style={StyleSheet.absoluteFill} 
        onPreviewOrientationChanged={previewOrientation => {
            setOrientation(previewOrientation);
        }}
    />
</View>

viewSize

Required: false
Type: { width: number, height: number }
Default: null
Description: When camera components are displayed in mobile applications, they are expanded/contracted or extended/shortened due to "Aspect Ratio" value differences. It is an approach designed for the image detected from the camera to appear as "Cover" on the user's screen.

The camera image detected by MLKit and the user's View screen image are in different sizes. It is recommended to provide this value so that the user can see a "Pixel Perferct" result on the UI side.

viewSize should directly reflect the dimensions in which the user uses the camera component. Using these values, MLKit's coordinate calculations are resized.
Example:

const viewSize = {width: 300, height: 600};

// Now the coordinates will be more accurate.
const {scanBarcodes} = useBarcodeScanner({viewSize});

<View style={{width: viewSize.width, height: viewSize.height}}>
    <Camera style={StyleSheet.absoluteFill} />
</View>

Sample App

You can use the sample application here to test the new features.
https://github.com/HyopeR/react-native-vision-camera-barcodes-scanner/tree/test

Sample Videos

In this example, all features are used. As can be seen, when QR goes outside the area specified with Ratio, the scanning process returns empty. In addition, coordinate tracking is successfully performed in various orientations.

IOS ANDROID
IOS.mp4
ANDROID.mp4

@HyopeR HyopeR changed the title fix: Android multi-format input fix. Swift/Kotlin code analogy. rev: Swift/Kotlin code analogy, new features, bug fixes. Jun 12, 2025
@HyopeR
Copy link
Author

HyopeR commented Jun 27, 2025

If there's anything I can help with here let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants