Skip to content

Commit 7ea9e4d

Browse files
committed
fix: avoid JS function binding on single-param functions when calling native module
1 parent 31a46a6 commit 7ea9e4d

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ expo-speech-recognition implements the iOS [`SFSpeechRecognizer`](https://develo
3737
- [getSpeechRecognitionServices()](#getspeechrecognitionservices-string-android-only)
3838
- [getDefaultRecognitionService()](#getdefaultrecognitionservice--packagename-string--android-only)
3939
- [getAssistantService()](#getassistantservice--packagename-string--android-only)
40-
- [supportsOnDeviceRecognition()](#supportsondevicerecognition-boolean-android-only)
40+
- [supportsOnDeviceRecognition()](#supportsondevicerecognition-boolean)
4141
- [supportsRecording()](#supportsrecording-boolean-android-only)
4242
- [androidTriggerOfflineModelDownload()](#androidtriggerofflinemodeldownload-locale-string--promise-status-opened_dialog--download_success--download_canceled-message-string-)
4343
- [setCategoryIOS()](#setcategoryios-void-ios-only)

example/App.tsx

+5-9
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import {
1818
type ExpoSpeechRecognitionOptions,
1919
type AndroidIntentOptions,
2020
useSpeechRecognitionEvent,
21-
AudioEncodingAndroidValue,
21+
type AudioEncodingAndroidValue,
2222
TaskHintIOS,
2323
AVAudioSessionCategory,
2424
type AVAudioSessionCategoryValue,
2525
AVAudioSessionCategoryOptions,
2626
type AVAudioSessionCategoryOptionsValue,
27-
SetCategoryOptions,
27+
type SetCategoryOptions,
2828
AVAudioSessionMode,
2929
type AVAudioSessionModeValue,
3030
ExpoWebSpeechRecognition,
@@ -131,10 +131,6 @@ export default function App() {
131131
});
132132
};
133133

134-
const stopListening = () => {
135-
ExpoSpeechRecognitionModule.stop();
136-
};
137-
138134
return (
139135
<SafeAreaView style={styles.container}>
140136
<StatusBar style="dark" translucent={false} />
@@ -191,12 +187,12 @@ export default function App() {
191187
<BigButton
192188
title="Stop"
193189
disabled={status !== "recognizing"}
194-
onPress={stopListening}
190+
onPress={ExpoSpeechRecognitionModule.stop}
195191
/>
196192
<BigButton
197193
title="Abort"
198194
disabled={status !== "recognizing"}
199-
onPress={() => ExpoSpeechRecognitionModule.abort()}
195+
onPress={ExpoSpeechRecognitionModule.abort}
200196
/>
201197
</View>
202198
)}
@@ -991,7 +987,7 @@ function WebSpeechAPIDemo() {
991987
reconizer.removeEventListener("error", handleError);
992988
reconizer.removeEventListener("end", handleEnd);
993989
};
994-
}, [listening]);
990+
}, [listening, reconizer]);
995991

996992
const startListeningWeb = () => {
997993
setListening(true);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "expo-speech-recognition",
3-
"version": "0.2.16",
3+
"version": "0.2.17",
44
"description": "Speech Recognition for React Native Expo projects",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",

src/ExpoSpeechRecognitionModule.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,31 @@ import type { ExpoSpeechRecognitionModuleType } from "./ExpoSpeechRecognitionMod
88

99
// It loads the native module object from the JSI or falls back to
1010
// the bridge module (from NativeModulesProxy) if the remote debugger is on.
11-
export const ExpoSpeechRecognitionModule =
11+
const ExpoSpeechRecognitionNativeModule =
1212
requireNativeModule<ExpoSpeechRecognitionModuleType>("ExpoSpeechRecognition");
1313

14+
export const ExpoSpeechRecognitionModule = {
15+
...ExpoSpeechRecognitionNativeModule,
16+
// Avoid any function bindings when calling the native module
17+
stop: () => ExpoSpeechRecognitionNativeModule.stop(),
18+
abort: () => ExpoSpeechRecognitionNativeModule.abort(),
19+
requestPermissionsAsync: () =>
20+
ExpoSpeechRecognitionNativeModule.requestPermissionsAsync(),
21+
getPermissionsAsync: () =>
22+
ExpoSpeechRecognitionNativeModule.getPermissionsAsync(),
23+
getStateAsync: () => ExpoSpeechRecognitionNativeModule.getStateAsync(),
24+
getAssistantService: () =>
25+
ExpoSpeechRecognitionNativeModule.getAssistantService(),
26+
getDefaultRecognitionService: () =>
27+
ExpoSpeechRecognitionNativeModule.getDefaultRecognitionService(),
28+
getSpeechRecognitionServices: () =>
29+
ExpoSpeechRecognitionNativeModule.getSpeechRecognitionServices(),
30+
supportsOnDeviceRecognition: () =>
31+
ExpoSpeechRecognitionNativeModule.supportsOnDeviceRecognition(),
32+
supportsRecording: () =>
33+
ExpoSpeechRecognitionNativeModule.supportsRecording(),
34+
};
35+
1436
export const ExpoSpeechRecognitionModuleEmitter = new EventEmitter(
15-
ExpoSpeechRecognitionModule ?? NativeModulesProxy.ExpoSpeechRecognition,
37+
ExpoSpeechRecognitionNativeModule ?? NativeModulesProxy.ExpoSpeechRecognition,
1638
);

0 commit comments

Comments
 (0)