Skip to content

IOS: You must override the supportedEvents method Error thrown when supportedEvents is implemented in super class #20687

Closed
@saumitrabhave

Description

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 RCTEventEmitters, 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

Metadata

Assignees

No one assigned

    Labels

    Platform: iOSiOS applications.Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions