IOS: You must override the supportedEvents
method Error thrown when supportedEvents
is implemented in super class
#21333
Labels
Platform: iOS
iOS applications.
Stale
There has been a lack of activity on this issue and it may be closed soon.
Environment
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
Memory: 140.67 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 9.11.1 - /usr/local/bin/node
npm: 5.6.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
Android SDK:
Build Tools: 21.1.2, 23.0.1, 24.0.0, 24.0.1, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.2, 27.0.3, 28.0.2
API Levels: 22, 23, 24, 25, 26, 27, 28
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5014246
Xcode: 10.0/10A255 - /usr/bin/xcodebuild
npmPackages:
react: ^16.5.0 => 16.5.0
react-native: ^0.57.1 => 0.57.1
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-cli: 2.0.1
react-native-create-library: 3.1.2
react-native-git-upgrade: 0.2.7
react-native-webengage: 1.0.3
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 usesclass_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 thesupportedEvents
is implemented by an intermediate superclass between the current class andRCTEventEmitter
.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 fromRCTEventEmitter
implement all the required functionalities also thesupportedEvents
method. Now create another classMainEmitter
which extends fromBaseEmitter
, do not implement thesupportedEvents
method inMyEmitter
to re-use implementation fromBaseEmitter
App will crash on first use of
MainEmitter
Note: Its a copy of #20687 because I could not update it on time with latest react version.
The text was updated successfully, but these errors were encountered: