react-native-create-bridge icon indicating copy to clipboard operation
react-native-create-bridge copied to clipboard

this._nativeModule.addListener is not a function

Open Sunjiawei58 opened this issue 6 years ago • 2 comments

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

Sunjiawei58 avatar Jan 09 '18 00:01 Sunjiawei58

Are you using redux/react navigation in your application? I'm having the same problem and trying to pin down the reason.

dbasea avatar May 17 '18 01:05 dbasea

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

AksimO avatar Jul 03 '18 22:07 AksimO