我有一个本机模块,我想输入它。
这是我的模块界面的示例
export interface BBAudioPlayer {
playSound: (sound: 'click' | 'tada') => Promise<void>;
pause: () => Promise<void>;
}
这就是我使用它的方式:
NativeModules.BBAudioPlayer.playSound('tada');
如何扩展
NativeModules
来添加我的新模块的类型?
// extendNativeModules.d.ts
// import original module declarations
import 'react-native';
export interface BBAudioPlayerInterface {
playSound: (sound: 'click' | 'tada') => Promise<void>;
pause: () => Promise<void>;
}
// and extend them!
declare module 'react-native' {
interface NativeModulesStatic {
BBAudioPlayer: BBAudioPlayerInterface;
}
}
扩展@strdr4605response,如果你想使用,还需要
& NativeModule
或extends NativeModule
到你现有的界面
new NativeEventEmitter(NativeModules.BBAudioPlayer)