-
Notifications
You must be signed in to change notification settings - Fork 221
feat: support react-native-vision-camera v3 #139
base: master
Are you sure you want to change the base?
feat: support react-native-vision-camera v3 #139
Conversation
Hello, Be careful a self in an override, I'm not sure swift likes that. just replace self by the class name ;) |
Hi @rocket13011, thanks for the tip. I have not done too much Swift programming, so I welcome any advice. It seems like self in this situation is just specifying that the code calls other methods on the same instance of the VisionCameraCodeScanner class. Is there something more complicated happening there? React-native-vision-camera v3's approach no longer expects a static callback method in frame processor plugins, so I removed the static keywords from this class. Replacing self by the class name wouldn't seem to work anymore with that change, but if it is more idiomatic Swift to avoid using self unnecessarily then just removing it altogether is an option. |
@rkmackinnon I tried installing this branch and got the following error message.
I published the build of this branch to my private npm registry and installed it from the registry. |
@bglgwyng I am not familiar with publishing packages to a private npm registry. For the time being I am using this branch without modification by cloning the repo/branch, running
I don't get any errors using this method. I would assume this *.tgz file is the same as would be generated and used by the npm publish command. Would you be able to give more detail on the exact steps you took to get that error message? |
@rkmackinnon I found the same error occurs using the local zipped package as you suggested. Do you have any idea? |
@bglgwyng I suspect you're right. I am using Flipper so I do not have Regardless, I tried to bump the version of react-native-skia to the latest on my branch in case it contained the fix, enabled the static frameworks option in the example project and unfortunately ran into a bunch of other compilation errors. Despite ostensibly having the new frameworks compatible version of react-native-skia, I was seeing errors akin to Shopify/react-native-skia#652 (comment), where if I removed the path prefix I could get a bit further along in the compilation. That seems to be the wrong way to go about fixing the problem though. If you were able to get a message specific to vision-camera-code-scanner, you must be doing something differently since skia doesn't seem to be a problem for you. What customizations did you make to the repo after cloning it to get your error message? |
For skia patch :
|
The patch @rocket13011 provides was already applied to the project. I think that's why I didn't see the error related to react-native-skia.
Regardless, it is still true that the use of use_frameworks! :linkage => :static is the determining factor in the successful build. @rkmackinnon Could you please test this repo and tell me if you can see the same error message? |
Hi @bglgwyng, I can confirm I see the same error message while testing your repo. Thanks for taking the time to put that together. I will have to look at the differences between your repo and the example project in the vision-camera-code-scanner to figure out the skia errors I was getting, but I will move forward with working on the error message in your repo first. |
Hi again @bglgwyng. I was able to fix the error you were getting. There is a missing dependency on the VisionCamera library in the podspec file for VisionCameraCodeScanner. I will push a new commit to my branch to fix this. Unfortunately, the code still doesn't compile though. Now your project and mine are both experiencing the same errors I was talking about with skia. Maybe you'll have some more luck than I have been having fixing that, but I have not given up on it yet! |
Fixes File Not Found errors importing VisionCamera public header files in the VisionCameraCodeScanner bridging header.
@rkmackinnon, thank you very much for your prompt response! I gave your latest commit a try, and the first time I ran it, I noticed that the error I previously reported was no longer present. However, it was replaced with a new issue related to 'react-native-skia'. Luckily, I was already familiar with how to resolve this type of problem, and I found a solution in this link: Shopify/react-native-skia#652 (comment). Nevertheless, the strange thing is that even after I applied the fix, I encountered the 'error: could not build Objective-C module 'VisionCameraCodeScanner' again. You can observe this behavior in the following commit: bglgwyng/RNVC3Sandbox@4c65b2f. |
@bglgwyng It has been pleasant going back and forth with you on this as well. I believe I have fixed the latest issue you reported. If you pull from my branch again and re-run I added a patch to the react-native-vision-camera library that essentially added an empty VisionCamera.h file to satisfy its complaints. I'm not sure if that's the best way to solve the problem, but it works! I tested it in the example project with |
@rkmackinnon, I followed your instructions as directed, but unfortunately, it did not work. Here is the commit. I have included the same patch file for 'react-native-vision-camera'. Can you please tell me what I may have done incorrectly? Furthermore, it would be nice to report the 'VisionCamera.h' issue on the V3 issue tracker (mrousavy/react-native-vision-camera#1376), since it appears to be a general problem across all frame processor modules. |
Hi @bglgwyng, I took a look at your patch. I see you have patched the podspec file to include the reference to VisionCamera.h, but it looks like you maybe forgot to create the empty VisionCamera.h file in the patch as well? My patch from https://github.com/rodgomesc/vision-camera-code-scanner/blob/4dcfeabd3cd41564257e3ec1b0824f3a39b15014/.yarn/patches/react-native-vision-camera-https-95cda75d0b.patch also includes this part:
That is a good suggestion about commenting on the VisionCamera.h file on the V3 issue tracker. There is actually an older issue mrousavy/react-native-vision-camera#1043 about it that I could comment on as well, but I think I should probably do both as that older one might not be actively monitored anymore. |
Your fix works. Thank you! |
Register plugin(s) outside of AppDelegate: AnomalousLLC@5d37292 No need to register Swift plugins manually after installation, maintains out of the box Expo support without prebuild/ejecting. |
Register plugin outside of AppDelegate
Bump min deployment version to match VisionCamera dependency
Remove no longer necessary frame processor plugin registration in AppDelegate didFinishLaunchingWithOptions
|
Certainly some frame processors would've worked with version 3.0, but not this one. There was a bug in version 3.0 that caused iOS frame processors not to pass in any of their options (which I included a patch for) and for Android frame processors that had options with array properties to not expose them to native code. In version 3.1 those bugs were fixed, but the new changes to add back in the OpenGL processing pipeline included new bugs that caused all Android frame processors to crash again. In version 3.2 those bugs seem to have been partially fixed. You are welcome to submit a PR to my repo (the underlying repo that this PR is based on) if I am wrong about this. |
Please try this out. The example app should be working with both iOS and Android now. |
#if defined __has_include && __has_include("VisionCameraCodeScanner-Swift.h") | ||
#import "VisionCameraCodeScanner-Swift.h" | ||
#else | ||
#import <VisionCameraCodeScanner/VisionCameraCodeScanner-Swift.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where's this -Swift.h file located?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another thing, i did install this version. but whenever open the camera with frameProcessor, it crashes. any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide any more details of the crash (e.g., logs, exception messages) or your test environment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I experienced the same issue. Camera works great but when i attach frameProcessor
it crashes the app. This is the log i get from the xCode. Do you know what could be a solution for this issue?
VisionCamera.didSetProps(_:): Updating 16 prop(s)...
VisionCamera.configureCaptureSession(): Configuring Session...
VisionCamera.configureCaptureSession(): Initializing Camera with device com.apple.avfoundation.avcapturedevice.built-in_video:6...
VisionCamera.configureCaptureSession(): Adding Video input...
VisionCamera.configureCaptureSession(): Adding Video Data output...
VisionCamera.invokeOnInitialized(): Camera initialized!
VisionCamera.configureCaptureSession(): Session successfully configured!
VisionCamera.configureFormat(): Configuring Format...
VisionCamera.configureFormat(): Format successfully configured!
VisionCamera.configureDevice(): Configuring Device...
VisionCamera.configureDevice(): Device successfully configured!
VisionCamera.didSetProps(_:): Starting Session...
VisionCamera.didSetProps(_:): Started Session!
libc++abi: terminating due to uncaught exception of type facebook::jsi::JSINativeException: Compiling JS failed: 1:1:invalid empty parentheses '( )' Buffer size 3 starts with: 280a29
I'm using these dependencies:
VisionCamera (3.2.2):
RNReanimated (3.5.4):
React (0.72.5)
Btw thanks @rkmackinnon for the effort!
How can I test this PR @rkmackinnon ? |
You can run the example app in the repo this PR is based on: https://github.com/rkmackinnon/vision-camera-code-scanner/tree/react-native-vision-camera-v3 |
Hi @rkmackinnon 2 import StaticSafeAreaInsets from 'react-native-static-safe-area-insets'; Found 1 error in example/src/Constants.ts:2` I have already tried to add 'react-native-static-safe-area-insets' this package but not useful. |
Hmm, I am using yarn to develop this package so it might be there are some tricky bits with working from source with npm. Try running yarn once you're in the example directory instead. |
Thanks for your reply. Maybe I describe my problem not so clear. I tried to download the package run in local with your suggestion "run yarn in the example directory" could run the project successfully. But now I want to use this package to replace the original v0.2.0 vision-camera-code-scanner in my current project. So I just 2 import StaticSafeAreaInsets from 'react-native-static-safe-area-insets'; Found 1 error in example/src/Constants.ts:2 ` |
I'm experiencing the same problem. Somehow a new dependency in the examples (react-native-static-safe-area-insets) requires it to be installed, but we don't use it. A possible solution would be either (1) somehow ignore the dependencies from examples folder or (2) change the example to avoid the new dependency. UPD: The error persists even if I add react-native-static-safe-area-insets as a dependency. |
Locally cloning and switching to this branch gives the same error when trying |
@rkmackinnon I know, Dimensions API might not be reliable on Android. That's probably why react-native-static-safe-area-insets was added in the first place. However, would that be sufficient to use just Dimensions in the example? Maybe we don't need precise window size for the demo purpose? I tested without this dependency and the package is installed in our project without any problem with npm. You can check the changes here: |
@superR8014 @hssrrw I believe this latest commit will fix the issue with react-native-static-safe-area-insets while still allowing it to be used in the example project. Thanks for helping test this. |
@mare95 Thanks for all your time on this, it is much appreciated. We do not use reanimated so had not run into this incompatibility ourselves. I will bump the react-native-worklets-core version on this branch. |
fixes an incompatibility with react-native-reanimated
Verified this work on iOS. Thanks @rkmackinnon |
Thank you so much! But for android there seems have some problem with enabling frame processor. Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x77a01e19f8 in tid 23358 (ionCamera.video), pid 23092 I currently using react native 0.72.4, react-native-reanimated 3.5.4, react-native-worklets-core 0.2.1 and react-native-vision-camera 3.2.2 Your help will be greatly appreciated. |
@rkmackinnon I faced this crash issue on release build. Do you have any ideas what may cause this? MY ENV: ERROR LOGS: Thread 3 name: Dispatch queue: /VisionCamera.video |
For anyone seeing these crashes, can you reproduce it in the example app? |
example app run perfectly, but my app still get crash issue. |
"react-native-vision-camera" now support code scanner |
Thank bro, you save my day |
Always great to have another option, especially one tied to a project with a better history of ongoing maintenance/support. I'll definitely be trying that out. At first glance, because it's not a frame processor, it looks like it'll support older devices on the Android side. One advantage of vision-camera-code-scanner is that we expose more of the structured output of MLKit. We also have the option to check inverted colors. It'll be interesting to see if there's enough interest to keep this project going after everyone has the time to make some comparisons and consider what they need. |
On iOS side the built-in code scanner of vision camera v3 uses some iOS built-in function to read QR codes and by the result of initial testing I personally prefer the results from MLKit. |
react-native-vision-camera is currently undergoing a rewrite to a new major version, v3: mrousavy/react-native-vision-camera#1376. This pull request would update vision-camera-code-scanner to support it. This code was tested against commit af4e366 from March 21, 2023 in the v3 branch of react-native-vision-camera.