feat: Make `startRecording()` awaitable :tada:
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
- Fixes https://github.com/mrousavy/react-native-vision-camera/issues/1319
- Fixes https://github.com/mrousavy/react-native-vision-camera/issues/742
- Fixes https://github.com/mrousavy/react-native-vision-camera/issues/1016
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 |
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.