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

Cannot update listeners while Voice is recording. #474

Open
yrichard opened this issue Jan 11, 2024 · 0 comments
Open

Cannot update listeners while Voice is recording. #474

yrichard opened this issue Jan 11, 2024 · 0 comments

Comments

@yrichard
Copy link

The current API doesn't allow to update listeners after Voice.start() while it's recording. This can be problematic if you're using hooks and your callback functions need to update as your component state is changing.

I've written the following patch for anyone interested, to be applied with patch-package:

diff --git a/node_modules/@react-native-community/voice/dist/index.js b/node_modules/@react-native-community/voice/dist/index.js
index a10af13..6852f11 100644
--- a/node_modules/@react-native-community/voice/dist/index.js
+++ b/node_modules/@react-native-community/voice/dist/index.js
@@ -52,7 +52,7 @@ class RCTVoice {
     }
     start(locale, options = {}) {
         if (!this._loaded && !this._listeners && voiceEmitter !== null) {
-            this._listeners = Object.keys(this._events).map((key) => voiceEmitter.addListener(key, this._events[key]));
+            this._listeners = Object.keys(this._events).map((key) => voiceEmitter.addListener(key, (event) => {return this._events[key](event);}));
         }
         return new Promise((resolve, reject) => {
             const callback = (error) => {`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant