react-native-create-bridge
react-native-create-bridge copied to clipboard
this._nativeModule.addListener is not a function
Dev setup:
-
react-native-create-bridge
version: 1.2.2 -
react-native
version: 0.49.3
I am using create-bridge in a:
- [ ] standalone library
- [yes ] existing React Native project
What you did:
I followed this tutorial video : https://www.youtube.com/watch?v=OrIIPNEjQfs to create a object-c Native Module. the constant and the general method works perfectly, but
What happened:
when I receive the event in the JS side using emitter.addListener('EXAMPLE_EVENT,({greeting}) =>{console.log(greeting)}'). It said "this._nativeModule.addListener is not a function"
Do you have any ideas on how that happens?
Thanks for any help
Are you using redux/react navigation in your application? I'm having the same problem and trying to pin down the reason.
Your generate generated a little bit different files that showed in this video.
Pay attention to a header file.
In video header file HelloWorld.h
contains #import “RCTEventEmitter.h”
, but your generated file doesn't.
As well definition of interface should be
@interface HelloWorldComponent : RCTEventEmitter <RCTBridgeModule>
// Define class properties here with @property
@end
instead of
@interface HelloWorldComponent : NSObject <RCTBridgeModule>
// Define class properties here with @property
@end