Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make startRecording() awaitable 🎉 #2194

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented Nov 21, 2023

What

Finally - startRecording() can now be awaited!!!! I'm using a little workaround that @cipolleschi from Facebook showed me - we're just using two Callbacks now.

My only concern is that after calling the first callback, the second callback might get garbage-collected. I hope this is not the case, I need to test this further.

Breaking Change

Any errors that occur while trying to start the recording will not be delegated through the VideoRecordOptions.onError callback, but will instead cause the returned promise to reject.

So callers will now need to await startRecording().

For your codebase, this now means:

-camera.current.startRecording({
+await camera.current.startRecording({
   // ... other props
   onError: (error) => {
     // ... your onError handling
   }
 })

Changes

Tested on

Related issues

Copy link

vercel bot commented Nov 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-vision-camera ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 21, 2023 4:46pm

@mrousavy
Copy link
Owner Author

mrousavy commented Nov 21, 2023

Okay update; it will not work like this. At least not with the Bridge, not sure if TurboModules will fix this.

The problem is this code:

https://github.com/facebook/react-native/blob/ce0dabddf369587311198290b5bfc8e058a39a28/packages/react-native/Libraries/BatchedBridge/NativeModules.js#L98-L162

It does not work when multiple functions are passed, as there can only always be one success and one error function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant