fix(android): barcode scan returns empty array despite successful detection - #7
Conversation
…ection Arguments.fromList() does not properly handle List<WritableMap>, causing it to return an empty array even when barcodes are successfully detected on Android. Changed to use Arguments.createArray() with pushMap() to properly handle WritableMap objects. Fixes barcode results not being returned on Android.
WalkthroughModified array result construction in ImageCodeScannerModule.kt, changing from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 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: 0
🧹 Nitpick comments (2)
android/src/main/java/com/imagecodescanner/ImageCodeScannerModule.kt (2)
251-251: Consider removing redundant null filter.The
.filter { it != null }is unnecessary sincemapNotNullon Line 226 already filters out null values by design.Apply this diff to simplify the code:
} - .filter { it != null }
209-210: Consider using consistent array creation pattern.For consistency with the fix on lines 253-254, consider using
Arguments.createArray()directly instead ofArguments.fromList(emptyList()).Apply this diff for consistency:
- val arr = Arguments.fromList(emptyList<String>()) + val arr = Arguments.createArray() promise.resolve(arr)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
android/src/main/java/com/imagecodescanner/ImageCodeScannerModule.kt(1 hunks)
🔇 Additional comments (1)
android/src/main/java/com/imagecodescanner/ImageCodeScannerModule.kt (1)
253-254: LGTM! Proper fix for WritableMap array serialization.The change correctly addresses the bug where
Arguments.fromList()doesn't handleList<WritableMap>properly. UsingArguments.createArray()withpushMap()is the standard React Native pattern for passing arrays of maps through the bridge.
Description
Fixes Android barcode scanning returning empty array despite successful detection.
Problem
Arguments.fromList()does not properly handleList<WritableMap>, causing it to return an empty array even when barcodes are successfully detected on Android.Solution
Changed to use
Arguments.createArray()withpushMap()to properly handleWritableMapobjects, which is the correct way to pass complex objects through the React Native bridge.Changes
ImageCodeScannerModule.ktlines 253-254Arguments.fromList(codes)withArguments.createArray()+ forEach loop withpushMap()Summary by CodeRabbit