Add configurable scan preprocessing options#51
Conversation
…lint-plugin versions to 0.79.2
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughThe PR adds configurable preprocessing flags to the JavaScript API and native scanners, updates Android image loading and iOS scan handling, redesigns the Expo example controls, raises Android SDK requirements, and revises compatibility, usage, release, and repository tooling documentation. ChangesScanner preprocessing and integration
Compatibility and repository updates
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant App
participant ImageCodeScanner
participant NativeScanner
participant BarcodeEngine
App->>ImageCodeScanner: scan(path, formats, preprocessing)
ImageCodeScanner->>NativeScanner: scanFromPath(path, nativeOptions)
NativeScanner->>NativeScanner: Load image and create enabled attempts
NativeScanner->>BarcodeEngine: Scan each bitmap attempt
BarcodeEngine-->>NativeScanner: Results or no result
NativeScanner-->>ImageCodeScanner: Resolve scan result
ImageCodeScanner-->>App: Return barcodes
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
src/__tests__/index.test.tsx (1)
78-99: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLGTM!
Consider adding a companion test that omits preprocessing options entirely and asserts
scanFromPathreceives{ enhanceContrast: true, convertToGrayscale: true, tryRotations: true }. This would lock in the default-behavior contract alongside the explicit-override test.#!/bin/bash # Check if any existing test already covers default preprocessing behavior rg -n "enhanceContrast.*true\|convertToGrayscale.*true\|tryRotations.*true" src/__tests__/index.test.tsx🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/__tests__/index.test.tsx` around lines 78 - 99, Add a companion test near the existing preprocessing override test for ImageCodeScanner.scan that omits enhanceContrast, convertToGrayscale, and tryRotations, then assert scanFromPath is called with all three options set to true.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@android/gradle.properties`:
- Line 2: Update ImageCodeScanner_minSdkVersion from 21 to 23 to satisfy the
minimum API requirement of com.google.mlkit:barcode-scanning:17.3.0, or replace
that ML Kit dependency with a version supporting API 21.
In `@android/src/main/java/com/imagecodescanner/ImageCodeScannerModule.kt`:
- Around line 135-146: Restrict openImageInputStream to supported local URI
schemes: handle null/empty and file as currently, explicitly accept only content
in the content-resolver branch, and throw IllegalArgumentException for every
other scheme instead of calling ContentResolver.openInputStream.
- Around line 353-366: Ensure listener callbacks cannot leave the promise
pending when tryNextImage() throws. Update the exception handling around the
success and failure callbacks in the scan flow, including the catch block and
addOnFailureListener, to catch failures from tryNextImage() and resolve or
reject through the existing safeResolve/safeReject mechanism after cleanup and
scanner closure.
In `@COMPATIBILITY.md`:
- Around line 18-19: Align the React Native version requirement documented in
README.md with the compatibility table: update the advertised >=0.70.0
requirement or explicitly note that React Native 0.80.x and newer are not yet
validated, while retaining the supported range described in COMPATIBILITY.md.
In `@README.md`:
- Around line 61-64: Qualify the “any image picker” statement in the README to
clarify that support is limited to local Android file paths, file:// URIs, and
resolver-backed content:// URIs, plus iOS file paths and file:// URIs. Note that
schemes such as ph://, assets-library://, remote URLs, and other
provider-specific values are not guaranteed to work.
---
Nitpick comments:
In `@src/__tests__/index.test.tsx`:
- Around line 78-99: Add a companion test near the existing preprocessing
override test for ImageCodeScanner.scan that omits enhanceContrast,
convertToGrayscale, and tryRotations, then assert scanFromPath is called with
all three options set to true.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9c7fd3f5-c951-4eff-8292-53038cfafe3f
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (17)
COMPATIBILITY.mdREADME.mdandroid/gradle.propertiesandroid/src/main/java/com/imagecodescanner/ImageCodeScannerModule.kteslint.config.mjsexample/README.mdexample/app.jsonexample/expo-env.d.tsexample/metro.config.jsexample/package.jsonexample/src/App.tsxexample/tsconfig.jsonios/ImageCodeScanner.swiftpackage.jsonscripts/validate-package.jssrc/__tests__/index.test.tsxsrc/index.tsx
💤 Files with no reviewable changes (1)
- example/expo-env.d.ts
…y and README files
…RI schemes and streamline image processing flow
…ive version compatibility note
Add configurable scan preprocessing options
Summary
This PR makes image scan preprocessing configurable while keeping the existing default behavior enabled. Callers can now disable contrast enhancement, grayscale conversion, and rotation retry passes independently when scanning local images.
Changes
enhanceContrast,convertToGrayscale, andtryRotationsoptions to the publicScanOptionsAPI, defaulting each option totrue.file://URIs, andcontent://URIs;file://URIs;Testing
npx jest --runInBand --watchman=falseNote:
yarn test --runInBandinitially failed in this sandbox because Watchman could not write its state file outside the workspace. Re-running Jest with Watchman disabled passed.Compatibility
Summary by CodeRabbit