Woonivers / react-native-document-scanner

Document scanner, features live border detection, perspective correction, image filters and more ! 📲📸
MIT License
85 stars 71 forks source link

Calling the capture method on ref causes error #36

Open idanlo opened 4 years ago

idanlo commented 4 years ago

When calling the ref.current.capture() method I get this error:

Exception 'This function must be called on the UIManager queue' was thrown while invoking capture on target RNPdfScannerManager with params (
    767
)

RCTFatal
facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&)
facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const
invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)
2AFAF864-7F5C-3011-840D-B066E7377AF1
2AFAF864-7F5C-3011-840D-B066E7377AF1
_dispatch_main_queue_callback_4CF
93BD750D-2ECE-3E38-8405-9E46EFE482C6
93BD750D-2ECE-3E38-8405-9E46EFE482C6
CFRunLoopRunSpecific
GSEventRunModal
UIApplicationMain
main
9059087B-727B-3B45-B672-09E5B03E6020
mirhat commented 4 years ago

@idanlo did you solve this issue, I would really appreciate any help!

idanlo commented 4 years ago

@mirhat I did not solve this but apparently this only happens in development, in production build the manual capture works. This still needs to be fixed though.

humphreyja commented 4 years ago

I suspect the issue has something to do with this: https://github.com/Woonivers/react-native-document-scanner/blob/master/android/src/main/java/com/documentscanner/DocumentScannerModule.java#L27

The question here is "why does this need to be ran like that, rather than just running the view.capture() method directly?".

After all, the capture method will run async and handle all the image processing in the callback method so detecting what thread it's on before calling it is pointless? Am I correct to assume this?

I actually rebuilt this package over at https://github.com/HarvestProfit/react-native-rectangle-scanner which you could try out. If the problem persists, then maybe I'm incorrect to assume that, but my package handles all capturing via manually (it uses javascript to auto call the manual capture function). I've had zero issues with this method.

antoinerousseau commented 4 years ago

I'm having the same issue. It would be great to make it work on the simulator too, even if the image is black, to be able to test an app easily :)

Does react-native-rectangle-scanner work on the iOS simulator?

humphreyja commented 4 years ago

@antoinerousseau It does work on an iOS simulator. It just shows a black screen. Also the onDeviceSetup function will send a hasCamera attribute that will be false so you can also show a custom message like "This device doesn't have a camera" if you want. I included that in the example.

Not working on a simulator was one of my biggest issues with this package and its derivatives which is why I included that requirement when I built the react-native-rectangle-scanner package.

Speedy37 commented 4 years ago

See #38 for a fix, this is caused by dispatch_get_main_queue that was here before the set of fixes #26 It removed the non idiomatic singleton approach ( race condition and memory leaks )