IOS: You must override the supportedEvents
method Error thrown when supportedEvents
is implemented in super class #20687
Description
- Review the documentation: https://facebook.github.io/react-native
- Search for existing issues: https://github.com/facebook/react-native/issues
- Use the latest React Native release: https://github.com/facebook/react-native/releases
Environment
Environment:
OS: macOS High Sierra 10.13.2
Node: 9.11.1
Yarn: Not Found
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.2 => 0.55.2
Description
RCTEventEmitter has a check implemented in class initializer to check that the Implementation being created implements 'supportedEvents' method. this is achieved here
But the RCTClassOverridesInstanceMethod
method defined here uses class_copyMethodList
obj-C Runtime method to get instance methods and iterate over them to see if required method is implemented.
as per Apple Docs class_copyMethodList
does NOT return instance methods implemented by super classes.
This causes the app to crash in Dev mode (because of RCTAssert?) if the app has its own hierarchy of RCTEventEmitter
s, in which case the supportedEvents
is implemented by an intermediate superclass between the current class and RCTEventEmitter
.
IMO, the implementation should walk the inheritance hierarchy till RCTEventEmitter
to make the correct assertion.
Reproducible Demo
Create a Native Module with One BaseEmitter
which extends from RCTEventEmitter
implement all the required functionalities also the supportedEvents
method. Now create another class MainEmitter
which extends from BaseEmitter
, do not implement the supportedEvents
method in MyEmitter
to re-use implementation from BaseEmitter
App will crash on first use of MainEmitter